Initialization and Assignment

Contents

Direct Initialization

The basic ntuple<> declaration can take upto 8 template type arguments. References to the ntuple<>'s elements are accessed with the get< N >() (also at< N >()) member template (where N is >= 0 and < then number of template arguments given in ntuple<>'s template paramiter list).

ntuple< int , double > id( 10, 2.3 );

std::cout << id.get< 0 >() << '\n';
std::cout << id.get< 1 >() << '\n';

CHECK( id.get< 1 >() == 2.3 );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

10
2.3

Other Constructors

ntuple<> has a default constructor, a copy contstuctor and an element-wise constuctor (used above) that takes arguments convertable to the ntuple<>'s element types.

ntuple< int, double > default_constructed;

// poor-man's initialize:
default_constructed.set<0>(2).set<1>(2.3);

ntuple< int, double > copy( default_constructed );

std::cout << copy << std::endl;

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(2,2.3)

Assignment

An ntuple<> can be assigned by any other ntuple<> that has element types that are convertable to the assignee's element type.

ntuple< int, double > int_double( 0, 0 );
ntuple< long, float > long_float( 1, 2.3F );

int_double = long_float;

CHECK( int_double.at< 0 >() == long_float.at< 0 >() );

std::cout << int_double << std::endl;

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(1,2.3)