Created
June 20, 2013 11:12
-
-
Save KrzaQ/5821926 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
| #include <iomanip> | |
| #include <type_traits> | |
| #include <sstream> | |
| #include <boost/tti/has_member_function.hpp> | |
| struct int_size{ | |
| int size() const { return 42; }; | |
| }; | |
| struct derived_int_size : int_size{}; | |
| struct size_t_size{ | |
| std::size_t size() const { return 42; } | |
| }; | |
| struct derived_size_t_size : size_t_size{}; | |
| struct void_size{ | |
| void size() {} | |
| }; | |
| struct no_size{}; | |
| struct template_int_size{ | |
| template<typename=int> | |
| int size() const { return 42; } | |
| }; | |
| struct overloaded_size{ | |
| size_t size() const { return 42; } | |
| int size() { return 41; } | |
| }; | |
| BOOST_TTI_HAS_MEMBER_FUNCTION(size) | |
| int main() | |
| { | |
| using namespace std; | |
| //#define dbg(x) { stringstream s; s << boolalpha << left << setw(8) << has_size_method2<x>::value << #x; cout << s.str() << endl; } | |
| #define dbg(x) { stringstream s; s << boolalpha << left << setw(8) <<\ | |
| (has_member_function_size<x,size_t,boost::mpl::vector<>, boost::function_types::const_qualified>::value ||\ | |
| has_member_function_size<x,int,boost::mpl::vector<>, boost::function_types::const_qualified>::value)\ | |
| << #x; cout << s.str() << endl; } | |
| dbg(int_size); | |
| dbg(derived_int_size); | |
| dbg(size_t_size); | |
| dbg(derived_size_t_size); | |
| dbg(void_size); | |
| dbg(no_size); | |
| dbg(template_int_size); | |
| dbg(overloaded_size); | |
| } |
This file contains hidden or 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
| true int_size | |
| false derived_int_size | |
| true size_t_size | |
| false derived_size_t_size | |
| false void_size | |
| false no_size | |
| true template_int_size | |
| true overloaded_size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment