Created
February 21, 2019 16:37
-
-
Save notfoundry/cc764f46cc6b8b6f25b00a5cabb29ddc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <utility> | |
| template <std::size_t Index, class T> | |
| struct indexed_pack_element { | |
| constexpr static T element(std::integral_constant<std::size_t, Index>); | |
| }; | |
| template <class IndexSeq, class... Ts> | |
| struct pack_indices_impl; | |
| template <std::size_t... Is, class... Ts> | |
| struct pack_indices_impl<std::integer_sequence<std::size_t, Is...>, Ts...> : indexed_pack_element<Is, Ts>... { | |
| using indexed_pack_element<Is, Ts>::element...; | |
| template <std::size_t Index> | |
| using at = decltype(element(std::integral_constant<std::size_t, Index>())); | |
| }; | |
| template <class... Ts> | |
| using pack_indices = pack_indices_impl<std::index_sequence_for<Ts...>, Ts...>; | |
| template <class IndexMap, std::size_t N, class... Accumulator> | |
| struct reverse_impl { | |
| constexpr reverse_impl< | |
| IndexMap, N, Accumulator..., | |
| typename IndexMap::template at<N - sizeof...(Accumulator)> | |
| > operator+(int); | |
| template <template <class...> class Out, class Back> | |
| using type = Out<Accumulator..., Back>; | |
| }; | |
| template <class> | |
| using iter = int; | |
| template <template <class...> class Out, class T, class... Ts> | |
| using reverse = typename decltype((reverse_impl<pack_indices<T, Ts...>, sizeof...(Ts)>() + ... + iter<Ts>()))::template type<Out, T>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment