[ create a new paste ] login | about

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

C++, pasted on Mar 23:
#include <iostream>
#include <string>

// 引数用の型
struct Arg0{
	std::string str;
	Arg0(const std::string& s)
		: str(s)
	{}
};
struct Arg1{
	std::string str;
	Arg1(const std::string& s)
		: str(s)
	{}
};


// 引数のうちArgType型のものを選ぶ
template<typename ArgType>
struct SelectArg{
	template<typename T1>
	static const ArgType& get(const ArgType& a0, const T1& a1){return a0;}
	template<typename T0>
	static const ArgType& get(const T0& a0, const ArgType& a1){return a1;}
};

// 引数を並べ替えられる関数
template<typename T0, typename T1>
void f(T0 a0, T1 a1){
	const Arg0& arg0 = SelectArg<Arg0>::get(a0, a1);
	const Arg1& arg1 = SelectArg<Arg1>::get(a0, a1);
	std::cout << "Arg0=" << arg0.str << "/ Arg1=" << arg1.str << std::endl;
}

int main(){

	f(Arg0("this is arg0"), Arg1("this is arg1"));
	f(Arg1("this is arg1"), Arg0("this is arg0"));
	return 0;
}


Output:
1
2
Arg0=this is arg0/ Arg1=this is arg1
Arg0=this is arg0/ Arg1=this is arg1


Create a new paste based on this one


Comments: