views:

28

answers:

1

Hi all. How to determine elements count in boost.preprocessor tuple`s ? Thanks.

+2  A: 

You don't. That's why every macro that uses tuples requires you to specify the size of the tuple. You could try doing something based on a 2 tuple where the first value is the size of the second:

#define MyTuple (2,(a,tuple))
#define MyTupleSize( S_ ) BOOST_PP_TUPLE_ELEM( 2, 0, S_ )
#define GetMyTuple( S_, I_ ) BOOST_PP_TUPLE_ELEM( MyTupleSize(S_), I_, BOOST_PP_TUPLE_ELEM(2, 1, S_ ) )
MyTupleSize( MyTuple ) // this is '2'
GetMyTuple( MyTuple, 1 )// this is 'tuple'

Unfortunately there is no way to determine the size of a tuple other than to know it or store it in a known sized tuple or in a list etc.

KitsuneYMG