Skip to content

Instantly share code, notes, and snippets.

@jefftrull
Created December 3, 2014 18:45
Show Gist options
  • Save jefftrull/131626a0dc13238510c2 to your computer and use it in GitHub Desktop.
Save jefftrull/131626a0dc13238510c2 to your computer and use it in GitHub Desktop.
demo "partial" specialization of a class template with a member function template
#include <typeinfo>
#include <string>
#include <iostream>
template<typename T> struct A {
template<typename U>
void foo(U u) {
std::cout << std::string("class template parameter generic, function template parameter ") + typeid(u).name() << std::endl;
}
};
// Now a special version of foo() for class B only
struct B {};
struct C {};
template<>
template <typename T>
void A<B>::foo(T t) {
std::cout << std::string("class template parameter B, function template parameter ") + typeid(t).name() << std::endl;
}
struct X {};
struct Y {};
int main() {
A<C> ac;
A<B> ab;
X x;
Y y;
ac.foo(x);
ac.foo(y);
ab.foo(x);
ab.foo(y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment