Skip to content

Instantly share code, notes, and snippets.

@Zikoel
Created July 17, 2018 09:21
Show Gist options
  • Save Zikoel/208dd2270a5cc4ef1acb31d1e229d33a to your computer and use it in GitHub Desktop.
Save Zikoel/208dd2270a5cc4ef1acb31d1e229d33a to your computer and use it in GitHub Desktop.
Iterating over a parameter pack
#include <assert.h>
#include <type_traits>
template<typename T, typename... Others>
struct splitter{
using Head = T;
template <template <typename...> typename U> using Tail = U<Others...>;
};
int main() {
static_assert( true == std::is_same<int, splitter<int, double, int>::Head>::value );
using MyType = splitter<int,double,int>;
using one = MyType::Head;
using two = MyType::Tail<splitter>::Head;
using three = MyType::Tail<splitter>::Tail<splitter>::Head;
//using four = MyType::Tail<splitter>::Tail<splitter>::Tail<splitter>::Head;
static_assert( true == std::is_same<int, one>::value );
static_assert( true == std::is_same<double, two>::value );
static_assert( true == std::is_same<int, three>::value );
static_assert( true == std::is_same<double, splitter<int,double,int>::Tail<splitter>::Head>::value );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment