Use PP_NAME, PP_POINTER when describing members; add overloaded_test

This commit is contained in:
Peter Dimov
2021-03-16 01:44:53 +02:00
parent ed26d4c495
commit 564f849629
3 changed files with 89 additions and 2 deletions

View File

@@ -7,6 +7,7 @@
#include <boost/describe/modifiers.hpp>
#include <boost/describe/detail/pp_for_each.hpp>
#include <boost/describe/detail/pp_utilities.hpp>
#include <boost/describe/detail/list.hpp>
#include <type_traits>
@@ -43,9 +44,12 @@ template<unsigned M, class... T> auto member_descriptor_fn_impl( int, T... )
return list<member_descriptor<T, M>...>();
}
template<class C, class F> constexpr auto mfn( F C::* p ) { return p; }
template<class C, class F> constexpr auto mfn( F * p ) { return p; }
#define BOOST_DESCRIBE_MEMBER_IMPL(C, m) , []{ struct _boost_desc { \
static constexpr auto pointer() noexcept { return &C::m; } \
static constexpr auto name() noexcept { return #m; } }; return _boost_desc(); }()
static constexpr auto pointer() noexcept { return BOOST_DESCRIBE_PP_POINTER(C, m); } \
static constexpr auto name() noexcept { return BOOST_DESCRIBE_PP_NAME(m); } }; return _boost_desc(); }()
#if defined(_MSC_VER) && !defined(__clang__)

View File

@@ -36,6 +36,7 @@ run members_test4.cpp ;
run members_test5.cpp ;
run members_test6.cpp ;
run members_test7.cpp : : : <toolset>msvc-14.0:<build>no ;
run overloaded_test.cpp ;
compile test_d_type.cpp ;

82
test/overloaded_test.cpp Normal file
View File

@@ -0,0 +1,82 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/describe/members.hpp>
#include <boost/describe/class.hpp>
#include <boost/core/lightweight_test.hpp>
struct X
{
int f() { return 1; }
int f() const { return 2; }
static int f( int x ) { return x; }
static int f( int x, int y ) { return x + y; }
};
BOOST_DESCRIBE_STRUCT(X, (), (
(int ()) f,
(int () const) f,
(int (int)) f,
(int (int, int)) f
))
#if !defined(BOOST_DESCRIBE_CXX14)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available")
int main() {}
#else
#include <boost/mp11.hpp>
int main()
{
using namespace boost::describe;
using namespace boost::mp11;
{
using L = describe_members<X, mod_any_access | mod_function>;
BOOST_TEST_EQ( mp_size<L>::value, 2 );
using D1 = mp_at_c<L, 0>;
using D2 = mp_at_c<L, 1>;
X x;
BOOST_TEST_EQ( (x.*D1::pointer)(), 1 );
BOOST_TEST_CSTR_EQ( D1::name, "f" );
BOOST_TEST_EQ( D1::modifiers, mod_public | mod_function );
BOOST_TEST_EQ( (x.*D2::pointer)(), 2 );
BOOST_TEST_CSTR_EQ( D2::name, "f" );
BOOST_TEST_EQ( D2::modifiers, mod_public | mod_function );
}
{
using L = describe_members<X, mod_any_access | mod_static | mod_function>;
BOOST_TEST_EQ( mp_size<L>::value, 2 );
using D1 = mp_at_c<L, 0>;
using D1 = mp_at_c<L, 0>;
using D2 = mp_at_c<L, 1>;
BOOST_TEST_EQ( (*D1::pointer)( 3 ), 3 );
BOOST_TEST_CSTR_EQ( D1::name, "f" );
BOOST_TEST_EQ( D1::modifiers, mod_public | mod_static | mod_function );
BOOST_TEST_EQ( (*D2::pointer)( 4, 5 ), 9 );
BOOST_TEST_CSTR_EQ( D2::name, "f" );
BOOST_TEST_EQ( D2::modifiers, mod_public | mod_static | mod_function );
}
return boost::report_errors();
}
#endif // !defined(BOOST_DESCRIBE_CXX14)