[fusion] how to initialize a container of non-const references to objects, from a container of objects

Hello, I've started to use fusion for the signal network gsoc project, and am really amazed with how much it simplified the prototype code (it brought down the need for preprocessing+file iteration to a bare minimum). Thanks for such a great library! I recently ran into a problem, though, and am wondering if someone could help me out. I have a need to do something along the lines of the following: boost::fusion::vector<int> a; boost::fusion::vector<int &> b(a); // first element of b refers to the first element of a Using fusion from CVS HEAD, this doesn't work because all of the related constructors take a const & argument. A similar use case (but not exactly what I need) does work: boost::fusion::vector<int> a; boost::fusion::vector<const int &> b(a); as does this: (but i'd like to avoid this approach because in my exact case the size of the vectors varies) boost::fusion::vector<int> a; boost::fusion::vector<int &> b(boost::fusion::at_c<0>(a)); I tried adding non-const versions of the constructors / helper functions to vector/vector.hpp and vector/vector_n.hpp, and after doing so the use case I need works OK. Unless there is an alternative way of doing what I'm trying to do, would it be possible to add in the non-const versions of the constructors? I don't mind producing the patches if someone points me to all the places where the non-const constructors should be added to make the addition consistent, as well as to any non-obvious things that would also need to be done (keeping in mind that currently my scope of "obvious" appears to be pretty limited :-)) Thanks for your help, Stjepan

Ping... anyone? On 6/9/07, Stjepan Rajko <stipe@asu.edu> wrote:
Hello,
I've started to use fusion for the signal network gsoc project, and am really amazed with how much it simplified the prototype code (it brought down the need for preprocessing+file iteration to a bare minimum). Thanks for such a great library!
I recently ran into a problem, though, and am wondering if someone could help me out. I have a need to do something along the lines of the following:
boost::fusion::vector<int> a; boost::fusion::vector<int &> b(a); // first element of b refers to the first element of a
Using fusion from CVS HEAD, this doesn't work because all of the related constructors take a const & argument. A similar use case (but not exactly what I need) does work:
boost::fusion::vector<int> a; boost::fusion::vector<const int &> b(a);
as does this: (but i'd like to avoid this approach because in my exact case the size of the vectors varies)
boost::fusion::vector<int> a; boost::fusion::vector<int &> b(boost::fusion::at_c<0>(a));
I tried adding non-const versions of the constructors / helper functions to vector/vector.hpp and vector/vector_n.hpp, and after doing so the use case I need works OK.
Unless there is an alternative way of doing what I'm trying to do, would it be possible to add in the non-const versions of the constructors? I don't mind producing the patches if someone points me to all the places where the non-const constructors should be added to make the addition consistent, as well as to any non-obvious things that would also need to be done (keeping in mind that currently my scope of "obvious" appears to be pretty limited :-))
Thanks for your help,
Stjepan

Stjepan Rajko wrote:
Ping... anyone?
There are several places where Fusion could use overloads like the one you request (reported several times by several people). So that "mutability issue" is already on the list. Until it's fixed, I'd try to work around the problem by using a fusion::transform to put a boost::reference_wrapper around each element. Regards, Tobias
participants (2)
-
Stjepan Rajko
-
Tobias Schwinger