From 3d7125d3dbea4850b9bcff411df5aff20986ce52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 2 Jan 2015 18:41:53 +0100 Subject: [PATCH] Refactored test to directly use the new header without preprocessor dependencies. --- test/has_member_function_callable_with.cpp | 558 ++++++--------------- 1 file changed, 166 insertions(+), 392 deletions(-) diff --git a/test/has_member_function_callable_with.cpp b/test/has_member_function_callable_with.cpp index 9049c44..41242a8 100644 --- a/test/has_member_function_callable_with.cpp +++ b/test/has_member_function_callable_with.cpp @@ -1,370 +1,75 @@ ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2011-2014. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/intrusive for documentation. // ////////////////////////////////////////////////////////////////////////////// - -//Just for BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED +//User define +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME func0to3 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 0 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 3 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace func0to3ns { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END } #include -#include -#include -namespace boost{ -namespace intrusive{ -namespace intrusive_detail{ -namespace has_member_function_callable_with { - -struct dont_care -{ - dont_care(...); -}; - -template -struct make_dontcare -{ - typedef has_member_function_callable_with::dont_care type; -}; - -struct private_type -{ - static private_type p; - private_type const &operator,(int) const; -}; - -typedef char yes_type; -struct no_type{ char dummy[2]; }; - -template -no_type is_private_type(T const &); -yes_type is_private_type(private_type const &); - -}}}} - - -namespace boost{ -namespace intrusive{ -namespace intrusive_detail{ - -template -class has_member_function_named_func -{ - struct BaseMixin - { - void func(); - }; - - struct Base : public ::boost::intrusive::detail::remove_cv::type, public BaseMixin {}; - template class Helper{}; - - template - static has_member_function_callable_with::no_type deduce - (U*, Helper* = 0); - static has_member_function_callable_with::yes_type deduce(...); - - public: - static const bool value = - sizeof(has_member_function_callable_with::yes_type) == sizeof(deduce((Base*)(0))); -}; - -}}} - -#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - template - struct has_member_function_callable_with_func_impl; - - - template - struct has_member_function_callable_with_func_impl - - { - static const bool value = false; - }; - - - }}} - - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - #if !defined(_MSC_VER) || (_MSC_VER < 1600) - - #if !defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - template().func(), 0)> - struct zeroarg_checker_func - { - has_member_function_callable_with::yes_type dummy; - zeroarg_checker_func(int); - }; - - //For buggy compilers like MSVC 7.1, ((F*)0)->func() does not - //fail but sizeof yields to 0. - template - struct zeroarg_checker_func - { - has_member_function_callable_with::no_type dummy; - zeroarg_checker_func(int); - }; - - template - struct has_member_function_callable_with_func_impl - - { - template - static zeroarg_checker_func Test(zeroarg_checker_func*); - - template - static has_member_function_callable_with::no_type Test(...); - - static const bool value - = sizeof(Test< Fun >(0)) == sizeof(has_member_function_callable_with::yes_type); - }; - - #else - - template - struct has_member_function_callable_with_func_impl - - { - //GCC [3.4-4.3) gives ICE when instantiating the 0 arg version so it is not supported. - static const bool value = true; - }; - - #endif - - #else - - template - struct has_member_function_callable_with_func_impl - - { - template - static decltype(boost::move_detail::declval().func(), has_member_function_callable_with::yes_type()) Test(U* f); - - template - static has_member_function_callable_with::no_type Test(...); - static const bool value = sizeof(Test((Fun*)0)) == sizeof(has_member_function_callable_with::yes_type); - }; - - #endif - - }}} - - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - template - struct has_member_function_callable_with_func_impl - - { - - struct FunWrap : Fun - { - using Fun::func; - has_member_function_callable_with::private_type - func( has_member_function_callable_with::dont_care) const; - }; - - static bool const value = (sizeof(has_member_function_callable_with::no_type) == - sizeof(has_member_function_callable_with::is_private_type - ( (::boost::move_detail::declval< FunWrap >().func( ::boost::move_detail::declval() ), 0) ) - ) - ); - }; - - }}} - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - template - struct has_member_function_callable_with_func_impl - - { - struct FunWrap: Fun - { - using Fun::func; - has_member_function_callable_with::private_type - func( has_member_function_callable_with::dont_care , has_member_function_callable_with::dont_care) const; - }; - - static bool const value = (sizeof(has_member_function_callable_with::no_type) == - sizeof(has_member_function_callable_with::is_private_type - ( (::boost::move_detail::declval< FunWrap >(). - func( ::boost::move_detail::declval() - , ::boost::move_detail::declval() ) - , 0) ) - ) - ); - }; - }}} - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - template - struct has_member_function_callable_with_func_impl - - { - struct FunWrap: Fun - { - using Fun::func; - has_member_function_callable_with::private_type - func( has_member_function_callable_with::dont_care - , has_member_function_callable_with::dont_care - , has_member_function_callable_with::dont_care) const; - }; - - static bool const value = (sizeof(has_member_function_callable_with::no_type) == - sizeof(has_member_function_callable_with::is_private_type - ( (::boost::move_detail::declval< FunWrap >(). - func( ::boost::move_detail::declval() - , ::boost::move_detail::declval() - , ::boost::move_detail::declval() ) - , 0) ) - ) - ); - }; - - template - struct has_member_function_callable_with_func - : public has_member_function_callable_with_func_impl - ::value, P0 , P1 , P2 > - {}; - - }}} - -#else //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - template - struct has_member_function_callable_with_func_impl; - - template - struct has_member_function_callable_with_func_impl - - { - static const bool value = false; - }; - - - }}} - - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - #ifdef BOOST_NO_CXX11_DECLTYPE - template().func(), 0)> - struct zeroarg_checker_func - { - has_member_function_callable_with::yes_type dummy; - zeroarg_checker_func(int); - }; - - //For buggy compilers like MSVC 7.1, ((F*)0)->func() does not - //fail but sizeof yields to 0. - template - struct zeroarg_checker_func - { - has_member_function_callable_with::no_type dummy; - zeroarg_checker_func(int); - }; - - #endif //BOOST_NO_CXX11_DECLTYPE - - template - struct has_member_function_callable_with_func_impl - - { - #ifndef BOOST_NO_CXX11_DECLTYPE - template().func()) > - static boost_intrusive_has_member_function_callable_with::yes_type Test(U*); - #else - template - static zeroarg_checker_func Test(zeroarg_checker_func*); - #endif - - template - static has_member_function_callable_with::no_type Test(...); - - static const bool value = sizeof(Test< Fun >(0)) - == sizeof(has_member_function_callable_with::yes_type); - }; - - }}} - - - namespace boost{ - namespace intrusive{ - namespace intrusive_detail{ - - template - struct has_member_function_callable_with_func_impl - - { - template - struct FunWrapTmpl : Fun - { - using Fun::func; - has_member_function_callable_with::private_type - func(DontCares...) const; - }; - - typedef FunWrapTmpl::type...> FunWrap; - - static bool const value = (sizeof(has_member_function_callable_with::no_type) == - sizeof(has_member_function_callable_with::is_private_type - ( (::boost::move_detail::declval< FunWrap >().func( ::boost::move_detail::declval()... ), 0) ) - ) - ); - }; - - template - struct has_member_function_callable_with_func - : public has_member_function_callable_with_func_impl - ::value, Args... > - {}; - - }}} - -#endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME func1to2 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 1 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 2 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace func1to2ns { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END } +#include + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME func3to3 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 3 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 3 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace func3to3ns { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END } +#include + +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME func0to0 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 0 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0 +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace func0to0ns { +#define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END } +#include + +/////////////////// +/////////////////// +// TEST CODE +/////////////////// +/////////////////// struct functor { - void func(); - void func(const int&); - void func(const int&, const int&); - void func(const int&, const int&, const int&); + //func0to3 + void func0to3(); + void func0to3(const int&); + void func0to3(const int&, const int&); + void func0to3(const int&, const int&, const int&); + //func1to2 + void func1to2(const int&); + void func1to2(const int&, const int&); + //func3to3 + void func3to3(const int&, const int&, const int&); + //func0to0 + void func0to0(); }; struct functor2 { - void func(char*); - void func(int, char*); - void func(int, char*, double); - void func(const int&, char*, void *); + void func0to3(char*); + void func0to3(int, char*); + void func0to3(int, char*, double); + void func0to3(const int&, char*, void *); + //func1to2 + void func1to2(char*); + void func1to2(int, char*); + void func1to2(int, char*, double); + //func3to3 + void func3to3(const int&, char*, void *); }; struct functor3 @@ -374,43 +79,55 @@ struct functor3 struct functor4 { - void func(...); - template - void func(int, const T &); - - template - void func(const T &); - - template - void func(int, const T &, const U &); + //func0to3 + void func0to3(...); + template void func0to3(int, const T &); + template void func0to3(const T &); + template void func0to3(int, const T &, const U &); + //func1to2 + template void func1to2(int, const T &); + template void func1to2(const T &); + template void func1to2(int, const T &, const U &); + //func3to3 + void func3to3(...); + template void func3to3(int, const T &, const U &); }; int main() { - using namespace boost::intrusive::intrusive_detail; - #if !defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - { - int check1[ has_member_function_callable_with_func::value ? 1 : -1]; - int check2[!has_member_function_callable_with_func::value ? 1 : -1]; - int check3[!has_member_function_callable_with_func::value ? 1 : -1]; - int check4[ has_member_function_callable_with_func::value ? 1 : -1]; + { //func0to3 0 arg + using func0to3ns::has_member_function_callable_with_func0to3; + int check1[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func0to3::value ? 1 : -1]; (void)check1; (void)check2; (void)check3; (void)check4; } + { //func0to0 0 arg + using func0to0ns::has_member_function_callable_with_func0to0; + int check1[ has_member_function_callable_with_func0to0::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func0to0::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func0to0::value ? 1 : -1]; + (void)check1; + (void)check2; + (void)check3; + } #endif - { - int check1[ has_member_function_callable_with_func::value ? 1 : -1]; - int check2[!has_member_function_callable_with_func::value ? 1 : -1]; - int check3[!has_member_function_callable_with_func::value ? 1 : -1]; - int check4[ has_member_function_callable_with_func::value ? 1 : -1]; - int check5[!has_member_function_callable_with_func::value ? 1 : -1]; - int check6[!has_member_function_callable_with_func::value ? 1 : -1]; - int check7[ has_member_function_callable_with_func::value ? 1 : -1]; - int check8[ has_member_function_callable_with_func::value ? 1 : -1]; + { //func0to3 1arg + using func0to3ns::has_member_function_callable_with_func0to3; + int check1[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check5[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check6[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check7[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check8[ has_member_function_callable_with_func0to3::value ? 1 : -1]; (void)check1; (void)check2; (void)check3; @@ -421,14 +138,35 @@ int main() (void)check8; } - { - int check1[ has_member_function_callable_with_func::value ? 1 : -1]; - int check2[!has_member_function_callable_with_func::value ? 1 : -1]; - int check3[!has_member_function_callable_with_func::value ? 1 : -1]; - int check4[ has_member_function_callable_with_func::value ? 1 : -1]; - int check5[!has_member_function_callable_with_func::value ? 1 : -1]; - int check6[!has_member_function_callable_with_func::value ? 1 : -1]; - int check7[ has_member_function_callable_with_func::value ? 1 : -1]; + { //func1to2 1arg + using func1to2ns::has_member_function_callable_with_func1to2; + int check1[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check5[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check6[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check7[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check8[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + (void)check1; + (void)check2; + (void)check3; + (void)check4; + (void)check5; + (void)check6; + (void)check7; + (void)check8; + } + + { //func0to3 2arg + using func0to3ns::has_member_function_callable_with_func0to3; + int check1[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check5[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check6[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check7[ has_member_function_callable_with_func0to3::value ? 1 : -1]; (void)check1; (void)check2; (void)check3; @@ -438,14 +176,51 @@ int main() (void)check7; } - { - int check1[ has_member_function_callable_with_func::value ? 1 : -1]; - int check2[!has_member_function_callable_with_func::value ? 1 : -1]; - int check3[!has_member_function_callable_with_func::value ? 1 : -1]; - int check4[ has_member_function_callable_with_func::value ? 1 : -1]; - int check5[!has_member_function_callable_with_func::value ? 1 : -1]; - int check6[!has_member_function_callable_with_func::value ? 1 : -1]; - int check7[ has_member_function_callable_with_func::value ? 1 : -1]; + { //func1to2 2arg + using func1to2ns::has_member_function_callable_with_func1to2; + int check1[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check5[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check6[!has_member_function_callable_with_func1to2::value ? 1 : -1]; + int check7[ has_member_function_callable_with_func1to2::value ? 1 : -1]; + (void)check1; + (void)check2; + (void)check3; + (void)check4; + (void)check5; + (void)check6; + (void)check7; + } + + { //func0to3 3arg + using func0to3ns::has_member_function_callable_with_func0to3; + int check1[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check5[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check6[!has_member_function_callable_with_func0to3::value ? 1 : -1]; + int check7[ has_member_function_callable_with_func0to3::value ? 1 : -1]; + (void)check1; + (void)check2; + (void)check3; + (void)check4; + (void)check5; + (void)check6; + (void)check7; + } + + { //func3to3 3arg + using func3to3ns::has_member_function_callable_with_func3to3; + int check1[ has_member_function_callable_with_func3to3::value ? 1 : -1]; + int check2[!has_member_function_callable_with_func3to3::value ? 1 : -1]; + int check3[!has_member_function_callable_with_func3to3::value ? 1 : -1]; + int check4[ has_member_function_callable_with_func3to3::value ? 1 : -1]; + int check5[!has_member_function_callable_with_func3to3::value ? 1 : -1]; + int check6[!has_member_function_callable_with_func3to3::value ? 1 : -1]; + int check7[ has_member_function_callable_with_func3to3::value ? 1 : -1]; (void)check1; (void)check2; (void)check3; @@ -456,5 +231,4 @@ int main() } return 0; - }