make TypeListIndexer constexpr (#733)

This commit is contained in:
Ian Taylor 2019-06-06 17:16:08 -04:00 committed by Anna Gringauze
parent b74b286d5e
commit 66809c6852

View File

@ -518,31 +518,31 @@ namespace details
struct TypeListIndexer struct TypeListIndexer
{ {
const TypeChain& obj_; const TypeChain& obj_;
TypeListIndexer(const TypeChain& obj) : obj_(obj) {} constexpr TypeListIndexer(const TypeChain& obj) : obj_(obj) {}
template <std::size_t N> template <std::size_t N>
const TypeChain& getObj(std::true_type) constexpr const TypeChain& getObj(std::true_type)
{ {
return obj_; return obj_;
} }
template <std::size_t N, typename MyChain = TypeChain, template <std::size_t N, typename MyChain = TypeChain,
typename MyBase = typename MyChain::Base> typename MyBase = typename MyChain::Base>
auto getObj(std::false_type) constexpr auto getObj(std::false_type)
-> decltype(TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>()) -> decltype(TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>())
{ {
return TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>(); return TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>();
} }
template <std::size_t N> template <std::size_t N>
auto get() -> decltype(getObj<N - 1>(std::integral_constant<bool, N == 0>())) constexpr auto get() -> decltype(getObj<N - 1>(std::integral_constant<bool, N == 0>()))
{ {
return getObj<N - 1>(std::integral_constant<bool, N == 0>()); return getObj<N - 1>(std::integral_constant<bool, N == 0>());
} }
}; };
template <typename TypeChain> template <typename TypeChain>
TypeListIndexer<TypeChain> createTypeListIndexer(const TypeChain& obj) constexpr TypeListIndexer<TypeChain> createTypeListIndexer(const TypeChain& obj)
{ {
return TypeListIndexer<TypeChain>(obj); return TypeListIndexer<TypeChain>(obj);
} }