Does Fusion have a tail function?

60 Views Asked by At

I need a tail-like funciton that can be used like this:

boost::fusion::vector<char, int, float> a('a', 12, 5.5f);
boost::fusion::vector<int, float> b(12, 5.5f);

boost::fusion::copy( Tail(a), b );
1

There are 1 best solutions below

7
Justin On BEST ANSWER

In the documentation for Boost Fusion, there's a section under Algorithms called Transformation. The Functions listed here notably include one called pop_front. This seems to do exactly what we want:

Returns a new sequence, with the first element of the original removed.
...

Example

assert(pop_front(make_vector(1,2,3)) == make_vector(2,3));

For your example:

boost::fusion::vector<char, int, float> a('a', 12, 5.5f);
boost::fusion::vector<int, float> b(12, 5.5f);

boost::fusion::copy( boost::fusion::pop_front(a), b );

The name pop_front is a little strange, considering that it doesn't actually modify the input sequence, but returns a modified result. However, pop_front comes from the C++ standard library, where it is used for removing the first element of a collection such as with std::list::pop_front. Boost Fusion chose this name to be "more consistent" with the standard library.