Jul 23, 2014

[C++] SFINAE trick with C++14 feature use

Compile time introspection in C++14 using single constexpr.

Nice use of tricks of sizeof, mentioned in Davide Di Gennaro's book:
Advanced C++ Metaprogramming with C++14 features enabled.

2 things to be noticed:

  1. decltype won't evaluate it's content. Which it can't take lambda expression as an argument.
  2. Lambdas can't be passed as parameters to constexpr functions. Ref: constexpr lambda functions

The technique is made use of
declval (std::add_rvalue_reference<T>::type)  / decltype / sizeof / template lambda / SFINAE



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.