[Boost-users] Compilation errors when trying to use range adaptors with C++11 lambdas

20 views
Skip to first unread message

Evan Driscoll

unread,
Jun 19, 2012, 2:25:15 PM6/19/12
to boost...@lists.boost.org
When trying to compile the following:

std::vector<int> v;
v | boost::adaptors::transformed([] (int x) { return x; });

I get a bunch of compile errors. If I replace the lambda with a function
defined normally, it works.

Am I doing something wrong, or is this a bug/missing feature/something?
I'm compiling with GCC 4.6.1 (though 4.7.1 has the same problem) and
have Boost 1.49.


The output and full program are attached. The main part (dropping the
"instantiated from..."s) of the first error is:

boost/utility/result_of.hpp:82:8: error: no class template named
�result� in �struct main()::<lambda(int)>�

Evan

errors.txt
test.cc

Akira Takahashi

unread,
Jun 19, 2012, 9:08:03 PM6/19/12
to boost...@lists.boost.org
Hi Evan,

2012/6/20 Evan Driscoll <dris...@cs.wisc.edu>:
> When trying to compile the following:
>
> std::vector<int> v;
> v | boost::adaptors::transformed([] (int x) { return x; });
>
> I get a bunch of compile errors. If I replace the lambda with a function
> defined normally, it works.

You must use
#define BOOST_RESULT_OF_USE_DECLTYPE

C++11 lambda can't apply non decltype-base result_of.

>>========================
Akira Takahashi
mailto:faitha...@gmail.com
https://sites.google.com/site/faithandbrave/about/en
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Evan Driscoll

unread,
Jun 20, 2012, 2:11:55 PM6/20/12
to boost...@lists.boost.org
On 06/20/2012 09:04 AM, boost-use...@lists.boost.org wrote:
> 2012/6/20 Evan Driscoll<dris...@cs.wisc.edu>:
>> When trying to compile the following:
>>
>> std::vector<int> v;
>> v | boost::adaptors::transformed([] (int x) { return x; });
>>
>> I get a bunch of compile errors. If I replace the lambda with a function
>> defined normally, it works.
>
> You must use
> #define BOOST_RESULT_OF_USE_DECLTYPE
>
> C++11 lambda can't apply non decltype-base result_of.

Thanks a lot; worked like a charm. Of course, in the interim I figured
out that the function will be rather more complicated than I thought so
I'm happier with it defined normally, but that'll be good to file away
for future reference. :-)

Evan
Reply all
Reply to author
Forward
0 new messages