#include <iostream>
#include <type_traits>
#include <functional>
using namespace std;
enum test
{
TEST = 2
} ;
/*template <typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
static std::size_t Hash(T const & t)
{
std::cout << "Calling Hash enum" << std::endl;
return std::hash<typename std::underlying_type<T>::type>()(t);
}
template <typename T, typename std::enable_if<!std::is_enum<T>::value>::type* = nullptr>
static std::size_t Hash(T const & t)
{
std::cout << "Calling Hash other type" << std::endl;
return std::hash<T>()(t);
}*/
template < typename T>
static std:: size_t Hash( T const & t)
{
typedef typename std:: conditional < std:: is_enum < T> :: value , std:: hash < typename std:: underlying_type < T> :: type > , std:: hash < T>> :: type Hasher;
return Hasher( ) ( t) ;
}
int main( ) {
Hash< test> ( TEST) ;
Hash< int > ( 5 ) ;
std:: cin .get ( ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgplbnVtIHRlc3QKewogICAgVEVTVCA9IDIKfTsKCi8qdGVtcGxhdGUgPHR5cGVuYW1lIFQsIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPHN0ZDo6aXNfZW51bTxUPjo6dmFsdWU+Ojp0eXBlKiA9IG51bGxwdHI+CnN0YXRpYyBzdGQ6OnNpemVfdCBIYXNoKFQgY29uc3QgJiB0KQp7CiAgICBzdGQ6OmNvdXQgPDwgIkNhbGxpbmcgSGFzaCBlbnVtIiA8PCBzdGQ6OmVuZGw7CiAgICByZXR1cm4gc3RkOjpoYXNoPHR5cGVuYW1lIHN0ZDo6dW5kZXJseWluZ190eXBlPFQ+Ojp0eXBlPigpKHQpOwp9Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVCwgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8IXN0ZDo6aXNfZW51bTxUPjo6dmFsdWU+Ojp0eXBlKiA9IG51bGxwdHI+CnN0YXRpYyBzdGQ6OnNpemVfdCBIYXNoKFQgY29uc3QgJiB0KQp7CiAgICBzdGQ6OmNvdXQgPDwgIkNhbGxpbmcgSGFzaCBvdGhlciB0eXBlIiA8PCBzdGQ6OmVuZGw7CiAgICByZXR1cm4gc3RkOjpoYXNoPFQ+KCkodCk7Cn0qLwoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnN0YXRpYyBzdGQ6OnNpemVfdCBIYXNoKFQgY29uc3QgJiB0KQp7CiAgICB0eXBlZGVmIHR5cGVuYW1lIHN0ZDo6Y29uZGl0aW9uYWw8c3RkOjppc19lbnVtPFQ+Ojp2YWx1ZSwgc3RkOjpoYXNoPHR5cGVuYW1lIHN0ZDo6dW5kZXJseWluZ190eXBlPFQ+Ojp0eXBlPiwgc3RkOjpoYXNoPFQ+Pjo6dHlwZSBIYXNoZXI7CiAgICByZXR1cm4gSGFzaGVyKCkodCk7Cn0KCmludCBtYWluKCkgewogICAgSGFzaDx0ZXN0PihURVNUKTsKICAgIEhhc2g8aW50Pig1KTsKICAgIHN0ZDo6Y2luLmdldCgpOwogICAgcmV0dXJuIDA7Cn0=
compilation info
In file included from /usr/include/c++/5/bits/move.h:57:0,
from /usr/include/c++/5/bits/stl_pair.h:59,
from /usr/include/c++/5/bits/stl_algobase.h:64,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from prog.cpp:1:
/usr/include/c++/5/type_traits: In instantiation of 'struct std::underlying_type<int>':
prog.cpp:30:134: required from 'std::size_t Hash(const T&) [with T = int; std::size_t = unsigned int]'
prog.cpp:36:16: required from here
/usr/include/c++/5/type_traits:2190:38: error: 'int' is not an enumeration type
typedef __underlying_type(_Tp) type;
^
stdout