Boost logo

Boost :

Subject: Re: [boost] [type_traits] common_type and SFINAE
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-10-04 12:19:07


On Thu, Oct 4, 2012 at 1:17 AM, Matt Calabrese <rivorus_at_[hidden]> wrote:
> On Thu, Oct 4, 2012 at 4:13 AM, Matt Calabrese <rivorus_at_[hidden]> wrote:
>
>> Updated and tested for edge cases int GCC and Clang.
>>
>
> Updated one more time to simplify it a little. I'm going to sleep,
> otherwise I'll keep changing it.

Thanks a lot!

template< class > struct always_void { typedef void type; };

template< class T, class U, class = void >
struct common_type_impl_2 {}; // (1)

template< class T, class U >
struct common_type_impl_2 // (2)
       < T, U
       , typename always_void
         < decltype( true ? std::declval< T >() : std::declval< U >()
) >::type // (*)
>
{
  typedef decltype( true ? std::declval< T >() : std::declval< U >() ) type;
};

So I understand it :) Would you explain me who the 2nd
common_type_impl2 get selected when there's a common type given that
always_void<...>::type is always void?

Is it because when decltype( true ? std::declval< T >() :
std::declval< U >() ) >::type is not valid in the instatiation of
always_void (*) then SFINAE removes the overload (2) and (1) gets
selected for being the only choice left? If so, why (1) has the lower
priority in being selected when there's a common type and both (1) and
(2) are valid?

Thanks!
--Lorenzo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk