niXman
niXman

Reputation: 1758

fusion::vector + fusion::push_back = fusion::vector?

I typedef a vector with two elements. Then I push_back into it an other element and expect what result type is also a vector. But that's not so.

Example:

typedef boost::fusion::vector<int, double> vec1;
typedef boost::fusion::result_of::push_back<vec1, std::string> vec2;
//boost::is_same<vec2, boost::fusion::vector<int, double, std::string>>::value == false

http://liveworkspace.org/code/361492801eebe24cc5679a1e899a5240

What am I doing wrong?

Regards.

Upvotes: 1

Views: 615

Answers (1)

Cat Plus Plus
Cat Plus Plus

Reputation: 129894

You've aliased the push_back itself as vec2. You need to use

typedef boost::fusion::result_of::push_back<vec1, std::string>::type vec2;

But keep in mind that the type might still not be the same, Fusion algorithms are not required to preserve the type (and since push_back function is supposed to return a lazy view, then vec2 will most likely be some view type). The only guarantee is that vec2 will be "A model of Forward Sequence.".

Upvotes: 2

Related Questions