Mar*_*rry 5 c++ templates c++11
我有一个功能:
template <typename T,
typename std::enable_if <std::is_same<T, int>::value == true>::type* = nullptr>
void test(T i)
{
//process data
}
Run Code Online (Sandbox Code Playgroud)
有用.
但是,我需要启用此功能不仅为int
,但float
并const char *
,以及...如何做到这一点,而无需编写相同的方法3X倍?
Ral*_*zky 11
像这样:
template <typename T,
typename std::enable_if <std::is_same<T, int >::value ||
std::is_same<T, float >::value ||
std::is_same<T, const char *>::value>::type* = nullptr>
void test(T i)
{
//process data
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1582 次 |
最近记录: |