Created
March 28, 2019 08:19
-
-
Save kim366/83f4c5c7c7d8230776e4ecf68d1b684f 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 <iostream> | |
#include <tuple> | |
template<unsigned, typename...> | |
struct ntuple_impl; | |
template<unsigned N, typename E, typename... Es> | |
struct ntuple_impl<N, std::enable_if_t<(N > 1)>, E, Es...> | |
{ | |
using type = typename ntuple_impl<N - 1, void, E, E, Es...>::type; | |
}; | |
template<typename... Es> | |
struct ntuple_impl<1, void, Es...> | |
{ | |
using type = std::tuple<Es...>; | |
}; | |
template<unsigned N, typename T> | |
using ntuple = ntuple_impl<N, void, T>; | |
template<unsigned N, typename T> | |
using ntuple_t = typename ntuple<N, T>::type; | |
int main() { | |
auto t = ntuple_t<3, int>{}; | |
static_assert(std::is_same_v<decltype(t), std::tuple<int, int, int>>); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment