New ntuple<>'s can be created no the fly (in expressions) with the inserter [1] operator operator << ()
ntuple< int, double, char > tuple( 1, 2.0, 'c' );
ntuple< int, int > a( 1, 2 ), b( 3, 4 );
std::cout << a << b << std::endl;
std::cout << (a << b) << std::endl;
std::cout << (a << 5) << std::endl;
CHECK( ntuple_( 1, 2, 3, 4 ) == (a << b) );
ntuple< double > d1( 1.2 );
ntuple< double, int > di( d1 << 3 );
std::cout << di << std::endl;
CHECK( ntuple_( 1.2, 3 ) == di );
Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed
Output
(1,2)(3,4) (1,2,3,4) (1,2,5) (1.2,3)
Currently as the inserter can only be used to create expression temporaries the created tuple is a tuple of constant references (T const &) to the (elements of) its argument.
This might change when/if the auto/decltype proposal becomes standard C++
As bound temporaries will not live long enough.
| [1] | inserter and "insertion" is used here as it corresponds to the extractor operator (operator >> ()) and also as the terms extractor and inserter are used with C++ iostream's. |