Skip to content

Instantly share code, notes, and snippets.

@thefloweringash
Created June 25, 2012 07:13
Show Gist options
  • Save thefloweringash/2987134 to your computer and use it in GitHub Desktop.
Save thefloweringash/2987134 to your computer and use it in GitHub Desktop.
C++11 Variadic Template Pattern Matching
#include <iostream>
using namespace std;
template <typename... T>
struct pp {};
template <typename T, typename TI,
typename U, typename UI>
struct matcher;
template <typename T, typename... TI,
typename U, typename... UI>
struct matcher<T, pp<TI...>,
U, pp<UI...>> {
matcher(TI... ti, UI... ui) {
cout << "TI size = " << sizeof...(ti) << endl
<< "UI size = " << sizeof...(ui) << endl;
}
};
using matcher_test = matcher<int, pp<int>,
int, pp<int>>;
int main() {
matcher_test(0, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment