diff --git a/Documentation/Examples/Algorithms/StaticForExample.cpp b/Documentation/Examples/Algorithms/StaticForExample.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47757458d71505fa585f3624575bcdaa55869602 --- /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 7ee4afd72c42e2bf0fd8db28bd3f5e7c3c47cc0f..5298b00a138b547d4fac56af327a146771eae13e 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