On 6/4/2015 4:30 PM, Peter Dimov wrote:
Eric Niebler wrote:
I made Meta SFINAE-friendly on a lark and found it useful in practice. (See this thread[*] where Louis and I compared common_type implementations with Meta and Hana.) ... [*] http://lists.boost.org/Archives/boost/2015/03/220446.php
Having a SFINAE-friendly fold helps, but here's my implementation of this challenge.
// common_type
template
struct common_type { using type_not_present = void***[]; }; template<class T> struct common_type<T>: std::decay<T> { };
template
using common_type_impl = common_type ; template
struct common_type : eval_or_default , common_type_impl, T1, T2, T...> { }; #include <iostream> #include <typeinfo>
int main() { std::cout << typeid( common_type
::type ).name() << std::endl; std::cout << typeid( common_type ::type_not_present ).name() << std::endl; } where eval_or_default
checks is_evaluable (from Bruno Dutra's earlier message) and returns F if evaluable, Def if not. Getting it right was a bit tricky, but I find the final result quite readable. (This implements the specification in the latest C++17 draft.)
I'm not so sure. If a user defines a specialization for
common_type