diff options
Diffstat (limited to 'doc/snippets')
-rw-r--r-- | doc/snippets/TopicAliasing_block.cpp | 2 | ||||
-rw-r--r-- | doc/snippets/TopicAliasing_block_correct.cpp | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/doc/snippets/TopicAliasing_block.cpp b/doc/snippets/TopicAliasing_block.cpp index 7d40cfafd..03282f4f0 100644 --- a/doc/snippets/TopicAliasing_block.cpp +++ b/doc/snippets/TopicAliasing_block.cpp @@ -1,5 +1,7 @@ MatrixXi mat(3,3); mat << 1, 2, 3, 4, 5, 6, 7, 8, 9; cout << "Here is the matrix mat:\n" << mat << endl; + +// This assignment shows the aliasing problem mat.bottomRightCorner(2,2) = mat.topLeftCorner(2,2); cout << "After the assignment, mat = \n" << mat << endl; diff --git a/doc/snippets/TopicAliasing_block_correct.cpp b/doc/snippets/TopicAliasing_block_correct.cpp new file mode 100644 index 000000000..6fee5801e --- /dev/null +++ b/doc/snippets/TopicAliasing_block_correct.cpp @@ -0,0 +1,7 @@ +MatrixXi mat(3,3); +mat << 1, 2, 3, 4, 5, 6, 7, 8, 9; +cout << "Here is the matrix mat:\n" << mat << endl; + +// The eval() solves the aliasing problem +mat.bottomRightCorner(2,2) = mat.topLeftCorner(2,2).eval(); +cout << "After the assignment, mat = \n" << mat << endl; |