From c81bdbdadc72b96dda3c4a120bfb189df62ece18 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 12 Nov 2018 22:06:33 +0100 Subject: Add manual doc on STL-compatible iterators --- doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp | 4 ++++ doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp | 5 +++++ doc/snippets/Tutorial_std_sort.cpp | 4 ++++ doc/snippets/Tutorial_std_sort_rows.cpp | 5 +++++ 4 files changed, 18 insertions(+) create mode 100644 doc/snippets/Tutorial_range_for_loop_1d_cxx11.cpp create mode 100644 doc/snippets/Tutorial_range_for_loop_2d_cxx11.cpp create mode 100644 doc/snippets/Tutorial_std_sort.cpp create mode 100644 doc/snippets/Tutorial_std_sort_rows.cpp (limited to 'doc/snippets') 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 -- cgit v1.2.3