Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
0a926954
There was an error fetching the commit references. Please try again later.
Commit
0a926954
authored
5 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
Writing TemplateStaticFor documentation.
parent
4c64b1fa
No related branches found
No related tags found
1 merge request
!44
Tutorials
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Documentation/Examples/Algorithms/TemplateStaticForExample.cpp
+15
-12
15 additions, 12 deletions
...entation/Examples/Algorithms/TemplateStaticForExample.cpp
src/TNL/Algorithms/TemplateStaticFor.h
+25
-0
25 additions, 0 deletions
src/TNL/Algorithms/TemplateStaticFor.h
with
40 additions
and
12 deletions
Documentation/Examples/Algorithms/TemplateStaticForExample.cpp
+
15
−
12
View file @
0a926954
#include
<iostream>
#include
<cstdlib>
#include
<TNL/Containers/StaticVector.h>
#include
<TNL/Algorithms/StaticFor.h>
#include
<TNL/Algorithms/
Template
StaticFor.h>
using
namespace
TNL
;
using
namespace
TNL
::
Containers
;
const
int
Size
(
5
);
template
<
int
I
>
struct
LoopBody
{
static
void
exec
(
const
StaticVector
<
Size
,
double
>&
v
)
{
std
::
cout
<<
"v[ "
<<
I
<<
" ] = "
<<
v
[
I
]
<<
std
::
endl
;
}
};
int
main
(
int
argc
,
char
*
argv
[]
)
{
/****
*
Create two
static vector
s
*
Initiate
static vector
*/
const
int
Size
(
3
);
StaticVector
<
Size
,
double
>
a
,
b
;
a
=
1.0
;
b
=
2.0
;
double
sum
(
0.0
);
StaticVector
<
Size
,
double
>
v
{
1.0
,
2.0
,
3.0
,
4.0
,
5.0
};
/****
*
Compute an addition of a vector and a constant number
.
*
Print out the vector using template parameters for indexing
.
*/
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
;
Algorithms
::
TemplateStaticFor
<
0
,
Size
,
LoopBody
>::
exec
(
v
);
}
This diff is collapsed.
Click to expand it.
src/TNL/Algorithms/TemplateStaticFor.h
+
25
−
0
View file @
0a926954
...
...
@@ -17,6 +17,31 @@
namespace
TNL
{
namespace
Algorithms
{
/**
* \brief TemplateStaticFor serves for coding for-loops in template parameters.
*
* The result of calling this loop with a templated class \p LoopBody is as follows:
*
* LoopBody< begin >::exec( ... );
*
* LoodBody< begin + 1 >::exec( ... );
*
* ...
*
* LoopBody< end - 1 >::exec( ... );
*
* \tparam IndexType is type of the loop indexes
* \tparam begin the loop iterates over index interval [begin,end).
* \tparam end the loop iterates over index interval [begin,end).
* \tparam LoopBody is a templated class having one template parameter of IndexType.
*/
template
<
typename
IndexType
,
IndexType
begin
,
IndexType
end
,
template
<
IndexType
>
class
LoopBody
>
struct
TemplateStaticFor
;
namespace
detail
{
template
<
typename
IndexType
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment