diff options
author | Gael Guennebaud <g.gael@free.fr> | 2019-01-22 17:08:47 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2019-01-22 17:08:47 +0100 |
commit | 80f81f9c4b01cc4f513c5b92c52c5a0efb68ecc3 (patch) | |
tree | 6e9c61e63dcb690afb48f40e1d470ed2c735ceff /doc | |
parent | db152b9ee6effd3799f70a621f495c427cb3c33f (diff) |
Cleanup SFINAE in Array/Matrix(initializer_list) ctors and minor doc editing.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/TutorialMatrixClass.dox | 29 | ||||
-rw-r--r-- | doc/snippets/Array_initializer_list_23_cxx11.cpp | 5 | ||||
-rw-r--r-- | doc/snippets/Array_initializer_list_cxx11.cpp | 6 | ||||
-rw-r--r-- | doc/snippets/Array_initializer_list_vector_cxx11.cpp | 2 | ||||
-rw-r--r-- | doc/snippets/Matrix_initializer_list_23_cxx11.cpp | 5 | ||||
-rw-r--r-- | doc/snippets/Matrix_initializer_list_cxx11.cpp | 6 | ||||
-rw-r--r-- | doc/snippets/Matrix_initializer_list_vector_cxx11.cpp | 2 |
7 files changed, 29 insertions, 26 deletions
diff --git a/doc/TutorialMatrixClass.dox b/doc/TutorialMatrixClass.dox index fc0ce5b1e..c44c8f24f 100644 --- a/doc/TutorialMatrixClass.dox +++ b/doc/TutorialMatrixClass.dox @@ -101,38 +101,39 @@ Matrix3f a(3,3); \endcode and is a no-operation. -Additionally, we also offer some constructors to initialize the coefficients of small fixed-size vectors up to size 4: +Matrices and vectors can also be initialized from lists of coefficients. +Prior to C++11, this feature is limited to small fixed-size column or vectors up to size 4: \code Vector2d a(5.0, 6.0); Vector3d b(5.0, 6.0, 7.0); Vector4d c(5.0, 6.0, 7.0, 8.0); \endcode -If C++11 is enabled, matrices can be constructed and initialized using initializer lists. In the case of fixed-sized vectors -and rowvectors a simple initializer list can be passed: +If C++11 is enabled, fixed-size column or row vectors of arbitrary size can be initialized through a single initializer list (\link Matrix::Matrix(const std::initializer_list<Scalar>&) details \endlink): \code -Vector2i a {1, 2}; // A vector containing the elements {1, 2} -Matrix<int, 4, 1> b {1, 2, 3, 4}; // A row-vector containing the elements {1, 2, 3, 4} -Matrix<int, 1, 4> c {1, 2, 3, 4}; // A vector containing the elements {1, 2, 3, 4} +Vector2i a {1, 2}; // A column vector containing the elements {1, 2} +Matrix<int, 5, 1> b {1, 2, 3, 4, 5}; // A row-vector containing the elements {1, 2, 3, 4, 5} +Matrix<int, 1, 5> c {1, 2, 3, 4, 5}; // A column vector containing the elements {1, 2, 3, 4, 5} \endcode -In the case of fixed or dynamically sized matrices an initializer list containing an initializer list for each row -can be passed. If the matrix is fixed-sized, the number of elements that are passed must match the dimensions. +In the general case of matrices and vectors with either fixed or runtime sizes, +coefficients have to be grouped by rows and passed as an initializer list of initializer list (\link Matrix::Matrix(const std::initializer_list<std::initializer_list<Scalar>>&) details \endlink): \code -MatrixXi a { +MatrixXi a { // construct a 2x2 matrix {1, 2}, // first row {3, 4} // second row }; Matrix<double, 2, 3> b { - {2.0, 3.0, 4.0}, - {5.0, 6.0, 7.0}, + {2, 3, 4}, + {5, 6, 7}, }; \endcode -In the case of vectors and rowvectors, the following shorthand notation can be used: +For column or row vectors, implicit transposition is allowed. +This means that a column vector can be initialized from a single row: \code -VectorXd a {{1.5, 2.5, 3.5}}; // A vector with 3 rows -RowVectorXd b {{1.0, 2.0, 3.0, 4.0}}; // A rowvector with 4 columns +VectorXd a {{1.5, 2.5, 3.5}}; // A column-vector with 3 coefficients +RowVectorXd b {{1.0, 2.0, 3.0, 4.0}}; // A row-vector with 4 coefficients \endcode \section TutorialMatrixCoeffAccessors Coefficient accessors diff --git a/doc/snippets/Array_initializer_list_23_cxx11.cpp b/doc/snippets/Array_initializer_list_23_cxx11.cpp new file mode 100644 index 000000000..1ea32dd80 --- /dev/null +++ b/doc/snippets/Array_initializer_list_23_cxx11.cpp @@ -0,0 +1,5 @@ +ArrayXXi a { + {1, 2, 3}, + {3, 4, 5} +}; +cout << a << endl;
\ No newline at end of file diff --git a/doc/snippets/Array_initializer_list_cxx11.cpp b/doc/snippets/Array_initializer_list_cxx11.cpp deleted file mode 100644 index d2f46e268..000000000 --- a/doc/snippets/Array_initializer_list_cxx11.cpp +++ /dev/null @@ -1,6 +0,0 @@ -Array<int, 2, 3> a { - {1, 2, 3}, - {3, 4, 5} -}; -Array<int, Dynamic, 1> v {{1, 2, 3, 4, 5}}; -cout << a << "\n\n" << v << endl;
\ No newline at end of file diff --git a/doc/snippets/Array_initializer_list_vector_cxx11.cpp b/doc/snippets/Array_initializer_list_vector_cxx11.cpp new file mode 100644 index 000000000..e38b61e95 --- /dev/null +++ b/doc/snippets/Array_initializer_list_vector_cxx11.cpp @@ -0,0 +1,2 @@ +Array<int, Dynamic, 1> v {{1, 2, 3, 4, 5}}; +cout << v << endl;
\ No newline at end of file diff --git a/doc/snippets/Matrix_initializer_list_23_cxx11.cpp b/doc/snippets/Matrix_initializer_list_23_cxx11.cpp new file mode 100644 index 000000000..d338d0253 --- /dev/null +++ b/doc/snippets/Matrix_initializer_list_23_cxx11.cpp @@ -0,0 +1,5 @@ +MatrixXd m { + {1, 2, 3}, + {4, 5, 6} +}; +cout << m << endl;
\ No newline at end of file diff --git a/doc/snippets/Matrix_initializer_list_cxx11.cpp b/doc/snippets/Matrix_initializer_list_cxx11.cpp deleted file mode 100644 index d68787ab6..000000000 --- a/doc/snippets/Matrix_initializer_list_cxx11.cpp +++ /dev/null @@ -1,6 +0,0 @@ -Matrix<int, 2, 3> m { - {1, 2, 3}, - {4, 5, 6} -}; -VectorXi v {{1, 2}}; -cout << m << "\n\n" << v << endl;
\ No newline at end of file diff --git a/doc/snippets/Matrix_initializer_list_vector_cxx11.cpp b/doc/snippets/Matrix_initializer_list_vector_cxx11.cpp new file mode 100644 index 000000000..8872e2cf3 --- /dev/null +++ b/doc/snippets/Matrix_initializer_list_vector_cxx11.cpp @@ -0,0 +1,2 @@ +VectorXi v {{1, 2}}; +cout << v << endl;
\ No newline at end of file |