#include #include #include #include template struct safe_convertable { public: explicit safe_convertable(T& ref) : _ref(ref) { } template operator TDestination () { typedef boost::is_same same_type; BOOST_STATIC_WARNING(same_type::value); // This will fail, as expected: //BOOST_STATIC_ASSERT(same_type::value); return _ref; } private: T& _ref; }; template safe_convertable get(T& ref) { return safe_convertable(ref); } int main() { int64_t x = 0; // this should fail: int32_t y = get(x); return y; }