Created
November 3, 2014 17:50
-
-
Save komiga/d116b4c1668194485b1d to your computer and use it in GitHub Desktop.
tinch_pp match_adaptor to avoid bind() blah blah blah
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 <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