Skip to content

Instantly share code, notes, and snippets.

@komiga
Created November 3, 2014 17:50
Show Gist options
  • Save komiga/d116b4c1668194485b1d to your computer and use it in GitHub Desktop.
Save komiga/d116b4c1668194485b1d to your computer and use it in GitHub Desktop.
tinch_pp match_adaptor to avoid bind() blah blah blah
#include <cassert>
#include <type_traits>
#include <memory>
#include <iostream>
template<class> struct is_smart_pointer : std::false_type {};
template<class T> struct is_smart_pointer<std::shared_ptr<T>> : std::true_type {};
template<class T> struct is_smart_pointer<std::unique_ptr<T>> : std::true_type {};
template<class T>
inline typename std::enable_if<is_smart_pointer<T>::value, bool>::type
match_adaptor(T& /*x*/) {
std::cout << "is_smart_pointer\n";
return true;
}
template<class T>
inline typename std::enable_if<!is_smart_pointer<T>::value, bool>::type
match_adaptor(T& /*x*/) {
std::cout << "!is_smart_pointer\n";
return false;
}
signed main() {
int i;
std::shared_ptr<int> sp;
assert(!match_adaptor(i));
assert(match_adaptor(sp));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment