Skip to content
GitLab
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
2222b5c8
Commit
2222b5c8
authored
May 08, 2019
by
Praetorius, Simon
Browse files
added some comments to switch cases
parent
11a18eb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/amdis/common/SwitchCases.hpp
View file @
2222b5c8
...
...
@@ -27,54 +27,6 @@ namespace AMDiS
return
elseBranch
(
value
);
}
// specialization for the case value in {0}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
1
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
,
Else
&&
elseBranch
)
{
return
std
::
size_t
(
value
)
==
std
::
size_t
(
0
)
?
thenBranch
(
index_t
<
0
>
{})
:
elseBranch
();
}
// specialization for the case value in {0,1}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
2
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
,
Else
&&
elseBranch
)
{
switch
(
std
::
size_t
(
value
))
{
case
0u
:
return
thenBranch
(
index_t
<
0
>
{});
case
1u
:
return
thenBranch
(
index_t
<
1
>
{});
default:
return
elseBranch
();
}
}
// specialization for the case value in {0,1,2}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
3
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
,
Else
&&
elseBranch
)
{
switch
(
std
::
size_t
(
value
))
{
case
0u
:
return
thenBranch
(
index_t
<
0
>
{});
case
1u
:
return
thenBranch
(
index_t
<
1
>
{});
case
2u
:
return
thenBranch
(
index_t
<
2
>
{});
default:
return
elseBranch
();
}
}
// specialization for the case value in {0,1,2,3}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
4
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
,
Else
&&
elseBranch
)
{
switch
(
std
::
size_t
(
value
))
{
case
0u
:
return
thenBranch
(
index_t
<
0
>
{});
case
1u
:
return
thenBranch
(
index_t
<
1
>
{});
case
2u
:
return
thenBranch
(
index_t
<
2
>
{});
case
3u
:
return
thenBranch
(
index_t
<
3
>
{});
default:
return
elseBranch
();
}
}
// static switching. Iterates over all possible values
template
<
class
T
,
T
to
,
T
from
,
class
Value
,
class
Then
>
constexpr
void
switchCases
(
const
Dune
::
StaticIntegralRange
<
T
,
to
,
from
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
)
...
...
@@ -91,48 +43,4 @@ namespace AMDiS
thenBranch
(
value
);
}
// specialization for the case value in {0}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
1
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
)
{
assert
(
std
::
size_t
(
value
)
<
1u
);
return
thenBranch
(
index_t
<
0
>
{});
}
// specialization for the case value in {0,1}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
2
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
)
{
assert
(
std
::
size_t
(
value
)
<
2u
);
switch
(
std
::
size_t
(
value
))
{
case
0u
:
return
thenBranch
(
index_t
<
0
>
{});
default:
return
thenBranch
(
index_t
<
1
>
{});
}
}
// specialization for the case value in {0,1,2}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
3
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
)
{
assert
(
std
::
size_t
(
value
)
<
3u
);
switch
(
std
::
size_t
(
value
))
{
case
0u
:
return
thenBranch
(
index_t
<
0
>
{});
case
1u
:
return
thenBranch
(
index_t
<
1
>
{});
default:
return
thenBranch
(
index_t
<
2
>
{});
}
}
// specialization for the case value in {0,1,2,3}
template
<
class
Value
,
class
Then
,
class
Else
>
constexpr
decltype
(
auto
)
switchCases
(
const
Dune
::
StaticIntegralRange
<
std
::
size_t
,
4
,
0
>&
cases
,
const
Value
&
value
,
Then
&&
thenBranch
)
{
assert
(
std
::
size_t
(
value
)
<
3u
);
switch
(
std
::
size_t
(
value
))
{
case
0u
:
return
thenBranch
(
index_t
<
0
>
{});
case
1u
:
return
thenBranch
(
index_t
<
1
>
{});
case
2u
:
return
thenBranch
(
index_t
<
2
>
{});
default:
return
thenBranch
(
index_t
<
3
>
{});
}
}
}
// end namespace AMDiS
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment