Created
December 3, 2014 18:45
-
-
Save jefftrull/131626a0dc13238510c2 to your computer and use it in GitHub Desktop.
demo "partial" specialization of a class template with a member function template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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