[fusion] construct a tuple's elements with arguments
If I have a
typedef fusion::tuple
Yuval Ronen wrote:
If I have a
typedef fusion::tuple
T; can I somehow create a T instance like
T t(1, "hello");
and by that I mean that each of T's elements (of types X, Y and Z) would be constructed using the constructor that accepts an int and a string, assuming there is such a constructor for all T's elements. If there isn't such constructor for all T's elements, then it shouldn't compile, of course.
No.
Of course using the exact syntax above is not possible, because it's reserved for something else, but any other syntax would be just as good (perhaps using in_place_factory).
Does it have to be done at construction? If not, you can use for_each. If yes, it might be interesting to have a forward fusion sequence that generates its elements on the fly (a generator). But this also presents some complications because you want the elements to be constructed with 2 arguments. So, I have no immediate ideas for you. If you have some specific suggestions, I'm all ears. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Joel de Guzman wrote:
Yuval Ronen wrote:
If I have a
typedef fusion::tuple
T; can I somehow create a T instance like
T t(1, "hello");
and by that I mean that each of T's elements (of types X, Y and Z) would be constructed using the constructor that accepts an int and a string, assuming there is such a constructor for all T's elements. If there isn't such constructor for all T's elements, then it shouldn't compile, of course.
No.
Of course using the exact syntax above is not possible, because it's reserved for something else, but any other syntax would be just as good (perhaps using in_place_factory).
Does it have to be done at construction? If not, you can use for_each.
Yes, I have to use the constructors. For performance reasons, and especially because X, Y and Z don't have a default constructor.
If yes, it might be interesting to have a forward fusion sequence that generates its elements on the fly (a generator). But this also presents some complications because you want the elements to be constructed with 2 arguments.
I want the ability to have the elements be constructed with any number of arguments. Two is just in this specific case...
So, I have no immediate ideas for you. If you have some specific suggestions, I'm all ears.
I don't have any ideas, except maybe somehow use boost::in_place_factory, but that's as specific as I can get... I do think, though, that it's a valuable feature for fusion, for types that don't have default constructors, or are non-copyable. Yuval
Yuval Ronen wrote:
I want the ability to have the elements be constructed with any number of arguments. Two is just in this specific case...
So, I have no immediate ideas for you. If you have some specific suggestions, I'm all ears.
I don't have any ideas, except maybe somehow use boost::in_place_factory, but that's as specific as I can get... I do think, though, that it's a valuable feature for fusion, for types that don't have default constructors, or are non-copyable.
Agreed. You got me thinking. The easiest I can think of is: a_tuple t(apply_for_each(val1, val2,... val3)); where apply_for_each signals the constructor to construct its elements using the supplied args. This would be a major undertaking though since we have to do this for all sequences in there. Perhaps there's an easier solution. I'm saving this one for future reference. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Joel de Guzman wrote:
Yuval Ronen wrote:
I want the ability to have the elements be constructed with any number of arguments. Two is just in this specific case...
So, I have no immediate ideas for you. If you have some specific suggestions, I'm all ears. I don't have any ideas, except maybe somehow use boost::in_place_factory, but that's as specific as I can get... I do think, though, that it's a valuable feature for fusion, for types that don't have default constructors, or are non-copyable.
Agreed. You got me thinking. The easiest I can think of is:
a_tuple t(apply_for_each(val1, val2,... val3));
where apply_for_each signals the constructor to construct its elements using the supplied args.
This would be a major undertaking though since we have to do this for all sequences in there. Perhaps there's an easier solution. I'm saving this one for future reference.
I keep my fingers crossed for you... :)
participants (2)
-
Joel de Guzman
-
Yuval Ronen