Created
January 27, 2017 17:28
-
-
Save fowlmouth/8b5f5fb177ade7005b1a4395f42fe383 to your computer and use it in GitHub Desktop.
This file contains 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
#pragma once | |
namespace fowl{ | |
namespace templates{ | |
// index<idx, TS...> returns the type at index idx | |
template<std::size_t idx, typename... txs> | |
struct index; | |
template<std::size_t idx, typename tx, typename... txs> | |
struct index<idx, tx, txs...> | |
{ | |
using type = typename index<idx-1, txs...>::type; | |
}; | |
template<typename tx, typename... txs> | |
struct index<0, tx, txs...> | |
{ | |
using type = tx; | |
}; | |
template< | |
template<typename...>typename tpl, | |
typename... ts > | |
using apply = tpl< ts... >; | |
template< | |
template<typename...> typename tpl, | |
template<typename...> typename out, | |
typename... ts > | |
using map = out< apply< tpl, ts >... >; | |
template< typename... Ts> | |
struct pack | |
{ | |
template< typename... Ys> | |
using append = pack<Ts..., Ys...>; | |
template< typename... Ys> | |
using prepend = pack<Ys..., Ts...>; | |
template< template<typename...> typename tpl> | |
using apply = fowl::templates::apply< tpl, Ts... >; | |
template< template<typename...> typename tpl> | |
using map = typename fowl::templates:: map< tpl, fowl::templates::pack, Ts...>; | |
template< std::size_t idx> | |
using at = typename fowl::templates:: index< idx, Ts...>::type; | |
static constexpr auto size = sizeof...(Ts); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment