Compare commits

...

8 Commits

Author SHA1 Message Date
Peter Dimov
3047e5a72f Document the new overload of enum_from_string 2023-09-09 19:07:05 +03:00
Peter Dimov
cfddb57d3a Add an overload of enum_from_string that takes a string-like type (such as string_view). Fixes #41. 2023-09-09 18:52:41 +03:00
Peter Dimov
6e7d49c6e1 Do not use -Werror with Serialization under GCC 2023-09-09 17:57:18 +03:00
Peter Dimov
cc2281054e {"world"} is now string in Boost.JSON, not array 2023-09-09 17:23:26 +03:00
Peter Dimov
215042b480 Update ci.yml 2023-09-09 17:03:54 +03:00
Peter Dimov
a0eafb0810 Merge branch 'fix-deprecated-inline-static-variables' of https://github.com/Romain-Geissler-1A/describe into feature/pr-40 2023-05-21 04:51:35 +03:00
Peter Dimov
1692c3e5d6 Update ci.yml 2023-05-21 04:05:26 +03:00
Romain Geissler
b54fda5469 Fix -Wdeprecated warnings when compiling with C++ >= 17 (ie with inline variables).
Example of warning we get:
/data/mwrep/res/osp/Boost/23-0-0-0/include/boost/describe/members.hpp:89:81: error: redundant redeclaration of 'constexpr' static data member 'boost::describe::detail::update_modifiers<T, Bm>::fn<D>::pointer' [-Werror=deprecated]
 89 | template<class T, unsigned Bm> template<class D> constexpr decltype(D::pointer) update_modifiers<T, Bm>::fn<D>::pointer;
    | ^~~~~~~~~~~~~~~~~~~~~~~ /data/mwrep/res/osp/Boost/23-0-0-0/include/boost/describe/members.hpp:83:47: note: previous declaration of 'boost::describe::detail::update_modifiers<T, Bm>::fn<D>::pointer'
 83 | static constexpr decltype(D::pointer) pointer = D::pointer;
    | ^~~~~~~
2023-05-20 23:41:18 +00:00
11 changed files with 371 additions and 24 deletions

View File

@@ -19,62 +19,73 @@ jobs:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: "03,11,14,14-gnu,1z,1z-gnu"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,14-gnu,1z,1z-gnu"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,14-gnu,17,17-gnu"
os: ubuntu-18.04
os: ubuntu-20.04
install: g++-7
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
os: ubuntu-20.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
os: ubuntu-22.04
install: g++-10
- toolset: gcc-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
os: ubuntu-22.04
- toolset: gcc-12
cxxstd: "03,11,14,17,20"
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12
- toolset: gcc-13
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
install: g++-13
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
@@ -103,26 +114,56 @@ jobs:
install: clang-12
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20"
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20"
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-15
- toolset: clang
compiler: clang++-16
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-latest
container: ubuntu:23.04
install: clang-16
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-11
- toolset: clang
cxxstd: "03,11,14,17,20,2b"
os: macos-12
- toolset: clang
cxxstd: "03,11,14,17,20,2b"
os: macos-13
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python3 git g++
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: |
sudo apt-get update
sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -143,7 +184,7 @@ jobs:
mkdir -p libs/$LIBRARY
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" -I example $LIBRARY
python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" -I example $LIBRARY
./bootstrap.sh
./b2 -d0 headers
@@ -232,10 +273,11 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
- os: macos-13
runs-on: ${{matrix.os}}
@@ -279,10 +321,11 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
- os: macos-13
runs-on: ${{matrix.os}}
@@ -336,10 +379,11 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
- os: macos-13
runs-on: ${{matrix.os}}
@@ -385,3 +429,183 @@ jobs:
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error
windows-cmake-subdir:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Use library with add_subdirectory (Debug)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake ..
cmake --build . --config Debug
ctest --output-on-failure --no-tests=error -C Debug
- name: Use library with add_subdirectory (Release)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__
cmake --build . --config Release
ctest --output-on-failure --no-tests=error -C Release
windows-cmake-install:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Configure
shell: cmd
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- name: Install (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target install --config Debug
- name: Install (Release)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target install --config Release
- name: Use the installed library (Debug)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__
cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
cmake --build . --config Debug
ctest --output-on-failure --no-tests=error -C Debug
- name: Use the installed library (Release)
shell: cmd
run: |
cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__
cmake --build . --config Release
ctest --output-on-failure --no-tests=error -C Release
windows-cmake-test:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
- name: Configure
shell: cmd
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON ..
- name: Build tests (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target tests --config Debug
- name: Run tests (Debug)
shell: cmd
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error -C Debug
- name: Build tests (Release)
shell: cmd
run: |
cd ../boost-root/__build__
cmake --build . --target tests --config Release
- name: Run tests (Release)
shell: cmd
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error -C Release

View File

@@ -8,6 +8,11 @@ https://www.boost.org/LICENSE_1_0.txt
# Revision History
:idprefix:
## Changes in Boost 1.84.0
* Added an overload of `enum_from_string` that takes a string view, to avoid
the need for null termination.
## Changes in Boost 1.81.0
* To allow the inclusion of `enumerators.hpp`, `bases.hpp`, and `members.hpp`

View File

@@ -362,6 +362,7 @@ namespace boost {
namespace describe {
template<class E> bool enum_from_string( char const * name, E & e ) noexcept;
template<class S, class E> bool enum_from_string( S const & name, E & e ) noexcept;
} }
```
@@ -372,6 +373,11 @@ The function `enum_from_string` assigns to `e` the enumerator value correspondin
to `name` and returns `true`. `E` must be a described enumeration type. If `name`
does not correspond to one of the described values, the function returns `false`.
The second overload only participates in overload resolution when `S` is a
string-like type such as `std::string` or `std::string_view`. String-like types
are recognized by the presence of nested `value_type` and `traits_type` typedefs
and are expected to have a non-throwing `operator==` taking `char const*`.
## <boost/describe/operators.hpp>
```

View File

@@ -80,6 +80,6 @@ BOOST_DESCRIBE_STRUCT(Object, (), (greet, add))
int main()
{
Object obj;
std::cout << call( obj, "greet", { "world" } ) << std::endl;
std::cout << call( obj, "add", { 1, 2 } ) << std::endl;
std::cout << call( obj, "greet", {{ "world" }} ) << std::endl;
std::cout << call( obj, "add", {{ 1, 2 }} ) << std::endl;
}

View File

@@ -26,7 +26,9 @@ template<class C, class B> struct base_descriptor
static constexpr unsigned modifiers = compute_base_modifiers<C, B>();
};
#ifndef __cpp_inline_variables
template<class C, class B> constexpr unsigned base_descriptor<C, B>::modifiers;
#endif
template<class... T> auto base_descriptor_fn_impl( int, T... )
{

View File

@@ -35,9 +35,11 @@ template<class D, unsigned M> struct member_descriptor
static constexpr unsigned modifiers = M | add_static_modifier( D::pointer() ) | add_function_modifier( D::pointer() );
};
#ifndef __cpp_inline_variables
template<class D, unsigned M> constexpr decltype(D::pointer()) member_descriptor<D, M>::pointer;
template<class D, unsigned M> constexpr decltype(D::name()) member_descriptor<D, M>::name;
template<class D, unsigned M> constexpr unsigned member_descriptor<D, M>::modifiers;
#endif
template<unsigned M, class... T> auto member_descriptor_fn_impl( int, T... )
{

View File

@@ -32,9 +32,11 @@ template<class D> struct enum_descriptor
static constexpr decltype(D::name()) name = D::name();
};
#ifndef __cpp_inline_variables
// GCC requires these definitions
template<class D> constexpr decltype(D::value()) enum_descriptor<D>::value;
template<class D> constexpr decltype(D::name()) enum_descriptor<D>::name;
#endif
template<class... T> auto enum_descriptor_fn_impl( int, T... )
{

View File

@@ -12,6 +12,7 @@
#include <boost/describe/enumerators.hpp>
#include <boost/mp11/algorithm.hpp>
#include <cstring>
#include <type_traits>
#if defined(_MSC_VER) && _MSC_VER == 1900
# pragma warning(push)
@@ -41,6 +42,29 @@ bool enum_from_string( char const* name, E& e ) noexcept
return found;
}
template<class S, class E, class De = describe_enumerators<E>,
class En = std::enable_if_t<
std::is_same<typename S::value_type, char>::value &&
std::is_same<typename S::traits_type::char_type, char>::value
>
>
bool enum_from_string( S const& name, E& e ) noexcept
{
bool found = false;
mp11::mp_for_each<De>([&](auto D){
if( !found && name == D.name )
{
found = true;
e = D.value;
}
});
return found;
}
} // namespace describe
} // namespace boost

View File

@@ -86,9 +86,11 @@ template<class T, unsigned Bm> struct update_modifiers
};
};
#ifndef __cpp_inline_variables
template<class T, unsigned Bm> template<class D> constexpr decltype(D::pointer) update_modifiers<T, Bm>::fn<D>::pointer;
template<class T, unsigned Bm> template<class D> constexpr decltype(D::name) update_modifiers<T, Bm>::fn<D>::name;
template<class T, unsigned Bm> template<class D> constexpr unsigned update_modifiers<T, Bm>::fn<D>::modifiers;
#endif
template<class D> struct gather_virtual_bases_impl;
template<class D> using gather_virtual_bases = typename gather_virtual_bases_impl<D>::type;

View File

@@ -78,6 +78,8 @@ run pedantic_bases_test.cpp
run pedantic_members_test.cpp
: : : <warnings>pedantic ;
run enum_from_string_test2.cpp ;
# examples
obj describe_cxx14 : describe_cxx14.cpp ;
@@ -86,7 +88,7 @@ explicit describe_cxx14 ;
local CXX14 = [ check-target-builds describe_cxx14 describe_cxx14 : : <build>no ] "<toolset>msvc-14.0:<cxxflags>-wd4100" ;
local JSON = <library>/boost//json/<warnings>off "<toolset>msvc-14.2:<cxxflags>-wd5104" ;
local SERIALIZATION = <library>/boost//serialization/<warnings>off "-<toolset>clang:<warnings-as-errors>on" ;
local SERIALIZATION = <library>/boost//serialization/<warnings>off "-<toolset>gcc:<warnings-as-errors>on" "-<toolset>clang:<warnings-as-errors>on" ;
run ../example/printing_enums_ct.cpp : : : $(CXX14) ;
run ../example/printing_enums_rt.cpp : : : $(CXX14) ;

View File

@@ -0,0 +1,78 @@
// 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_from_string.hpp>
#include <boost/describe/enum.hpp>
#include <boost/core/detail/string_view.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#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
enum E1 { v101 = 101, v102 = 102 };
BOOST_DESCRIBE_ENUM(E1, v101, v102)
enum class E2 { v201 = 201, v202 = 202 };
BOOST_DESCRIBE_ENUM(E2, v201, v202)
BOOST_DEFINE_ENUM(E3, v301, v302)
BOOST_DEFINE_ENUM_CLASS(E4, v401, v402)
template<class St> void test()
{
using boost::describe::enum_from_string;
{
E1 w{};
BOOST_TEST( enum_from_string( St( "v101" ), w ) ) && BOOST_TEST_EQ( w, v101 );
BOOST_TEST( enum_from_string( St( "v102" ), w ) ) && BOOST_TEST_EQ( w, v102 );
BOOST_TEST_NOT( enum_from_string( St( "v103" ), w ) );
}
{
E2 w{};
BOOST_TEST( enum_from_string( St( "v201" ), w ) ) && BOOST_TEST_EQ( (int)w, (int)E2::v201 );
BOOST_TEST( enum_from_string( St( "v202" ), w ) ) && BOOST_TEST_EQ( (int)w, (int)E2::v202 );
BOOST_TEST_NOT( enum_from_string( St( "v203" ), w ) );
}
{
E3 w{};
BOOST_TEST( enum_from_string( St( "v301" ), w ) ) && BOOST_TEST_EQ( w, v301 );
BOOST_TEST( enum_from_string( St( "v302" ), w ) ) && BOOST_TEST_EQ( w, v302 );
BOOST_TEST_NOT( enum_from_string( St( "v303" ), w ) );
}
{
E4 w{};
BOOST_TEST( enum_from_string( St( "v401" ), w ) ) && BOOST_TEST_EQ( (int)w, (int)E4::v401 );
BOOST_TEST( enum_from_string( St( "v402" ), w ) ) && BOOST_TEST_EQ( (int)w, (int)E4::v402 );
BOOST_TEST_NOT( enum_from_string( St( "v403" ), w ) );
}
}
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
# include <string_view>
#endif
int main()
{
test<std::string>();
test<boost::core::string_view>();
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
test<std::string_view>();
#endif
return boost::report_errors();
}
#endif // !defined(BOOST_DESCRIBE_CXX14)