-, - //, , , - . explicit
. explicit
( ::std::is_convertible
):
#include <utility>
#include <type_traits>
#include <iostream>
template<typename Anything> class
Void
{
public: using type = void;
};
template<typename T, typename U, typename Enabled = void> class
Conversion
: public ::std::false_type {};
template<typename T, typename U> class
Conversion<T, U, typename Void<decltype(static_cast<U>(::std::declval<T>()))>::type>
: public ::std::true_type {};
struct foo{ explicit operator int(void) const; };
int main()
{
::std::cout << "Conversion short to int :" << Conversion<short, int>::value << "\n";
::std::cout << "Conversion int to short :" << Conversion<int, short>::value << "\n";
::std::cout << "Conversion int to float :" << Conversion<int, float>::value << "\n";
::std::cout << "Conversion float to int :" << Conversion<float, int>::value << "\n";
::std::cout << "Conversion float to foo :" << Conversion<float, foo>::value << "\n";
::std::cout << "Conversion foo to float :" << Conversion<foo, float>::value << "\n";
::std::cout << "Conversion int to foo :" << Conversion<int, foo>::value << "\n";
::std::cout << "Conversion foo to int :" << Conversion<foo, int>::value << "\n";
return 0;
}
-, /W 4 v++