Skip to content

Instantly share code, notes, and snippets.

@den-mentiei
Created May 3, 2013 14:08
Show Gist options
  • Save den-mentiei/5509320 to your computer and use it in GitHub Desktop.
Save den-mentiei/5509320 to your computer and use it in GitHub Desktop.
Variadic template type list enumerating.
#include <iostream>
using namespace std;
template <typename... T>
struct counter;
template <>
struct counter<> {
static constexpr size_t count() {
return 0;
}
};
template <typename Head, typename... Tail>
struct counter<Head, Tail...> {
static constexpr size_t count() {
return 1 + counter<Tail...>::count();
}
};
template <typename... T>
constexpr size_t count() {
return counter<T...>::count();
}
int main() {
cout << count<int, bool, unsigned int, char>() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment