13 #ifndef OGLPLUS_ONE_OF_1107121519_HPP 
   14 #define OGLPLUS_ONE_OF_1107121519_HPP 
   16 #include <oglplus/config/compiler.hpp> 
   18 #include <type_traits> 
   24 template <
typename Common, 
typename T>
 
   28         !std::is_same<T, void>::value,
 
   29         "The passed value has not one of the allowed types!" 
   32     static inline Common Accept(
T value)
 
   41 #if OGLPLUS_DOCUMENTATION_ONLY 
   59 template <
typename Common, 
typename Variants>
 
   64     operator Common(
void) 
const;
 
   67 template <
typename Common, 
typename TypeList>
 
   72 template <
typename Common, 
typename V1, 
typename V2>
 
   73 class OneOf<Common, std::tuple<V1, V2>>
 
   79      : _value(Common(value))
 
   83      : _value(Common(value))
 
   89         typename std::enable_if<
 
   90             std::is_convertible<T, V1>::value
 
   92     ): _value(Common(V1(value)))
 
   98         typename std::enable_if<
 
   99             std::is_convertible<T, V2>::value
 
  101     ): _value(Common(V2(value)))
 
  104     OGLPLUS_EXPLICIT 
operator Common (
void) const
 
  105     OGLPLUS_NOEXCEPT(true)
 
  112 template <
typename Common, 
typename V1, 
typename V2, 
typename V3>
 
  113 class OneOf<Common, std::tuple<V1, V2, V3>>
 
  119      : _value(Common(value))
 
  123      : _value(Common(value))
 
  127      : _value(Common(value))
 
  130     template <
typename T>
 
  133         typename std::enable_if<
 
  134             std::is_convertible<T, V1>::value
 
  136     ): _value(Common(V1(value)))
 
  139     template <
typename T>
 
  142         typename std::enable_if<
 
  143             std::is_convertible<T, V2>::value
 
  145     ): _value(Common(V2(value)))
 
  148     template <
typename T>
 
  151         typename std::enable_if<
 
  152             std::is_convertible<T, V3>::value
 
  154     ): _value(Common(V3(value)))
 
  157     OGLPLUS_EXPLICIT 
operator Common (
void) const
 
  158     OGLPLUS_NOEXCEPT(true)
 
  164 #if !OGLPLUS_NO_VARIADIC_TEMPLATES 
  165 template <
typename Common, 
typename ... Variants>
 
  166 class OneOf<Common, std::tuple<Variants...>>
 
  167  : 
public aux::OneOfBase<Common, Variants>...
 
  172     template <
typename T>
 
  174      : std::is_convertible<
 
  176         aux::OneOfBase<Common, T>
 
  180     template <
typename T, 
typename V, 
typename ... Vi>
 
  181     static V _do_find_one_of(std::true_type);
 
  183     template <
typename T, 
typename V>
 
  184     static void _do_find_one_of(std::false_type);
 
  186     template <
typename T, 
typename V, 
typename ... Vi>
 
  187     static auto _find_one_of(
void) ->
 
  188     decltype(_do_find_one_of<T, V, Vi...>(std::is_convertible<T, V>()));
 
  190     template <
typename T, 
typename V, 
typename V1, 
typename ... Vi>
 
  191     static auto _do_find_one_of(std::false_type) ->
 
  192     decltype(_find_one_of<T, V1, Vi...>());
 
  194     template <
typename T>
 
  197         typedef decltype(_find_one_of<T, Variants...>()) type;
 
  200     template <typename 
T>
 
  203         typename std::enable_if<is_one_of<
T>::value>::type* = 
nullptr 
  204     ): _value(aux::OneOfBase<Common, 
T>::Accept(value))
 
  207     template <
typename T>
 
  210         typename std::enable_if<!is_one_of<T>::value>::type* = 
nullptr 
  211     ): _value(aux::OneOfBase<Common, typename find<
T>::type>::Accept(value))
 
  214     OGLPLUS_EXPLICIT 
operator Common (
void) const
 
  215     OGLPLUS_NOEXCEPT(true)
 
  220 #endif // !OGLPLUS_NO_VARIADIC_TEMPLATES 
  224 #endif // include guard 
Stores a value having one of the listed types in a common representation. 
Definition: one_of.hpp:60