To discover implicit / explicit constructivity for SFINAE:
template<class T0, typename std::enable_if< std::is_convertible<const T0 &, Base<T>>::value, int>::type = 0> Derived(const T0& rhs) : Base<T>(rhs) { } template<class T0, typename std::enable_if< std::is_constructible<Base<T>, const T0 &>::value && !std::is_convertible<const T0 &, Base<T>>::value, int>::type = 0> explicit Derived(const T0& rhs) : Base<T>(rhs) { }
Use the fact that std::is_convertible checks for implicit convertibility and uses std::is_constructible to further check for explicit convertibility.
Edit: the parameters of the enable_if template are fixed using a solution from boost :: enable_if, and not in the function signature .
Verification:
Derived<int>{5}; // allowed [](Derived<int>){}(5); // allowed Derived<int>{std::string{"hello"}}; // allowed [](Derived<int>){}(std::string{"hello"}); // not allowed
source share