Opened 10 years ago

Last modified 10 years ago

#6965 new Feature Requests

Handling of sequence of non const reference

Reported by: Joel Falcou Owned by: Joel de Guzman
Milestone: To Be Determined Component: fusion
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

Currently, assigning or copying a fusion sequence of non const reference to another is not possible. Down into the code, the vectorN classes only has a vectorN( const Sequence& ) constructor that calls a const qualified from_sequence method from the base_type.

Sequence of reference has a nice use case of enabling strcuture of arrayArray of structure efficient application and this can't be doen with current Fusion.

Could all sequence be amended so passing a non const sequence as initialisation is dealt with correctly ?

Attachments (2)

ref_vector.cpp (1.6 KB ) - added by Joel Falcou 10 years ago.
Test case for composite_reference, a class acting as a reference tuple onto an struct adapted as a fusion sequence
ref_vector.error.output (3.5 KB ) - added by Joel Falcou 10 years ago.
Error of former example

Download all attachments as: .zip

Change History (5)

comment:1 by Joel de Guzman, 10 years ago

If you can provide a test case for a specific use case, I can look into this and implement a fusion wide mod. Thanks, Joel!

by Joel Falcou, 10 years ago

Attachment: ref_vector.cpp added

Test case for composite_reference, a class acting as a reference tuple onto an struct adapted as a fusion sequence

by Joel Falcou, 10 years ago

Attachment: ref_vector.error.output added

Error of former example

comment:2 by Joel Falcou, 10 years ago

I Just attached a test case and the error I get. Adding:

  template <typename Sequence>
  static BOOST_PP_CAT(vector_data, N)
  init_from_sequence(Sequence& seq)
  {
      typedef typename result_of::begin<Sequence>::type I0;
      I0 i0 = fusion::begin(seq);
      BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_ITER_DECL_VAR, _)
      return BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_PARAMS(N, *i));
  }

  template <typename Sequence>
  BOOST_PP_CAT(vector, N)(
      Sequence& seq
#if (N == 1)
    , typename boost::disable_if<is_convertible<Sequence, T0> >::type* /*dummy*/ = 0
#endif
      )
      : base_type(base_type::init_from_sequence(seq)) {}

to vector_n.hpp and re-preprocess fix the stuff. I guess other sequences may have similar mechanism. Not sure about any side effect tough.

comment:3 by Joel de Guzman, 10 years ago

Fixed for vector. I'll leave this open as a reminder to fix other containers.

Note: See TracTickets for help on using tickets.