From 44d08f19a74a33e0034f737b04ee0284f6f10069 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Tue, 19 Nov 2019 16:32:56 +0100 Subject: [PATCH] Writing documentation on StaticFor. --- .../Examples/Algorithms/StaticForExample.cpp | 28 +++++++++++++++++++ .../Tutorials/ForLoops/StaticForExample-3.cpp | 5 +--- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Documentation/Examples/Algorithms/StaticForExample.cpp diff --git a/Documentation/Examples/Algorithms/StaticForExample.cpp b/Documentation/Examples/Algorithms/StaticForExample.cpp new file mode 100644 index 0000000000..47757458d7 --- /dev/null +++ b/Documentation/Examples/Algorithms/StaticForExample.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <cstdlib> +#include <TNL/Containers/StaticVector.h> +#include <TNL/Algorithms/StaticFor.h> + +using namespace TNL; +using namespace TNL::Containers; + +int main( int argc, char* argv[] ) +{ + /**** + * Create two static vectors + */ + const int Size( 3 ); + StaticVector< Size, double > a, b; + a = 1.0; + b = 2.0; + double sum( 0.0 ); + + /**** + * Compute an addition of a vector and a constant number. + */ + auto addition = [&]( int i, const double& c ) { a[ i ] = b[ i ] + c; sum += a[ i ]; }; + Algorithms::StaticFor< 0, Size >::exec( addition, 3.14 ); + std::cout << "a = " << a << std::endl; + std::cout << "sum = " << sum << std::endl; +} + diff --git a/Documentation/Tutorials/ForLoops/StaticForExample-3.cpp b/Documentation/Tutorials/ForLoops/StaticForExample-3.cpp index 7ee4afd72c..5298b00a13 100644 --- a/Documentation/Tutorials/ForLoops/StaticForExample-3.cpp +++ b/Documentation/Tutorials/ForLoops/StaticForExample-3.cpp @@ -1,4 +1 @@ -for( int i = 0; i < Size; i++ ) -{ - a[ i ] = b[ i ] + c; sum += a[ i ]; -}; +Algorithms::StaticFor< 0, Size, true >::exec( addition, 3.14 ); \ No newline at end of file -- GitLab