mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-31 20:04:29 +02:00
refactored takes_arg_as_const_reference.hpp again, fixed tests
This commit is contained in:
@@ -18,75 +18,37 @@ namespace unordered{
|
|||||||
namespace detail{
|
namespace detail{
|
||||||
namespace foa{
|
namespace foa{
|
||||||
|
|
||||||
static constexpr bool noexcept_is_part_of_signature=
|
template<typename Arg,typename R,typename... Args>
|
||||||
!std::is_same<void(*)(),void(*)()noexcept>::value;
|
void check_function_1st_arg(R(*)(Arg,Args...));
|
||||||
|
|
||||||
template<typename Arg,typename Sig>
|
|
||||||
static std::false_type has_1st_arg(Sig);
|
|
||||||
|
|
||||||
template<typename Arg,typename R,typename... Args>
|
template<typename Arg,typename R,typename... Args>
|
||||||
static std::true_type has_1st_arg(R(*)(Arg,Args...));
|
void check_function_1st_arg(R(*)(Arg,Args...,...));
|
||||||
|
|
||||||
template<
|
#define BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(qualifier) \
|
||||||
typename Arg,typename R,typename... Args,
|
|
||||||
bool dependent_value=false,
|
|
||||||
typename std::enable_if<
|
|
||||||
noexcept_is_part_of_signature||dependent_value>::type* =nullptr
|
|
||||||
>
|
|
||||||
static std::true_type has_1st_arg(R(*)(Arg,Args...)noexcept);
|
|
||||||
|
|
||||||
template<typename Arg,typename R,typename... Args>
|
|
||||||
static std::true_type has_1st_arg(R(*)(Arg,Args...,...));
|
|
||||||
|
|
||||||
template<
|
|
||||||
typename Arg,typename R,typename... Args,
|
|
||||||
bool dependent_value=false,
|
|
||||||
typename std::enable_if<
|
|
||||||
noexcept_is_part_of_signature||dependent_value>::type* =nullptr
|
|
||||||
>
|
|
||||||
std::true_type has_1st_arg(R(*)(Arg,Args...,...)noexcept);
|
|
||||||
|
|
||||||
#define BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(qualifier) \
|
|
||||||
template<typename Arg,typename R,typename C,typename... Args> \
|
template<typename Arg,typename R,typename C,typename... Args> \
|
||||||
static std::true_type has_1st_arg(R(C::*)(Arg,Args...)qualifier); \
|
void check_memfun_1st_arg(R(C::*)(Arg,Args...)qualifier); \
|
||||||
\
|
|
||||||
template< \
|
|
||||||
typename Arg,typename R,typename C,typename... Args, \
|
|
||||||
bool dependent_value=false, \
|
|
||||||
typename std::enable_if< \
|
|
||||||
noexcept_is_part_of_signature||dependent_value>::type* =nullptr \
|
|
||||||
> \
|
|
||||||
static std::true_type has_1st_arg(R(C::*)(Arg,Args...)qualifier noexcept); \
|
|
||||||
\
|
\
|
||||||
template<typename Arg,typename R,typename C,typename... Args> \
|
template<typename Arg,typename R,typename C,typename... Args> \
|
||||||
static std::true_type has_1st_arg(R(C::*)(Arg,Args...,...)qualifier); \
|
void check_memfun_1st_arg(R(C::*)(Arg,Args...,...)qualifier);
|
||||||
\
|
|
||||||
template< \
|
|
||||||
typename Arg,typename R,typename C,typename... Args, \
|
|
||||||
bool dependent_value=false, \
|
|
||||||
typename std::enable_if< \
|
|
||||||
noexcept_is_part_of_signature||dependent_value>::type* =nullptr \
|
|
||||||
> \
|
|
||||||
static std::true_type has_1st_arg(R(C::*)(Arg,Args...,...)qualifier noexcept);
|
|
||||||
|
|
||||||
/* VS warns when a pp function is directly called with an empty arg */
|
/* VS warns when a pp function is directly called with an empty arg */
|
||||||
#define BOOST_UNORDERED_EMPTY_PP_ARG()
|
#define BOOST_UNORDERED_EMPTY_PP_ARG()
|
||||||
|
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(BOOST_UNORDERED_EMPTY_PP_ARG())
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(BOOST_UNORDERED_EMPTY_PP_ARG())
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(const)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(volatile)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(volatile)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const volatile)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(const volatile)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(const&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(volatile&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(volatile&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const volatile&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(const volatile&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(&&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(&&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const&&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(const&&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(volatile&&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(volatile&&)
|
||||||
BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const volatile&&)
|
BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG(const volatile&&)
|
||||||
|
|
||||||
#undef BOOST_UNORDERED_EMPTY_PP_ARG
|
#undef BOOST_UNORDERED_EMPTY_PP_ARG
|
||||||
#undef BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN
|
#undef BOOST_UNORDERED_CHECK_MEMFUN_1ST_ARG
|
||||||
|
|
||||||
/* Detects if f(x) takes x as a const reference. From an implementation
|
/* Detects if f(x) takes x as a const reference. From an implementation
|
||||||
* technique by Kenneth Gorking.
|
* technique by Kenneth Gorking.
|
||||||
@@ -94,29 +56,41 @@ BOOST_UNORDERED_HAS_CONST_REFERENCE_ARG_MEMFUN(const volatile&&)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename F,typename Arg,typename=void>
|
template<typename F,typename Arg,typename=void>
|
||||||
struct takes_arg_as_const_reference0:
|
struct takes_arg_as_const_reference0:std::false_type{};
|
||||||
decltype(has_1st_arg<const Arg&>(std::declval<F>())){};
|
|
||||||
|
|
||||||
template<typename F,typename Arg>
|
template<typename F,typename Arg>
|
||||||
struct takes_arg_as_const_reference0<
|
struct takes_arg_as_const_reference0<
|
||||||
F,Arg,
|
F,Arg,
|
||||||
boost::void_t<
|
boost::void_t<
|
||||||
decltype(has_1st_arg<const Arg&>(&F::template operator()<Arg>))
|
decltype(check_function_1st_arg<const Arg&>(std::declval<F>()))
|
||||||
>
|
>
|
||||||
>:
|
>:std::true_type{};
|
||||||
decltype(has_1st_arg<const Arg&>(&F::template operator()<Arg>)){};
|
|
||||||
|
template<typename F,typename Arg>
|
||||||
|
struct takes_arg_as_const_reference0<
|
||||||
|
F,Arg,
|
||||||
|
boost::void_t<
|
||||||
|
decltype(std::declval<F>().operator()(std::declval<Arg&>()))
|
||||||
|
>
|
||||||
|
>:std::true_type{};
|
||||||
|
|
||||||
template<typename F,typename Arg,typename=void>
|
template<typename F,typename Arg,typename=void>
|
||||||
struct takes_arg_as_const_reference:takes_arg_as_const_reference0<F,Arg>{};
|
struct takes_arg_as_const_reference:takes_arg_as_const_reference0<F,Arg>{};
|
||||||
|
|
||||||
|
template<
|
||||||
|
typename F,typename Arg,
|
||||||
|
typename R=decltype(std::declval<F>()(std::declval<Arg&>())),
|
||||||
|
typename RawF=
|
||||||
|
typename std::remove_cv<typename std::remove_reference<F>::type>::type
|
||||||
|
>
|
||||||
|
using check_operator_call_takes_arg_as_reference=
|
||||||
|
decltype(check_memfun_1st_arg<Arg&,R,RawF>(&RawF::operator()));
|
||||||
|
|
||||||
template<typename F,typename Arg>
|
template<typename F,typename Arg>
|
||||||
struct takes_arg_as_const_reference<
|
struct takes_arg_as_const_reference<
|
||||||
F,Arg,
|
F,Arg,
|
||||||
boost::void_t<
|
boost::void_t<check_operator_call_takes_arg_as_reference<F,Arg>>
|
||||||
decltype(has_1st_arg<const Arg&>(&F::operator()))
|
>:std::false_type{};
|
||||||
>
|
|
||||||
>:
|
|
||||||
decltype(has_1st_arg<const Arg&>(&F::operator())){};
|
|
||||||
|
|
||||||
} /* namespace foa */
|
} /* namespace foa */
|
||||||
} /* namespace detail */
|
} /* namespace detail */
|
||||||
|
@@ -78,9 +78,9 @@ int main()
|
|||||||
int retrieved=0;
|
int retrieved=0;
|
||||||
auto lambda54 = [&]( const int& x ) mutable { retrieved = x; };
|
auto lambda54 = [&]( const int& x ) mutable { retrieved = x; };
|
||||||
using f54=decltype(lambda54);
|
using f54=decltype(lambda54);
|
||||||
auto lambda55 = []( int& ){};
|
auto lambda55 = []( int& x ){ x = 0; };
|
||||||
using f55=decltype(lambda55);
|
using f55=decltype(lambda55);
|
||||||
auto lambda56 = [&]( int& x ) mutable { retrieved = x; };
|
auto lambda56 = [&]( int& x ) mutable { retrieved = x; x = 0; };
|
||||||
using f56=decltype(lambda56);
|
using f56=decltype(lambda56);
|
||||||
|
|
||||||
#if !defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
#if !defined(BOOST_NO_CXX14_GENERIC_LAMBDAS)
|
||||||
@@ -88,9 +88,9 @@ int main()
|
|||||||
using f57=decltype(lambda57);
|
using f57=decltype(lambda57);
|
||||||
auto lambda58 = [&]( const auto& x ) mutable { retrieved = x; };
|
auto lambda58 = [&]( const auto& x ) mutable { retrieved = x; };
|
||||||
using f58=decltype(lambda58);
|
using f58=decltype(lambda58);
|
||||||
auto lambda59 = []( auto& ){};
|
auto lambda59 = []( auto& x ){ x = 0; };
|
||||||
using f59=decltype(lambda59);
|
using f59=decltype(lambda59);
|
||||||
auto lambda60 = [&]( auto& x ) mutable { retrieved = x; };
|
auto lambda60 = [&]( auto& x ) mutable { retrieved = x; x = 0; };
|
||||||
using f60=decltype(lambda60);
|
using f60=decltype(lambda60);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -122,14 +122,14 @@ int main()
|
|||||||
BOOST_TEST(( takes_arg_as_const_reference<f10, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f10, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f11, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f11, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f12, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f12, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f13, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f13&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f14, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f14&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f15, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f15&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f16, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f16&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f17, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f17&&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f18, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f18&&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f19, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f19&&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f20, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f20&&, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f21, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f21, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f22, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f22, int>::value ));
|
||||||
BOOST_TEST(( takes_arg_as_const_reference<f23, int>::value ));
|
BOOST_TEST(( takes_arg_as_const_reference<f23, int>::value ));
|
||||||
@@ -138,14 +138,14 @@ int main()
|
|||||||
BOOST_TEST(( !takes_arg_as_const_reference<f26, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f26, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f27, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f27, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f28, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f28, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f29, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f29&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f30, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f30&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f31, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f31&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f32, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f32&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f33, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f33&&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f34, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f34&&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f35, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f35&&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f36, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f36&&, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f37, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f37, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f38, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f38, int>::value ));
|
||||||
BOOST_TEST(( !takes_arg_as_const_reference<f39, int>::value ));
|
BOOST_TEST(( !takes_arg_as_const_reference<f39, int>::value ));
|
||||||
|
Reference in New Issue
Block a user