Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
amdis
amdis-core
Commits
58ebcd51
Commit
58ebcd51
authored
Nov 29, 2020
by
Praetorius, Simon
Browse files
Add treepath literal _tp and a test
parent
ba263fc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
amdis/typetree/TreePath.hpp
View file @
58ebcd51
#pragma once
#include
<cassert>
#include
<sstream>
#include
<string>
#include
<type_traits>
...
...
@@ -10,6 +11,7 @@
#include
<dune/typetree/typetraits.hh>
#include
<amdis/common/Apply.hpp>
#include
<amdis/common/Literals.hpp>
#include
<amdis/common/Logical.hpp>
namespace
AMDiS
{
...
...
@@ -150,6 +152,14 @@ auto makeTreePath(Dune::TypeTree::StaticTreePath<I...>)
#endif // DOXYGEN
/// Literal to create treepath, e.g. 021_tp -> HybridTreePath<index_t<0>,index_t<2>,index_t<1>>
template
<
char
...
digits
>
constexpr
auto
operator
""
_tp
()
{
return
Dune
::
TypeTree
::
hybridTreePath
(
std
::
integral_constant
<
std
::
size_t
,
Impl
::
char2digit
(
digits
)
>
{}...);
}
// convert a treepath into a string, comma-separated
template
<
class
...
T
>
std
::
string
to_string
(
Dune
::
TypeTree
::
HybridTreePath
<
T
...
>
const
&
tp
)
...
...
test/TreePathTest.cpp
View file @
58ebcd51
...
...
@@ -10,6 +10,16 @@
using
namespace
AMDiS
;
using
namespace
Dune
::
Indices
;
template
<
class
...
I
,
class
...
J
,
std
::
enable_if_t
<
(
sizeof
...(
I
)
==
sizeof
...(
J
)),
int
>
=
0
>
bool
compare
(
Dune
::
TypeTree
::
HybridTreePath
<
I
...
>
const
&
tp1
,
Dune
::
TypeTree
::
HybridTreePath
<
J
...
>
const
&
tp2
)
{
return
Ranges
::
applyIndices
<
sizeof
...(
I
)
>
([
&
](
auto
...
i
)
{
return
((
tp1
[
i
]
==
tp2
[
i
])
&&
...);
});
}
int
main
(
int
argc
,
char
**
argv
)
{
Environment
env
(
argc
,
argv
);
...
...
@@ -36,4 +46,11 @@ int main (int argc, char** argv)
auto
tp
=
Dune
::
TypeTree
::
hybridTreePath
(
1u
,
_2
);
static_assert
(
std
::
is_same_v
<
TYPEOF
(
tp
),
TYPEOF
(
makeTreePath
(
tp
))
>
);
AMDIS_TEST
(
compare
(
tp
,
12
_tp
));
AMDIS_TEST
(
compare
(
makeTreePath
(
1
,
2
),
12
_tp
));
AMDIS_TEST
(
compare
(
makeTreePath
(
0
,
1
,
2
),
012
_tp
));
AMDIS_TEST
(
compare
(
makeTreePath
(
0
,
0
,
1
,
2
),
0012
_tp
));
return
report_errors
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment