Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
amdis-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
amdis
amdis-core
Commits
2222b5c8
Commit
2222b5c8
authored
5 years ago
by
Praetorius, Simon
Browse files
Options
Downloads
Patches
Plain Diff
added some comments to switch cases
parent
11a18eb6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!51
add hybrid utility SwitchCases for dynamic and static dispatching
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/amdis/common/SwitchCases.hpp
+0
-92
0 additions, 92 deletions
src/amdis/common/SwitchCases.hpp
with
0 additions
and
92 deletions
src/amdis/common/SwitchCases.hpp
+
0
−
92
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
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