黑魔法求调
  • 板块灌水区
  • 楼主lbdontknow
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/4/7 14:10
  • 上次更新2023/10/23 19:11:50
查看原帖
黑魔法求调
664908
lbdontknow楼主2023/4/7 14:10

rt,想实现一个万能prinf,CE了

#ifndef EASY_CPP_H_INCLUDED
#define EASY_CPP_H_INCLUDED
#include<string>
#include<cstdio>
using namespace std;
template<typename T>
constexpr bool __is_int=false;
template<>
constexpr bool __is_int<int>=true;
template<>
constexpr bool __is_int<long>=true;

template<typename T>
constexpr bool __is_char=false;
template<>
constexpr bool __is_char<char>=true;

template<typename T>
constexpr bool __is_long_long=false;
template<>
constexpr bool __is_long_long<long long>=true;

template<typename T>
constexpr bool __is_string=false;
template<>
constexpr bool __is_string<string>=true;
template<>
constexpr bool __is_string<char*>=true;

template<typename T>
constexpr bool __is_float=false;
template<>
constexpr bool __is_float<float>=true;

template<typename T>
constexpr bool __is_double=false;
template<>
constexpr bool __is_double<double>=true;

template<typename T>
constexpr bool __is_ldouble=false;
template<>
constexpr bool __is_ldouble<long double>=true;

template<typename T>
constexpr bool __is_ull=false;
template<>
constexpr bool __is_ull<unsigned long long>=true;

namespace ec{
    template<typename T>
    void print(T x){
        string type;
        if(__is_int<T>){
            type="%d";
        }
        else if(__is_char<T>){
            type="%c";
        }
        else if(__is_long_long<T>){
            type="%lld";
        }
        else if(__is_string<T>){
            type="%s";
        }
        else if(__is_float<T>){
            type="%f";
        }
        else if(__is_double<T>){
            type="%lf";
        }
        else if(__is_ldouble<T>){
            type="%llf";
        }
        else if(__is_ull<T>){
            type="%ulld";
        }
        printf(type.c_str(),x);
        return;
    }
    template<typename T,typename... Args>
    void print(T x,Args... args){
        print(x);
        print(args...);
    }
}
#endif














2023/4/7 14:10
加载中...