#include <iostream>
#include <type_traits> // <-------
using namespace std;
template < typename T>
enable_if_t< is_fundamental< T> :: value , T>
sum( const T& a, const T& b) { return a + b; }
template < typename T>
enable_if_t< ! is_fundamental< T> :: value , T>
sum( const T& , const T& ) { static_assert( false , "Not fundamental type" ) ; }
int main( )
{
struct A { } ;
cout << sum( 5.1f , 9.4f ) << endl;
sum( A( ) , A( ) ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+IC8vIDwtLS0tLS0tCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgplbmFibGVfaWZfdDxpc19mdW5kYW1lbnRhbDxUPjo6dmFsdWUsIFQ+CnN1bShjb25zdCBUJiBhLCBjb25zdCBUJiBiKSB7IHJldHVybiBhICsgYjt9Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgplbmFibGVfaWZfdDwhaXNfZnVuZGFtZW50YWw8VD46OnZhbHVlLCBUPgpzdW0oY29uc3QgVCYsIGNvbnN0IFQmKSB7IHN0YXRpY19hc3NlcnQoZmFsc2UsICJOb3QgZnVuZGFtZW50YWwgdHlwZSIpO30KCmludCBtYWluKCkKewogICAgc3RydWN0IEEge307CiAgICBjb3V0IDw8IHN1bSg1LjFmLCA5LjRmKSA8PCBlbmRsOwogICAgc3VtKEEoKSwgQSgpKTsKICAgIHJldHVybiAwOwp9Cg==
compilation info
prog.cpp: In function 'std::enable_if_t<(! std::is_fundamental<_Tp>::value), T> sum(const T&, const T&)':
prog.cpp:11:27: error: static assertion failed: Not fundamental type
sum(const T&, const T&) { static_assert(false, "Not fundamental type");}
^
stdout