Boost logo

Boost :

Subject: Re: [boost] [result_of] now uses decltype on release branch
From: Eric Niebler (eric_at_[hidden])
Date: 2012-09-08 12:56:14


On 9/8/2012 12:45 PM, Michel Morin wrote:
> template < class , class = void >
> struct result_of_aux
> {};
>
> template < class F, class ...Args>
> struct result_of_aux<F(Args...),
> decltype(std::declval<F>()(std::declval<Args>()...), void ())>
> {
> typedef decltype(std::declval<F>()(std::declval<Args>()...)) type;
> };

What is void()? That's not any expression I recognize. It's a function
type. Anyway, keep in mind that std::declval<F>()(...) could have an
incomplete type, so you can't really use it in an expression. You should
use it in decltype, and then pass it as a template parameter to
something like this:

template<typename T>
struct always_void { typedef void type; };

template < class , class = void >
struct result_of_aux
{};

template < class F, class ...Args>
struct result_of_aux<F(Args...),
typename
always_void<decltype(std::declval<F>()(std::declval<Args>()...))>::type>
{
    typedef decltype(std::declval<F>()(std::declval<Args>()...)) type;
};

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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