aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/snippets
diff options
context:
space:
mode:
authorGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2010-08-23 17:23:30 +0100
committerGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2010-08-23 17:23:30 +0100
commit474c2996bd7da42663bdc7696c2143f1ab1f1af5 (patch)
tree2a4f6a7e243b5c6549624a0b250dce0d96ff2ad4 /doc/snippets
parentd1111d625ccfc29a4b4a0db0192cbf6e2fdedf3c (diff)
Docs: add section on resolving the aliasing issue.
Diffstat (limited to 'doc/snippets')
-rw-r--r--doc/snippets/TopicAliasing_block.cpp2
-rw-r--r--doc/snippets/TopicAliasing_block_correct.cpp7
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;