64,637
社区成员
发帖
与我相关
我的任务
分享
#include <type_traits>
using namespace std;
template<class T>
void g(T&& t, std::false_type)
{
}
template<class T>
void f(T&& t)
{
g(forward<T>(t), std::is_integral<typename remove_reference<T>::type>());
}
int main() {
int i = 1;
f(i);
return 0;
}
#include <type_traits>
template<class T>
void g(T&& t,
typename std::enable_if<std::is_integral<typename std::remove_reference<T>::type>::value, int>::type dummy= 0)
{
}
int main() {
int i = 1;
g(i);
g(4L);
//g(2.5); //error,not integral
//g("hello world"); //error,not integral
return 0;
}
#include <type_traits>
template<class T>
void g(T t, std::true_type) {
}
template<class T> void f(T&& t) {
using my_booltype = std::integral_constant<bool, std::is_integral<typename std::remove_reference<T>::type>::value>;
g(std::forward<T>(t), my_booltype());
}
int main() {
int i = 1;
f(std::move(i));
return 0;
}
不知道lz干嘛, 还是我自己搞错了.
f函数的参数T&&, forward<T>(t)返回类型是T, is_integral<xxx>又不是返回true/false_type.
g的参数却是(T&&, false_type)