Created
December 4, 2014 10:30
-
-
Save jefftrull/561b4e51d03bb3df3f86 to your computer and use it in GitHub Desktop.
attempt to partially specialize class by defining a member function template to be different for a certain *class* template parameters
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> | |
A(U u) { | |
std::cout << std::string("class template parameter generic, ctor template parameter ") + typeid(u).name() << std::endl; | |
} | |
}; | |
struct B {}; | |
// Now a special version of the constructor for class pointer arguments only | |
template<typename T> | |
template <typename U> | |
A<T*>::A(U u) { | |
std::cout << std::string("class template parameter pointer, function template parameter ") + typeid(u).name() << std::endl; | |
} | |
struct X {}; | |
struct Y {}; | |
int main() { | |
X x; | |
Y y; | |
// these should call the default ctor | |
A<B> abx(x); | |
A<B> aby(y); | |
// these should call the (class) specialized version | |
A<B*> abpx(x); | |
A<B*> abpy(y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment