Skip to content

Instantly share code, notes, and snippets.

@sdeming
Created May 25, 2012 15:00
Show Gist options
  • Save sdeming/2788614 to your computer and use it in GitHub Desktop.
Save sdeming/2788614 to your computer and use it in GitHub Desktop.
using partial template specialization for pattern matching in c++, simple demo
#include <iostream>
template <int N>
void pr(const std::string &msg)
{
std::cout << msg << std::endl;
pr<N-1>(msg); // would be nice to do tail call optimization here...
}
template <>
void pr<0>(const std::string &msg)
{
}
int main(int argc, char *argv[])
{
pr<100>("Hello World");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment