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-04 01:10:46


On 4/4/2012 11:42 AM, paul Fultz wrote:
>
>
>> 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.
>
> But I thought since this overload is provided for get:
>
>
> template< std::size_t I, class... Types >
>
> typename std::tuple_element<I, tuple<Types...> >::type const&
>
> get( const tuple<Types...>& t );
>
> Then it would add const to the reference. Also, forward_as_tuple
> is just the std::forward_as_tuple.

Nope. That is not correct. See:

  #include <boost/fusion/tuple.hpp>
  #include <iostream>

  template <typename T>
  void foo(T const& t)
  {
      using namespace boost::fusion;

      get<0>(t) = 123;
  }

  int main()
  {
      using namespace boost::fusion;

      int i = 999;
      tuple<int&, int> t(i, 1);
      foo(t);

      std::cout << get<0>(t) << std::endl;
  }

The printout is 123. get<1>(t) OTOH is another story.
Go figure...

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