See Extracting Elements and also Skipping Elements below.
operator >> () can be used for extracting sub-tuples.
ntuple< int, double, char, bool > idcb( 1, 2.0, 'c', false ); ntuple< int, double > id; char c; bool b; idcb >> id >> c >> b; std::cout << std::boolalpha; std::cout << idcb << " >> " << id << " >> " << c << " >> " << b << std::endl; CHECK( id == ntuple_( 1, 2.0 ) && c == 'c' && !b );
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
(1,2,c,false) >> (1,2) >> c >> false
When extacting elements of sub-tuples a convinience method is provided so that unwanted values can be skipped.
ntuple<> has a static template member skip< N >() that returns a type that encapsulates the compile-time constant [1] number of elements to be skipped.
This value used as an extractor (tuple >> tuple.skip<2>() >> third_value) causes N elements to be skipped.
ntuple< int, double, char, bool > tuple( 1, 2.0, 'c', false ); int i; bool b; tuple >> i >> tuple.skip< 2 >() >> b; std::cout << std::boolalpha; std::cout << tuple << " >> " << i << " >> tuple.skip< 2 >() >> " << b << std::endl; CHECK( i == 1 && !b );
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
(1,2,c,false) >> 1 >> tuple.skip< 2 >() >> false
As a further convinience the value 0 (or infact any bool or bool convertable constant [2]) can be used to skip a single element.
ntuple< int, double, char > tuple( 1, 2.0, 'c' ); int i; char c; tuple >> i >> 0 >> c; std::cout << tuple << " >> " << i << " >> 0 >> " << c << std::endl; CHECK( i == 1 && c == 'c' );
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
(1,2,c) >> 1 >> 0 >> c
| [1] | skip< N >() returns a imp::meta::int_type< N > |
| [2] | Yes its a Hack. |