为什么复制构造函数的两个版本在使用时会给出不同的结果enable_if
?据我了解,使用的两个复制构造函数应该产生相同的结果(仅用于未定义Settings<int>
)
template <typename Type>
struct Predicate : std::integral_constant<bool, true>
{
};
template <>
struct Predicate<int> : std::integral_constant<bool, false>
{
};
template <typename FooType>
struct Settings
{
Settings() {}
// Here it works fine
template <typename OtherFooType>
Settings(const Settings<OtherFooType>& other, std::enable_if_t<Predicate<OtherFooType>::value, int*> = 0) {}
// In this case enable_if does not work
//template <typename OtherFooType>
//Settings(typename std::enable_if<Predicate<OtherFooType>::value, const Settings<OtherFooType>&>::type other){}
};
int main()
{
Settings<float> f = Settings<char>();
return 0;
}