3#ifndef DUNE_COMMON_OVERLOADSET_HH
4#define DUNE_COMMON_OVERLOADSET_HH
9#include <dune/common/std/type_traits.hh>
17#if __cpp_variadic_using >= 201611
19 template<
typename... F>
26 template<
typename... FF>
27 OverloadSet(FF&&... ff)
28 : F(
std::forward<FF>(ff))...
31 using F::operator()...;
41 template<
class F0,
class... F>
42 class OverloadSet:
public OverloadSet<F...>, F0
44 using Base = OverloadSet<F...>;
47 template<
class FF0,
class... FF>
48 OverloadSet(FF0&& f0, FF&&... ff) :
49 Base(
std::forward<FF>(ff)...),
50 F0(
std::forward<FF0>(f0))
55 using Base::operator();
59 class OverloadSet<F0>:
public F0
64 OverloadSet(FF0&& f0) :
65 F0(
std::forward<FF0>(f0))
105 return Impl::OverloadSet<std::decay_t<F>...>(std::forward<F>(f)...);
112 template<
class F0,
class... F>
113 class OrderedOverloadSet:
public OrderedOverloadSet<F...>, F0
115 using Base = OrderedOverloadSet<F...>;
118 template<
class FF0,
class... FF>
119 OrderedOverloadSet(FF0&& f0, FF&&... ff) :
120 Base(
std::forward<FF>(ff)...),
121 F0(
std::forward<FF0>(f0))
125 template<
class... Args,
126 std::enable_if_t<Std::is_callable<F0(Args&&...)>::value,
int> = 0>
127 decltype(
auto)
operator()(Args&&... args)
129 return F0::operator()(std::forward<Args>(args)...);
135 template<
class... Args,
136 std::enable_if_t< not Std::is_callable<F0(Args&&...)>::value,
int> = 0>
137 decltype(
auto)
operator()(Args&&... args)
139 return Base::operator()(std::forward<Args>(args)...);
145 class OrderedOverloadSet<F0>:
public F0
150 OrderedOverloadSet(FF0&& f0) :
151 F0(
std::forward<FF0>(f0))
156 template<
class... Args>
157 decltype(
auto)
operator()(Args&&... args)
159 static_assert(Std::is_callable<F0(Args&&...)>::value,
"No matching overload found in OrderedOverloadSet");
160 return F0::operator()(std::forward<Args>(args)...);
193 return Impl::OrderedOverloadSet<std::decay_t<F>...>(std::forward<F>(f)...);
auto orderedOverload(F &&... f)
Create an ordered overload set.
Definition: overloadset.hh:191
auto overload(F &&... f)
Create an overload set.
Definition: overloadset.hh:103
Dune namespace.
Definition: alignedallocator.hh:10