mirror of
https://github.com/boostorg/describe.git
synced 2026-01-19 16:12:19 +00:00
Compare commits
6 Commits
feature/ov
...
feature/ne
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94a80a6812 | ||
|
|
62c032ff22 | ||
|
|
bef1e45cb0 | ||
|
|
92afba2c39 | ||
|
|
031c55b392 | ||
|
|
36c52dcbd6 |
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@@ -159,6 +159,11 @@ jobs:
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2019
|
||||
- toolset: msvc-14.2
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
cxxflags: "-Zc:preprocessor"
|
||||
os: windows-2019
|
||||
- toolset: gcc
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
addrmd: 64
|
||||
@@ -195,4 +200,5 @@ jobs:
|
||||
shell: cmd
|
||||
run: |
|
||||
cd ../boost-root
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
|
||||
if not "${{matrix.cxxflags}}" == "" set CXXFLAGS=cxxflags=${{matrix.cxxflags}}
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} %CXXFLAGS% variant=debug,release
|
||||
|
||||
@@ -31,6 +31,11 @@ environment:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: clang-win
|
||||
CXXSTD: 14,17,latest
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
TOOLSET: msvc-14.2
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 32,64
|
||||
CXXFLAGS: -Zc:preprocessor
|
||||
|
||||
install:
|
||||
- set BOOST_BRANCH=develop
|
||||
@@ -49,4 +54,5 @@ build: off
|
||||
test_script:
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
- b2 -j3 libs/describe/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
|
||||
- if not "%CXXFLAGS%" == "" set CXXFLAGS=cxxflags=%CXXFLAGS%
|
||||
- b2 -j3 libs/describe/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %CXXFLAGS% variant=debug,release embed-manifest-via=linker
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <boost/describe/detail/bases.hpp>
|
||||
#include <boost/describe/detail/members.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -33,6 +34,7 @@ namespace describe
|
||||
friend BOOST_DESCRIBE_PRIVATE_MEMBERS(C, BOOST_DESCRIBE_PP_UNPACK Private)
|
||||
|
||||
#define BOOST_DESCRIBE_STRUCT(C, Bases, Members) \
|
||||
static_assert(std::is_class<C>::value, "BOOST_DESCRIBE_STRUCT should only be used with class types"); \
|
||||
BOOST_DESCRIBE_BASES(C, BOOST_DESCRIBE_PP_UNPACK Bases) \
|
||||
BOOST_DESCRIBE_PUBLIC_MEMBERS(C, BOOST_DESCRIBE_PP_UNPACK Members) \
|
||||
BOOST_DESCRIBE_PROTECTED_MEMBERS(C) \
|
||||
@@ -58,6 +60,7 @@ namespace describe
|
||||
friend BOOST_DESCRIBE_PRIVATE_MEMBERS_(C BOOST_DESCRIBE_PP_UNPACK Private)
|
||||
|
||||
#define BOOST_DESCRIBE_STRUCT(C, Bases, Members) \
|
||||
static_assert(std::is_class<C>::value, "BOOST_DESCRIBE_STRUCT should only be used with class types"); \
|
||||
BOOST_DESCRIBE_BASES_(C BOOST_DESCRIBE_PP_UNPACK Bases) \
|
||||
BOOST_DESCRIBE_PUBLIC_MEMBERS_(C BOOST_DESCRIBE_PP_UNPACK Members) \
|
||||
BOOST_DESCRIBE_PROTECTED_MEMBERS_(C) \
|
||||
|
||||
@@ -5,16 +5,19 @@
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/describe/detail/pp_for_each.hpp>
|
||||
#include <boost/describe/detail/list.hpp>
|
||||
#include <boost/describe/detail/config.hpp>
|
||||
|
||||
#if !defined(BOOST_DESCRIBE_CXX14)
|
||||
|
||||
#define BOOST_DESCRIBE_ENUM(E, ...)
|
||||
#define BOOST_DESCRIBE_NESTED_ENUM(E, ...)
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/describe/detail/pp_for_each.hpp>
|
||||
#include <boost/describe/detail/list.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace describe
|
||||
@@ -53,17 +56,31 @@ template<class... T> auto enum_descriptor_fn_impl( int, T... )
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
|
||||
#define BOOST_DESCRIBE_ENUM(E, ...) \
|
||||
static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_ENUM should only be used with enums"); \
|
||||
BOOST_DESCRIBE_ENUM_BEGIN(E) \
|
||||
BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, __VA_ARGS__) \
|
||||
BOOST_DESCRIBE_ENUM_END(E)
|
||||
|
||||
#define BOOST_DESCRIBE_NESTED_ENUM(E, ...) \
|
||||
static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_NESTED_ENUM should only be used with enums"); \
|
||||
friend BOOST_DESCRIBE_ENUM_BEGIN(E) \
|
||||
BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, __VA_ARGS__) \
|
||||
BOOST_DESCRIBE_ENUM_END(E)
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_DESCRIBE_ENUM(E, ...) \
|
||||
static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_ENUM should only be used with enums"); \
|
||||
BOOST_DESCRIBE_ENUM_BEGIN(E) \
|
||||
BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, ##__VA_ARGS__) \
|
||||
BOOST_DESCRIBE_ENUM_END(E)
|
||||
|
||||
#define BOOST_DESCRIBE_NESTED_ENUM(E, ...) \
|
||||
static_assert(std::is_enum<E>::value, "BOOST_DESCRIBE_NESTED_ENUM should only be used with enums"); \
|
||||
friend BOOST_DESCRIBE_ENUM_BEGIN(E) \
|
||||
BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_ENUM_ENTRY, E, ##__VA_ARGS__) \
|
||||
BOOST_DESCRIBE_ENUM_END(E)
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace describe
|
||||
|
||||
@@ -25,6 +25,7 @@ run pp_pointer_test.cpp ;
|
||||
run enumerators_test.cpp ;
|
||||
run empty_enum_test.cpp ;
|
||||
run trailing_comma_test.cpp ;
|
||||
run nested_enum_test.cpp ;
|
||||
|
||||
run compute_base_modifiers.cpp ;
|
||||
run bases_test.cpp ;
|
||||
@@ -41,12 +42,15 @@ run overloaded_test2.cpp ;
|
||||
|
||||
compile test_d_type.cpp ;
|
||||
|
||||
compile-fail enum_struct_fail.cpp ;
|
||||
compile-fail struct_enum_fail.cpp ;
|
||||
|
||||
obj describe_cxx14 : describe_cxx14.cpp ;
|
||||
explicit describe_cxx14 ;
|
||||
|
||||
local CXX14 = [ check-target-builds describe_cxx14 describe_cxx14 : : <build>no ] ;
|
||||
|
||||
local JSON = <library>/boost//json/<warnings>off "<toolset>msvc-14.0:<build>no" ;
|
||||
local JSON = <library>/boost//json/<warnings>off "<toolset>msvc-14.0:<build>no" "<toolset>msvc-14.2:<cxxflags>-wd5104" ;
|
||||
local SERIALIZATION = <library>/boost//serialization/<warnings>off "-<toolset>clang:<warnings-as-errors>on" ;
|
||||
|
||||
run ../example/printing_enums_ct.cpp : : : $(CXX14) ;
|
||||
|
||||
16
test/enum_struct_fail.cpp
Normal file
16
test/enum_struct_fail.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/describe/class.hpp>
|
||||
|
||||
#if !defined(BOOST_DESCRIBE_CXX14)
|
||||
|
||||
#error "Skipping test because C++14 is not available"
|
||||
|
||||
#else
|
||||
|
||||
enum E1 {};
|
||||
BOOST_DESCRIBE_STRUCT(E1, (), ())
|
||||
|
||||
#endif // !defined(BOOST_DESCRIBE_CXX14)
|
||||
130
test/nested_enum_test.cpp
Normal file
130
test/nested_enum_test.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
// Copyright 2020, 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/describe/enumerators.hpp>
|
||||
#include <boost/describe/enum.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct X1
|
||||
{
|
||||
enum E
|
||||
{
|
||||
v1 = 5
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_NESTED_ENUM(E, v1)
|
||||
};
|
||||
|
||||
class X2
|
||||
{
|
||||
private:
|
||||
|
||||
enum E
|
||||
{
|
||||
v1, v2
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_NESTED_ENUM(E, v1, v2)
|
||||
|
||||
public:
|
||||
|
||||
typedef E E2;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_DESCRIBE_CXX11)
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test because C++11 is not available")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
struct X3
|
||||
{
|
||||
enum class E
|
||||
{
|
||||
v1 = 7
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_NESTED_ENUM(E, v1)
|
||||
};
|
||||
|
||||
class X4
|
||||
{
|
||||
private:
|
||||
|
||||
enum class E
|
||||
{
|
||||
v1, v2
|
||||
};
|
||||
|
||||
BOOST_DESCRIBE_NESTED_ENUM(E, v1, v2)
|
||||
|
||||
public:
|
||||
|
||||
typedef E E2;
|
||||
};
|
||||
|
||||
#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>
|
||||
using namespace boost::mp11;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
using D = boost::describe::describe_enumerators<X1::E>;
|
||||
|
||||
BOOST_TEST_EQ( mp_size<D>::value, 1 );
|
||||
|
||||
BOOST_TEST_EQ( (mp_at_c<D, 0>::value), X1::v1 );
|
||||
BOOST_TEST_CSTR_EQ( (mp_at_c<D, 0>::name), "v1" );
|
||||
}
|
||||
|
||||
{
|
||||
using D = boost::describe::describe_enumerators<X2::E2>;
|
||||
|
||||
BOOST_TEST_EQ( mp_size<D>::value, 2 );
|
||||
|
||||
BOOST_TEST_EQ( (mp_at_c<D, 0>::value), 0 );
|
||||
BOOST_TEST_CSTR_EQ( (mp_at_c<D, 0>::name), "v1" );
|
||||
|
||||
BOOST_TEST_EQ( (mp_at_c<D, 1>::value), 1 );
|
||||
BOOST_TEST_CSTR_EQ( (mp_at_c<D, 1>::name), "v2" );
|
||||
}
|
||||
|
||||
{
|
||||
using D = boost::describe::describe_enumerators<X3::E>;
|
||||
|
||||
BOOST_TEST_EQ( mp_size<D>::value, 1 );
|
||||
|
||||
BOOST_TEST_EQ( (int)(mp_at_c<D, 0>::value), (int)X3::E::v1 );
|
||||
BOOST_TEST_CSTR_EQ( (mp_at_c<D, 0>::name), "v1" );
|
||||
}
|
||||
|
||||
{
|
||||
using D = boost::describe::describe_enumerators<X4::E2>;
|
||||
|
||||
BOOST_TEST_EQ( mp_size<D>::value, 2 );
|
||||
|
||||
BOOST_TEST_EQ( (int)(mp_at_c<D, 0>::value), 0 );
|
||||
BOOST_TEST_CSTR_EQ( (mp_at_c<D, 0>::name), "v1" );
|
||||
|
||||
BOOST_TEST_EQ( (int)(mp_at_c<D, 1>::value), 1 );
|
||||
BOOST_TEST_CSTR_EQ( (mp_at_c<D, 1>::name), "v2" );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif // !defined(BOOST_DESCRIBE_CXX14)
|
||||
#endif // !defined(BOOST_DESCRIBE_CXX11)
|
||||
16
test/struct_enum_fail.cpp
Normal file
16
test/struct_enum_fail.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2021 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/describe/enum.hpp>
|
||||
|
||||
#if !defined(BOOST_DESCRIBE_CXX14)
|
||||
|
||||
#error "Skipping test because C++14 is not available"
|
||||
|
||||
#else
|
||||
|
||||
struct X {};
|
||||
BOOST_DESCRIBE_ENUM(X)
|
||||
|
||||
#endif // !defined(BOOST_DESCRIBE_CXX14)
|
||||
Reference in New Issue
Block a user