[ create a new paste ] login | about

Link: http://codepad.org/WzgvDtWb    [ raw code | output | fork ]

C++, pasted on Sep 8:
#include <cstdio>



template <class T, class U> struct is_same
{
static bool const value = false;
}; 

template <class T> struct is_same<T, T>
{
static bool const value = true;
};

template <bool p, class T, class F> struct select
{
typedef T type;
};

template <class T, class F> struct select<false, T, F>
{
typedef F type;
};



struct hoge {};
struct fuga {};

struct for_hoge
{
static void func(hoge)
{
std::puts("func for hoge");
}
};

struct for_fuga
{
static void func(fuga)
{
std::puts("func for fuga");
}
};



template <class T> void call_func(void)
{
if(!is_same<T, hoge>::value && !is_same<T, fuga>::value)
{
return;
}

typedef typename select<is_same<T, hoge>::value, hoge, fuga>::type xxx;
typedef typename select<is_same<T, hoge>::value, for_hoge, for_fuga>::type for_xxx;

xxx x;

for_xxx::func(x);
}



int main(void)
{
call_func<hoge>();
call_func<fuga>();

return 0;
}


Output:
1
2
Line 15: error: 'template<bool p, class T, class F> struct select' redeclared as different kind of symbol
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: