#ifndef ANDROID_PDX_RPC_ENUMERATION_H_ #define ANDROID_PDX_RPC_ENUMERATION_H_ #include namespace android { namespace pdx { namespace rpc { // Utility for manipulating lists of types. Provides operations to lookup an // element by type or index. namespace detail { // Helper type that captures type and index for each element of a type // enumeration. template struct IndexedElement { using Type = T; static constexpr std::size_t Index = I; }; // Helper type that captures an IndexSequence and corresponding list of types. template struct ElementIndexer; // Partial specialization that generates an instantiation of IndexElement // for each element of a type enumeration using inheritance. Once a type // enumeration is instantiated this way the compiler is able to deduce either I // or T from the other using the method below. template struct ElementIndexer, Ts...> : IndexedElement... { }; // Helper function that causes the compiler to deduce an IndexedElement // given T. template static IndexedElement SelectElementByType(IndexedElement); // Helper function that causes the compiler to deduce an IndexedElement // given I. template static IndexedElement SelectElementByIndex(IndexedElement); } // namespace detail // Deduces the IndexedElement given T and a type sequence Ts. This may be // used to determine the index of T within Ts at compile time. template using ElementForType = decltype(detail::SelectElementByType( detail::ElementIndexer::type, Ts...>{})); // Deduces the IndexedElement given I and a type sequence Ts. This may be // used to determine the type of the element at index I within Ts at compile // time. Tuple operations may also be used to accomplish the same task, however // this implementation is provided here for symmetry. template using ElementForIndex = decltype(detail::SelectElementByIndex( detail::ElementIndexer::type, Ts...>{})); } // namespace rpc } // namespace pdx } // namespace android #endif // ANDROID_PDX_RPC_ENUMERATION_H_