1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| namespace TagDispatch {
template <typename T> void fun2(T&& params, std::false_type) { std::vector<std::string> temp; temp.emplace_back(std::forward<T>(params)); std::cout << "called fun(T&& params)" << std::endl; }
void fun2(int a, std::true_type) { std::cout << "called fun(int a)" << std::endl; }
template <typename T> void fwd(T&& params) { fun2(std::forward<T>(params), std::is_integral<typename std::remove_reference<T>::type>()); }
void test() { fwd("abc"); int a = 0; fwd(a); short b = 10; fwd(b); }
}
|