Skip to content

Instantly share code, notes, and snippets.

@allstarschh
Created November 15, 2017 09:27
Show Gist options
  • Save allstarschh/b459ee21c7a4df989b8c9794bbf46d0f to your computer and use it in GitHub Desktop.
Save allstarschh/b459ee21c7a4df989b8c9794bbf46d0f to your computer and use it in GitHub Desktop.
#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