How could comma separated initialization such as in Eigen be possibly implemented in C++? -
How could comma separated initialization such as in Eigen be possibly implemented in C++? -
here's part of eigen documentation:
matrix3f m; m << 1, 2, 3, 4, 5, 6, 7, 8, 9; std::cout << m; output:
1 2 3 4 5 6 7 8 9 i couldn't understand how comma separated values captured operator<< above. did tiny experiment:
cout << "just commas: "; cout << 1, 2, 3, 4, 5; cout << endl; cout << "commas in parentheses: "; cout << ( 1, 2, 3, 4, 5 ); cout << endl; predictably (according understanding of c++ syntax) 1 of values captured operator<< :
just commas: 1 commas in parentheses: 5 thus title question.
the basic thought overload both << , , operators.
m << 1 overloaded set 1 m , returns special proxy object - phone call p - holding reference m.
then p, 2 overloaded set 2 m , homecoming p, p, 2, 3 first set 2 m , 3.
a similar technique used boost.assign, though utilize += rather <<.
c++ initialization operator-overloading eigen
Comments
Post a Comment