// Copyright (C) 2014 Lorenzo Caminiti. #include #include #include #include namespace aux { template< bool Condition > struct static_if_statement { template< typename F > void then ( F const& f ) { f(); } template< typename F > void else_ ( F const& ) { } }; template< > struct static_if_statement { template< typename F > void then ( F const& ) { } template< typename F > void else_ ( F const& f ) { f(); } }; } // namespace template< bool Condition, typename F > aux::static_if_statement static_if ( F const& f ) { aux::static_if_statement if_; if_.then(f); return if_; } template< typename T > void assign ( T& x, T const& y ) { x = y; static_if::value>( std::bind([] ( auto x, auto y ) { assert(x == y); std::cout << "asserted for: " << typeid(T).name() << std::endl; }, x, y) ).else_( [] ( ) { std::cout << "cannot assert for: " << typeid(T).name() << std::endl; } ); } int main ( ) { int i = 1; struct x_t { } x; static_assert(boost::has_equal_to::value == 1, "int equal"); static_assert(boost::has_equal_to::value == 0, "x_t not equal"); assign(i, i); assign(x, x); return 0; }