Created
November 15, 2017 09:27
-
-
Save allstarschh/b459ee21c7a4df989b8c9794bbf46d0f to your computer and use it in GitHub Desktop.
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 <type_traits> | |
#include <iostream> | |
template <bool isPod = true> | |
class FooClearPolicy { | |
public: | |
static void clear() { | |
std::cout<<"pod clear"<<std::endl; | |
} | |
}; | |
template <> | |
class FooClearPolicy<false> { | |
public: | |
static void clear() { | |
std::cout<<"non-pod clear"<<std::endl; | |
} | |
}; | |
template <typename T, typename ClearPolicy = FooClearPolicy<std::is_pod<T>::value>> | |
class Foo { | |
public: | |
void clear() { | |
ClearPolicy::clear(); | |
} | |
}; | |
template<typename T> | |
class Goo { | |
typedef Foo<T> impl; | |
}; | |
class Bar { | |
public: | |
Bar() = default; | |
Bar(const Bar& rhs) {} | |
}; | |
int main () | |
{ | |
Foo<int> f; | |
Foo<Bar> g; | |
f.clear(); | |
g.clear(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment