Boost logo

Boost :

Subject: Re: [boost] [result_of] Allow result_of to work with C++11 lambdas
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-04-10 18:24:04

On 10/04/13 19:43, Nathan Crookston wrote:
> Hi Mathias,
> Mathias Gaunard wrote:
>> I personally have my own implementation of result_of which does this. My
>> implementation is also simpler, compiles faster, is optionally optimized
>> for compilers with variadic templates (also supports compilers with
>> decltype but no variadic templates), has preprocessing support, and has the
>> added benefit that result_of<Sig>::type is only defined if Sig is callable.
> Sounds pretty slick. Is this in NT2, or just in some other code you have?

Yes. I've found that boost::result_of is often a performance bottleneck.
Unfortunately the code in Boost is not as simple as it could be; it
instantiates way too many templates, I suppose for legacy purposes.
My version could probably still be improved too.

> Just so it's clear to others on the list, boost::result_of (at least in
> trunk) also has result_of<Sig>::type that is only defined when Sig is
> callable. I believe Eric Niebler added that a while back.

Doesn't work with latest trunk.
The code below doesn't compile.

/home/mgaunard/dev/boost/trunk/boost/utility/result_of.hpp:173:8: error:
no class template named ‘result’ in ‘struct foo’

It does work, however, if instructed to use decltype. My version applies
SFINAE in C++03 and without SFINAE for expressions too.

#include <boost/utility/result_of.hpp>
#include <iostream>

struct foo {};

template<class T>
typename boost::result_of<T(int)>::type bar(T const& t);
void bar(...)
   std::cout << "not callable" << std::endl;

int main()

Boost list run by bdawes at, gregod at, cpdaniel at, john at