Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
Core Modules
dune-common
Commits
3d5152be
There was a problem fetching the pipeline summary.
Commit
3d5152be
authored
8 years ago
by
Carsten Gräser
Committed by
Christoph Grüninger
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[test][cleanup] Use Dune::TupleVector instead of local implementation
parent
38d5ba56
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!212
Fix link to build system doc
,
!134
Add the TupleVector class
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/test/hybridutilitiestest.cc
+6
-46
6 additions, 46 deletions
dune/common/test/hybridutilitiestest.cc
dune/common/test/indicestest.cc
+2
-17
2 additions, 17 deletions
dune/common/test/indicestest.cc
with
8 additions
and
63 deletions
dune/common/test/hybridutilitiestest.cc
+
6
−
46
View file @
3d5152be
...
...
@@ -9,50 +9,10 @@
#include
<vector>
#include
<dune/common/hybridutilities.hh>
#include
<dune/common/tuplevector.hh>
#include
<dune/common/test/testsuite.hh>
/** \brief A std::tuple that allows access to its element via operator[]
*
* Since there is no heterogeneous container in dune-common that supports
* operator[std::integralconstant<T,i>] we make our own for the test.
*/
template
<
class
...
T
>
class
TupleVector
:
public
std
::
tuple
<
T
...
>
{
using
Base
=
std
::
tuple
<
T
...
>
;
public:
using
Base
::
Base
;
/** \brief Array-style access to the tuple elements */
template
<
std
::
size_t
i
>
decltype
(
auto
)
operator
[](
const
Dune
::
index_constant
<
i
>&
)
{
return
std
::
get
<
i
>
(
*
this
);
}
template
<
std
::
size_t
i
>
constexpr
decltype
(
auto
)
operator
[](
const
Dune
::
index_constant
<
i
>&
)
const
{
return
std
::
get
<
i
>
(
*
this
);
}
static
constexpr
auto
size
()
{
return
std
::
tuple_size
<
Base
>::
value
;
}
};
template
<
class
...
T
>
constexpr
auto
makeTupleVector
(
T
&&
...
t
)
{
// The std::decay_t<T> is is a slight simplification,
// because std::reference_wrapper needs special care.
return
TupleVector
<
std
::
decay_t
<
T
>
...
>
(
std
::
forward
<
T
>
(
t
)...);
}
template
<
class
C
>
auto
incrementAll
(
C
&&
c
)
...
...
@@ -91,7 +51,7 @@ auto incAndAppendToFirst(C&& c)
int
main
()
{
auto
vector
=
std
::
vector
<
int
>
{
1
,
2
,
3
};
auto
numberTuple
=
makeTupleVector
(
0.1
,
2
,
3
);
auto
numberTuple
=
Dune
::
makeTupleVector
(
0.1
,
2
,
3
);
Dune
::
TestSuite
test
;
...
...
@@ -100,7 +60,7 @@ int main()
<<
"Incrementing vector entries with Hybrid::forEach failed."
;
incrementAll
(
numberTuple
);
test
.
check
(
numberTuple
==
makeTupleVector
(
1.1
,
3
,
4
))
test
.
check
(
numberTuple
==
Dune
::
makeTupleVector
(
1.1
,
3
,
4
))
<<
"Incrementing tuple entries with Hybrid::forEach failed."
;
addIndex
(
vector
);
...
...
@@ -108,13 +68,13 @@ int main()
<<
"Adding indices to vector entries with Hybrid::forEach failed."
;
addIndex
(
numberTuple
);
test
.
check
(
numberTuple
==
makeTupleVector
(
1.1
,
4
,
6
))
test
.
check
(
numberTuple
==
Dune
::
makeTupleVector
(
1.1
,
4
,
6
))
<<
"Adding indices to vector entries with Hybrid::forEach failed."
;
auto
mixedTuple
=
makeTupleVector
(
std
::
string
(
"1"
),
2
,
3
);
auto
mixedTuple
=
Dune
::
makeTupleVector
(
std
::
string
(
"1"
),
2
,
3
);
incAndAppendToFirst
(
mixedTuple
);
test
.
check
(
mixedTuple
==
makeTupleVector
(
std
::
string
(
"1+1"
),
3
,
4
))
test
.
check
(
mixedTuple
==
Dune
::
makeTupleVector
(
std
::
string
(
"1+1"
),
3
,
4
))
<<
"Adding indices to vector entries with Hybrid::forEach failed."
;
return
test
.
exit
();
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/indicestest.cc
+
2
−
17
View file @
3d5152be
...
...
@@ -7,25 +7,10 @@
#include
<tuple>
#include
<dune/common/indices.hh>
#include
<dune/common/tuplevector.hh>
using
namespace
Dune
;
/** \brief A std::tuple that allows access to its element via operator[]
*
* Helper class to test the static indices with
*/
template
<
class
...
T
>
struct
TupleVector
:
public
std
::
tuple
<
T
...
>
{
/** \brief Array-style access to the tuple elements */
template
<
std
::
size_t
i
>
auto
operator
[](
const
index_constant
<
i
>&
)
->
decltype
(
std
::
get
<
i
>
(
*
this
))
{
return
std
::
get
<
i
>
(
*
this
);
}
};
int
main
()
...
...
@@ -33,7 +18,7 @@ int main()
using
namespace
Dune
::
Indices
;
// Test whether indices can be used to index a data structure
TupleVector
<
int
,
double
,
float
>
v
;
Dune
::
TupleVector
<
int
,
double
,
float
>
v
;
v
[
_0
]
=
42
;
v
[
_1
]
=
3.14
;
v
[
_2
]
=
2.7
;
...
...
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