Reputation: 3111
I have been looking into type_traits
recently & was wondering why are they implemented as class templates
whereas implementing them as functions
could be more obvious & have a simpler syntax.
What I want to say is this syntax :-
int x = 5;
std::cout << is_same<int>(x);
Is more convincing & cleaner than the actual one ie :-
int x = 5;
std::cout << is_same <int, decltype(x)>::value;
This is just a case of curiosity. I just want to know the philosophy of the Standardization Committee in preferring the class
method over the function
method.
Upvotes: 3
Views: 232
Reputation: 8785
X::value
boolean constant and X::type
type alias which can be used for tag dispatch. constexpr
functions were not avaliable. Even in constexpr functions you cannot pass values as parameter, as it might prevent compile-time evaluation. Upvotes: 8