From 4759d9e86dea0b4b964e6590e68319cedf6a64e1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 17 Jan 2019 10:35:14 +0100 Subject: Doc: add manual page on STL iterators --- doc/TutorialSTL.dox | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 doc/TutorialSTL.dox (limited to 'doc') diff --git a/doc/TutorialSTL.dox b/doc/TutorialSTL.dox new file mode 100644 index 000000000..9f41528d3 --- /dev/null +++ b/doc/TutorialSTL.dox @@ -0,0 +1,66 @@ +namespace Eigen { + +/** \eigenManualPage TutorialSTL STL iterators and algorithms + +Since the version 3.4, %Eigen's dense matrices and arrays provide STL compatible iterators. +As demonstrated below, this makes them naturally compatible with range-for-loops and STL's algorithms. + +\eigenAutoToc + +\section TutorialSTLVectors Iterating over 1D arrays and vectors + +Any dense 1D expressions exposes the pair of `begin()/end()` methods to iterate over them. + +This directly enables c++11 range for loops: + + + +
Example:Output:
+\include Tutorial_range_for_loop_1d_cxx11.cpp + +\verbinclude Tutorial_range_for_loop_1d_cxx11.out +
+ +One dimensional expressions can also easily be passed to STL algorithms: + + + +
Example:Output:
+\include Tutorial_std_sort.cpp + +\verbinclude Tutorial_std_sort.out +
+ +Similar to `std::vector`, 1D expressions also exposes the pair of `cbegin()/cend()` methods to conveniently get const iterators on non-const object. + +\section TutorialSTLMatrices Iterating over coefficients of 2D arrays and matrices + +STL iterators are intrinsically designed to iterate over 1D structures. +This is why `begin()/end()` methods are disabled for 2D expressions. +Iterating over all coefficients of a 2D expressions is still easily accomplished by creating a 1D linear view through `reshaped()`: + + + +
Example:Output:
+\include Tutorial_range_for_loop_2d_cxx11.cpp + +\verbinclude Tutorial_range_for_loop_2d_cxx11.out +
+ +\section TutorialSTLRowsColumns Iterating over rows or columns of 2D arrays and matrices + +It is also possible to get iterators over rows or columns of 2D expressions. +Those are available through the `rowwise()` and `colwise()` proxies. +Here is an example sorting each row of a matrix: + + + +
Example:Output:
+\include Tutorial_std_sort_rows.cpp + +\verbinclude Tutorial_std_sort_rows.out +
+ +*/ + +} -- cgit v1.2.3