Commit 2222b5c8 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added some comments to switch cases

parent 11a18eb6
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment