aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/snippets
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-11-12 22:06:33 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-11-12 22:06:33 +0100
commitc81bdbdadc72b96dda3c4a120bfb189df62ece18 (patch)
treec8b348d22d891a70322ef9caed6001c949f301af /doc/snippets
parent0105146915c62f732841bb63d5c2046ed7cb3864 (diff)
Add manual doc on STL-compatible iterators
Diffstat (limited to 'doc/snippets')
-rw-r--r--doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp4
-rw-r--r--doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp5
-rw-r--r--doc/snippets/Tutorial_std_sort.cpp4
-rw-r--r--doc/snippets/Tutorial_std_sort_rows.cpp5
4 files changed, 18 insertions, 0 deletions
diff --git a/doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp b/doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp
new file mode 100644
index 000000000..d8e582ad5
--- /dev/null
+++ b/doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp
@@ -0,0 +1,4 @@
+VectorXi v = VectorXi::Random(4);
+cout << "Here is the vector v:\n";
+for(auto x : v) cout << x << " ";
+cout << "\n"; \ No newline at end of file
diff --git a/doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp b/doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp
new file mode 100644
index 000000000..7e532d3c8
--- /dev/null
+++ b/doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp
@@ -0,0 +1,5 @@
+Matrix2i A = Matrix2i::Random();
+cout << "Here are the coeffs of the 2x2 matrix A:\n";
+for(auto x : A.reshaped())
+ cout << x << " ";
+cout << "\n"; \ No newline at end of file
diff --git a/doc/snippets/Tutorial_std_sort.cpp b/doc/snippets/Tutorial_std_sort.cpp
new file mode 100644
index 000000000..8f893684a
--- /dev/null
+++ b/doc/snippets/Tutorial_std_sort.cpp
@@ -0,0 +1,4 @@
+Array4i v = Array4i::Random().abs();
+cout << "Here is the initial vector v:\n" << v.transpose() << "\n";
+std::sort(v.begin(), v.end());
+cout << "Here is the sorted vector v:\n" << v.transpose() << "\n"; \ No newline at end of file
diff --git a/doc/snippets/Tutorial_std_sort_rows.cpp b/doc/snippets/Tutorial_std_sort_rows.cpp
new file mode 100644
index 000000000..fdd850d13
--- /dev/null
+++ b/doc/snippets/Tutorial_std_sort_rows.cpp
@@ -0,0 +1,5 @@
+ArrayXXi A = ArrayXXi::Random(4,4).abs();
+cout << "Here is the initial matrix A:\n" << A << "\n";
+for(auto row : A.rowwise())
+ std::sort(row.begin(), row.end());
+cout << "Here is the sorted matrix A:\n" << A << "\n"; \ No newline at end of file