1

I want to know if there is a way to check for the last element in a fusion for_each loop (in order to apply special code for this case)

Edit : Maybe a better question should be :

I have played with fusion::for_each, now I want to apply code on each element of a fusion sequence with special code (special code does not mean "extra code" but different code) for the last element. May be I should use iterators (an example please)?

Laurent
  • 812
  • 5
  • 15

1 Answers1

2

Some ideas:

1) use boost::fusion::fold, count your way though, and on the last one, perform your edit

2) if all types in the tuple are heterogenous, match on type to determine last one

3) include some sort of marker for the last one on which you can match

4) use the 'prior(end(v))' operators to manipulate the last element when for_each processing is complete

  • Thank Raymond, this is my second question you answered! The method 1) looks old school index based programing but at least thats a way to achieve my goal. I dont want to make assumption on type so 2) will not fit. 4) suppose to add some code for the last element, on my case its more like removing some code. I'm sure there is an elegant solution but I cant find it. – Laurent Nov 25 '13 at 13:06