File indexing completed on 2025-09-15 08:55:03
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <type_traits>
0010 #include <utility>
0011 #include <variant>
0012
0013 namespace celeritas
0014 {
0015 namespace detail
0016 {
0017
0018
0019
0020
0021 template<class T, class F>
0022 struct ReturnAsImpl
0023 {
0024 F apply;
0025
0026 template<class U>
0027 T operator()(U&& other)
0028 {
0029 return this->apply(std::forward<U>(other));
0030 }
0031 };
0032
0033
0034
0035
0036
0037 template<class E, template<E> class ETraits>
0038 struct EnumVariantImpl
0039 {
0040
0041 using EInt = std::underlying_type_t<E>;
0042
0043 static_assert(static_cast<EInt>(E::size_) > 0, "ill-defined enumeration");
0044
0045
0046 using EIntRange
0047 = std::make_integer_sequence<EInt, static_cast<EInt>(E::size_)>;
0048
0049
0050 template<EInt I>
0051 struct EIntTraits
0052 {
0053 using type = typename ETraits<static_cast<E>(I)>::type;
0054 };
0055
0056
0057
0058 template<class Seq>
0059 struct VariantImpl;
0060 template<EInt... Is>
0061 struct VariantImpl<std::integer_sequence<EInt, Is...>>
0062 {
0063 using type = std::variant<typename EIntTraits<Is>::type...>;
0064 };
0065
0066
0067
0068 using type = typename VariantImpl<EIntRange>::type;
0069 };
0070
0071
0072 }
0073 }