3#ifndef DUNE_COMMON_OVERLOADSET_HH
4#define DUNE_COMMON_OVERLOADSET_HH
9#include <dune/common/std/type_traits.hh>
21 template<
class F0,
class... F>
22 class OverloadSet:
public OverloadSet<F...>, F0
24 using Base = OverloadSet<F...>;
27 template<
class FF0,
class... FF>
28 OverloadSet(FF0&& f0, FF&&... ff) :
29 Base(
std::forward<FF>(ff)...),
30 F0(
std::forward<FF0>(f0))
35 using Base::operator();
39 class OverloadSet<F0>:
public F0
44 OverloadSet(FF0&& f0) :
45 F0(
std::forward<FF0>(f0))
81 return Impl::OverloadSet<std::decay_t<F>...>(std::forward<F>(f)...);
88 template<
class F0,
class... F>
89 class OrderedOverloadSet:
public OrderedOverloadSet<F...>, F0
91 using Base = OrderedOverloadSet<F...>;
94 template<
class FF0,
class... FF>
95 OrderedOverloadSet(FF0&& f0, FF&&... ff) :
96 Base(
std::forward<FF>(ff)...),
97 F0(
std::forward<FF0>(f0))
101 template<
class... Args,
102 std::enable_if_t<Std::is_callable<F0(Args&&...)>::value,
int> = 0>
103 decltype(
auto)
operator()(Args&&... args)
105 return F0::operator()(std::forward<Args>(args)...);
111 template<
class... Args,
112 std::enable_if_t< not Std::is_callable<F0(Args&&...)>::value,
int> = 0>
113 decltype(
auto)
operator()(Args&&... args)
115 return Base::operator()(std::forward<Args>(args)...);
121 class OrderedOverloadSet<F0>:
public F0
126 OrderedOverloadSet(FF0&& f0) :
127 F0(
std::forward<FF0>(f0))
132 template<
class... Args>
133 decltype(
auto)
operator()(Args&&... args)
135 static_assert(Std::is_callable<F0(Args&&...)>::value,
"No matching overload found in OrderedOverloadSet");
136 return F0::operator()(std::forward<Args>(args)...);
167 return Impl::OrderedOverloadSet<std::decay_t<F>...>(std::forward<F>(f)...);
Dune namespace.
Definition: alignment.hh:11
auto orderedOverload(F &&... f)
Create an ordered overload set.
Definition: overloadset.hh:165
auto overload(F &&... f)
Create an overload set.
Definition: overloadset.hh:79