[ create a new paste ] login | about

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

C++, pasted on Sep 7:
#include <iostream>
#include <typeinfo>
#include <vector>
using namespace std;

template <bool, class IfTrue, class IfFalse>
class sub;

/* 元のsub1 */
template <class IfTrue, class IfFalse>
class sub<true, IfTrue, IfFalse>
{
public:
	typedef IfTrue retT;
	static void sub0(const retT& a)
	{
		cout << "s" << endl;
	}
};

/* 元のsub2 */
template <class IfTrue, class IfFalse>
class sub<false, IfTrue, IfFalse>
{
public:
	typedef IfFalse retT;
	static void sub0(const retT& a)
	{
		cout << "d" << endl;
	}
};

template <class T>
void foo(T oh)
{
	vector<int> s;
	vector<vector<int> > d;
	if (typeid(s) == typeid(T)) {
		typedef sub<false, vector<vector<int> >, vector<int> > subT;
		subT::retT subT::sub0(oh);
	} else if (typeid(d) == typeid(T)) {
		typedef sub<true, vector<vector<int> >, vector<int> > subT;
		subT::retT subT::sub0(oh);
	} else {
		cout << "oops" << endl;
	}
}

int main(void)
{
	vector<int> bar1; bar1.push_back(8);
	foo<vector<int> >(bar1);
	return 0;
}


Output:
1
2
3
In function 'void foo(T)':
Line 40: error: too few template-parameter-lists
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: