Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] iterating over a sequence with non-const references
From: Joel de Guzman (joel_at_[hidden])
Date: 2012-04-03 22:23:49


On 4/3/2012 10:50 PM, paul Fultz wrote:

> Yea, sorry about that. It seems it was still calling my own invoke and there
> was a mistake in that. If you call invoke like this:
>
> std::cout << invoke(mutable_func(), forward_as_tuple(i, 1)) << std::endl;
>
> There are two errors:
>
> invoke.hpp:209:24: error: non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'
> return f( BOOST_PP_ENUM(N,M,~) );
> ^~~~~~~~~~~~~~~~~~~~~~~~~
>
> Which I assume is because invoke takes the sequence as a const-reference
> because it is a temporary. But then why does the other example work(its also
> a temporary)?

The int& held in the tuple will always be mutable regardless if
the holder tuple is const, that is why it works. I don't know what
else you are doing with forward_as_tuple.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net