From 5ec603ce5ccb88c98e24e5a324c0e72f5983186c Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 17:10:25 +0300 Subject: [PATCH 01/16] Rewrite modules to the new recommended Boost practice --- CMakeLists.txt | 33 ++++++-- include/boost/pfr/config.hpp | 14 +--- include/boost/pfr/core.hpp | 18 ++-- include/boost/pfr/core_name.hpp | 18 ++-- include/boost/pfr/detail/core14_classic.hpp | 14 ++-- include/boost/pfr/detail/core14_loophole.hpp | 2 +- include/boost/pfr/detail/core17_generated.hpp | 2 +- .../boost/pfr/detail/core_name20_static.hpp | 2 +- include/boost/pfr/detail/detectors.hpp | 2 +- include/boost/pfr/detail/fields_count.hpp | 2 +- include/boost/pfr/detail/for_each_field.hpp | 12 +-- .../boost/pfr/detail/for_each_field_impl.hpp | 8 +- include/boost/pfr/detail/functional.hpp | 6 +- include/boost/pfr/detail/io.hpp | 2 +- .../detail/make_flat_tuple_of_references.hpp | 11 ++- .../pfr/detail/make_integer_sequence.hpp | 2 +- .../boost/pfr/detail/offset_based_getter.hpp | 11 ++- .../boost/pfr/detail/possible_reflectable.hpp | 2 +- include/boost/pfr/detail/rvalue_t.hpp | 2 +- include/boost/pfr/detail/sequence_tuple.hpp | 2 +- include/boost/pfr/detail/size_array.hpp | 2 +- include/boost/pfr/detail/size_t_.hpp | 7 ++ include/boost/pfr/detail/stdarray.hpp | 6 +- include/boost/pfr/detail/stdtuple.hpp | 6 +- .../pfr/detail/tie_from_structure_tuple.hpp | 2 +- include/boost/pfr/detail/unsafe_declval.hpp | 2 +- include/boost/pfr/functions_for.hpp | 4 + include/boost/pfr/functors.hpp | 10 ++- include/boost/pfr/io.hpp | 14 ++-- include/boost/pfr/io_fields.hpp | 25 +++--- include/boost/pfr/ops.hpp | 10 ++- include/boost/pfr/ops_fields.hpp | 10 ++- include/boost/pfr/traits.hpp | 15 +++- include/boost/pfr/traits_fwd.hpp | 10 ++- include/boost/pfr/tuple_size.hpp | 18 ++-- misc/generate_cpp17.py | 2 +- module/CMakeLists.txt | 37 --------- module/pfr.cppm | 44 ---------- modules/CMakeLists.txt | 11 +++ modules/pfr.cppm | 83 +++++++++++++++++++ {module => modules}/usage_sample.cpp | 7 +- {module => modules}/usage_test_mu1.cpp | 4 +- {module => modules}/usage_test_mu2.cpp | 6 +- 43 files changed, 280 insertions(+), 220 deletions(-) delete mode 100644 module/CMakeLists.txt delete mode 100644 module/pfr.cppm create mode 100644 modules/CMakeLists.txt create mode 100644 modules/pfr.cppm rename {module => modules}/usage_sample.cpp (92%) rename {module => modules}/usage_test_mu1.cpp (97%) rename {module => modules}/usage_test_mu2.cpp (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e05acce2..a55b81e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,20 +4,37 @@ # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.5...3.16) +cmake_minimum_required(VERSION 3.5...3.31) project(boost_pfr VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) -add_library(boost_pfr INTERFACE) -add_library(Boost::pfr ALIAS boost_pfr) - -target_include_directories(boost_pfr INTERFACE include) - -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BUILD_MODULE) - add_subdirectory(module) +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) + add_library(boost_pfr STATIC) + target_compile_features(boost_pfr PUBLIC cxx_std_23) + target_sources(boost_pfr PUBLIC + FILE_SET modules_public TYPE CXX_MODULES FILES + ${CMAKE_CURRENT_LIST_DIR}/modules/pfr.cppm + ) + set_target_properties(boost_pfr PROPERTIES CXX_MODULE_STD 1) + target_compile_definitions(boost_pfr PUBLIC BOOST_USE_MODULES) + target_include_directories(boost_pfr PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +else() + add_library(boost_pfr INTERFACE) + target_include_directories(boost_pfr INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) endif() +add_library(Boost::pfr ALIAS boost_pfr) + if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") add_subdirectory(test) endif() +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES AND BUILD_TESTING) + add_executable(boost_pfr_module_usage modules/usage_sample.cpp) + target_link_libraries(boost_pfr_module_usage PRIVATE Boost::pfr) + + # Make sure that mixing includes and imports is fine for different TU + add_executable(boost_pfr_module_usage_mu modules/usage_test_mu1.cpp modules/usage_test_mu2.cpp) + target_link_libraries(boost_pfr_module_usage_mu PRIVATE Boost::pfr) +endif() + diff --git a/include/boost/pfr/config.hpp b/include/boost/pfr/config.hpp index 65d27539..8db4b75c 100644 --- a/include/boost/pfr/config.hpp +++ b/include/boost/pfr/config.hpp @@ -8,7 +8,7 @@ #define BOOST_PFR_CONFIG_HPP #pragma once -#if __cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900) +#if !defined(BOOST_USE_MODULES) #include // to get non standard platform macro definitions (__GLIBCXX__ for example) #endif @@ -70,8 +70,10 @@ #endif #ifndef BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE +# if defined(BOOST_USE_MODULES) +# define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 // Assume that libstdc++ since GCC-7.3 does not have linear instantiation depth in std::make_integral_sequence -# if defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101 +# elif defined( __GLIBCXX__) && __GLIBCXX__ >= 20180101 # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 # elif defined(_MSC_VER) # define BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE 1 @@ -145,12 +147,4 @@ #undef BOOST_PFR_NOT_SUPPORTED -#ifndef BOOST_PFR_BEGIN_MODULE_EXPORT -# define BOOST_PFR_BEGIN_MODULE_EXPORT -#endif - -#ifndef BOOST_PFR_END_MODULE_EXPORT -# define BOOST_PFR_END_MODULE_EXPORT -#endif - #endif // BOOST_PFR_CONFIG_HPP diff --git a/include/boost/pfr/core.hpp b/include/boost/pfr/core.hpp index 0785c921..ce0803db 100644 --- a/include/boost/pfr/core.hpp +++ b/include/boost/pfr/core.hpp @@ -9,6 +9,10 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include #include @@ -17,10 +21,14 @@ #include #include +#include + +#if defined(BOOST_USE_MODULES) +import std; +#else #include #include // metaprogramming stuff - -#include +#endif /// \file boost/pfr/core.hpp /// Contains all the basic tuple-like interfaces \forcedlink{get}, \forcedlink{tuple_size}, \forcedlink{tuple_element_t}, and others. @@ -29,8 +37,6 @@ namespace boost { namespace pfr { -BOOST_PFR_BEGIN_MODULE_EXPORT - /// \brief Returns reference or const reference to a field with index `I` in \aggregate `val`. /// Overload taking the type `U` returns reference or const reference to a field /// with provided type `U` in \aggregate `val` if there's only one field of such type in `val`. @@ -245,8 +251,8 @@ constexpr detail::tie_from_structure_tuple tie_from_structure(Eleme return detail::tie_from_structure_tuple(args...); } -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_CORE_HPP diff --git a/include/boost/pfr/core_name.hpp b/include/boost/pfr/core_name.hpp index 7b73e3df..277632f4 100644 --- a/include/boost/pfr/core_name.hpp +++ b/include/boost/pfr/core_name.hpp @@ -14,16 +14,24 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include #include #include #include -#include // for std::size_t - #include +#if defined(BOOST_USE_MODULES) +import std; +#else +#include // for std::size_t +#endif + /// \file boost/pfr/core_name.hpp /// Contains functions \forcedlink{get_name} and \forcedlink{names_as_array} to know which names each field of any \aggregate has. /// @@ -33,8 +41,6 @@ namespace boost { namespace pfr { -BOOST_PFR_BEGIN_MODULE_EXPORT - /// \brief Returns name of a field with index `I` in \aggregate `T`. /// /// \b Example: @@ -106,8 +112,8 @@ constexpr void for_each_field_with_name(T&& value, F&& func) { return boost::pfr::detail::for_each_field_with_name(std::forward(value), std::forward(func)); } -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_CORE_NAME_HPP diff --git a/include/boost/pfr/detail/core14_classic.hpp b/include/boost/pfr/detail/core14_classic.hpp index 419ee6f5..789738ff 100644 --- a/include/boost/pfr/detail/core14_classic.hpp +++ b/include/boost/pfr/detail/core14_classic.hpp @@ -9,13 +9,6 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE -import std; -#else -#include -#include // metaprogramming stuff -#endif - #include #include #include @@ -25,6 +18,13 @@ import std; #include #include +#if defined(BOOST_USE_MODULES) +import std; +#else +#include +#include // metaprogramming stuff +#endif + #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wmissing-braces" diff --git a/include/boost/pfr/detail/core14_loophole.hpp b/include/boost/pfr/detail/core14_loophole.hpp index d9e42bd9..2990fa58 100644 --- a/include/boost/pfr/detail/core14_loophole.hpp +++ b/include/boost/pfr/detail/core14_loophole.hpp @@ -24,7 +24,7 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/core17_generated.hpp b/include/boost/pfr/detail/core17_generated.hpp index 9b3d0731..8c9a2a61 100644 --- a/include/boost/pfr/detail/core17_generated.hpp +++ b/include/boost/pfr/detail/core17_generated.hpp @@ -22,7 +22,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include // for std::conditional_t, std::is_reference diff --git a/include/boost/pfr/detail/core_name20_static.hpp b/include/boost/pfr/detail/core_name20_static.hpp index 3c99e17a..3f3c5a62 100644 --- a/include/boost/pfr/detail/core_name20_static.hpp +++ b/include/boost/pfr/detail/core_name20_static.hpp @@ -22,7 +22,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/detectors.hpp b/include/boost/pfr/detail/detectors.hpp index 5631815a..a3a19344 100644 --- a/include/boost/pfr/detail/detectors.hpp +++ b/include/boost/pfr/detail/detectors.hpp @@ -9,7 +9,7 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/fields_count.hpp b/include/boost/pfr/detail/fields_count.hpp index 1b6a5d8c..11f1f969 100644 --- a/include/boost/pfr/detail/fields_count.hpp +++ b/include/boost/pfr/detail/fields_count.hpp @@ -12,7 +12,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include // CHAR_BIT diff --git a/include/boost/pfr/detail/for_each_field.hpp b/include/boost/pfr/detail/for_each_field.hpp index 5e868eb8..810f7014 100644 --- a/include/boost/pfr/detail/for_each_field.hpp +++ b/include/boost/pfr/detail/for_each_field.hpp @@ -9,17 +9,17 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE -import std; -#else -#include // metaprogramming stuff -#endif - #include #include #include #include +#if defined(BOOST_USE_MODULES) +import std; +#else +#include // metaprogramming stuff +#endif + namespace boost { namespace pfr { namespace detail { template diff --git a/include/boost/pfr/detail/for_each_field_impl.hpp b/include/boost/pfr/detail/for_each_field_impl.hpp index 52a05faa..3686fbfb 100644 --- a/include/boost/pfr/detail/for_each_field_impl.hpp +++ b/include/boost/pfr/detail/for_each_field_impl.hpp @@ -9,15 +9,15 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#include +#include + +#if defined(BOOST_USE_MODULES) import std; #else #include // metaprogramming stuff #endif -#include -#include - namespace boost { namespace pfr { namespace detail { template diff --git a/include/boost/pfr/detail/functional.hpp b/include/boost/pfr/detail/functional.hpp index eed0ee64..75a7a189 100644 --- a/include/boost/pfr/detail/functional.hpp +++ b/include/boost/pfr/detail/functional.hpp @@ -9,15 +9,15 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#include + +#if defined(BOOST_USE_MODULES) import std; #else #include #include #endif -#include - namespace boost { namespace pfr { namespace detail { template struct equal_impl { diff --git a/include/boost/pfr/detail/io.hpp b/include/boost/pfr/detail/io.hpp index a28c3156..90b72659 100644 --- a/include/boost/pfr/detail/io.hpp +++ b/include/boost/pfr/detail/io.hpp @@ -11,7 +11,7 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include // stream operators diff --git a/include/boost/pfr/detail/make_flat_tuple_of_references.hpp b/include/boost/pfr/detail/make_flat_tuple_of_references.hpp index a54fc519..55928e50 100644 --- a/include/boost/pfr/detail/make_flat_tuple_of_references.hpp +++ b/include/boost/pfr/detail/make_flat_tuple_of_references.hpp @@ -9,16 +9,15 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE -import std; -#else -#include // metaprogramming stuff -#endif - #include #include #include +#if defined(BOOST_USE_MODULES) +import std; +#else +#include // metaprogramming stuff +#endif namespace boost { namespace pfr { namespace detail { diff --git a/include/boost/pfr/detail/make_integer_sequence.hpp b/include/boost/pfr/detail/make_integer_sequence.hpp index cf72cc41..f1c0b99b 100644 --- a/include/boost/pfr/detail/make_integer_sequence.hpp +++ b/include/boost/pfr/detail/make_integer_sequence.hpp @@ -10,7 +10,7 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/offset_based_getter.hpp b/include/boost/pfr/detail/offset_based_getter.hpp index b4641466..9c3f2f2c 100644 --- a/include/boost/pfr/detail/offset_based_getter.hpp +++ b/include/boost/pfr/detail/offset_based_getter.hpp @@ -10,7 +10,11 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#include +#include +#include + +#if defined(BOOST_USE_MODULES) import std; #else #include @@ -18,11 +22,6 @@ import std; #include // std::addressof #endif -#include -#include -#include - - namespace boost { namespace pfr { namespace detail { // Our own implementation of std::aligned_storage. On godbolt with MSVC, I have compilation errors diff --git a/include/boost/pfr/detail/possible_reflectable.hpp b/include/boost/pfr/detail/possible_reflectable.hpp index 9081d303..990adeb5 100644 --- a/include/boost/pfr/detail/possible_reflectable.hpp +++ b/include/boost/pfr/detail/possible_reflectable.hpp @@ -10,7 +10,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include // for std::is_aggregate diff --git a/include/boost/pfr/detail/rvalue_t.hpp b/include/boost/pfr/detail/rvalue_t.hpp index 06ecfec0..ede795bf 100644 --- a/include/boost/pfr/detail/rvalue_t.hpp +++ b/include/boost/pfr/detail/rvalue_t.hpp @@ -7,7 +7,7 @@ #define BOOST_PFR_DETAIL_RVALUE_T_HPP #pragma once -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/sequence_tuple.hpp b/include/boost/pfr/detail/sequence_tuple.hpp index a833a7e8..8814bd01 100644 --- a/include/boost/pfr/detail/sequence_tuple.hpp +++ b/include/boost/pfr/detail/sequence_tuple.hpp @@ -10,7 +10,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/size_array.hpp b/include/boost/pfr/detail/size_array.hpp index 63b94279..eb33083e 100644 --- a/include/boost/pfr/detail/size_array.hpp +++ b/include/boost/pfr/detail/size_array.hpp @@ -9,7 +9,7 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/size_t_.hpp b/include/boost/pfr/detail/size_t_.hpp index 4b9564ee..b6dc82fb 100644 --- a/include/boost/pfr/detail/size_t_.hpp +++ b/include/boost/pfr/detail/size_t_.hpp @@ -7,6 +7,13 @@ #define BOOST_PFR_DETAIL_SIZE_T_HPP #pragma once +#if defined(BOOST_USE_MODULES) +import std; +#else +#include +#include +#endif + namespace boost { namespace pfr { namespace detail { ///////////////////// General utility stuff diff --git a/include/boost/pfr/detail/stdarray.hpp b/include/boost/pfr/detail/stdarray.hpp index 77202b72..dc2452d1 100644 --- a/include/boost/pfr/detail/stdarray.hpp +++ b/include/boost/pfr/detail/stdarray.hpp @@ -9,7 +9,9 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#include + +#if defined(BOOST_USE_MODULES) import std; #else #include // metaprogramming stuff @@ -18,8 +20,6 @@ import std; #include #endif -#include - namespace boost { namespace pfr { namespace detail { template diff --git a/include/boost/pfr/detail/stdtuple.hpp b/include/boost/pfr/detail/stdtuple.hpp index ab98032c..c4183071 100644 --- a/include/boost/pfr/detail/stdtuple.hpp +++ b/include/boost/pfr/detail/stdtuple.hpp @@ -9,15 +9,15 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#include + +#if defined(BOOST_USE_MODULES) import std; #else #include // metaprogramming stuff #include #endif -#include - namespace boost { namespace pfr { namespace detail { template diff --git a/include/boost/pfr/detail/tie_from_structure_tuple.hpp b/include/boost/pfr/detail/tie_from_structure_tuple.hpp index c20f2625..ae75b394 100644 --- a/include/boost/pfr/detail/tie_from_structure_tuple.hpp +++ b/include/boost/pfr/detail/tie_from_structure_tuple.hpp @@ -16,7 +16,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/detail/unsafe_declval.hpp b/include/boost/pfr/detail/unsafe_declval.hpp index 8848b2cd..3cb0a8ee 100644 --- a/include/boost/pfr/detail/unsafe_declval.hpp +++ b/include/boost/pfr/detail/unsafe_declval.hpp @@ -9,7 +9,7 @@ #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include diff --git a/include/boost/pfr/functions_for.hpp b/include/boost/pfr/functions_for.hpp index aac27a30..a2b63ee8 100644 --- a/include/boost/pfr/functions_for.hpp +++ b/include/boost/pfr/functions_for.hpp @@ -9,8 +9,12 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else #include #include +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) /// \file boost/pfr/functions_for.hpp /// Contains BOOST_PFR_FUNCTIONS_FOR macro that defined comparison and stream operators for T along with hash_value function. diff --git a/include/boost/pfr/functors.hpp b/include/boost/pfr/functors.hpp index 8ea57888..e21faf27 100644 --- a/include/boost/pfr/functors.hpp +++ b/include/boost/pfr/functors.hpp @@ -9,6 +9,10 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include #include @@ -35,8 +39,6 @@ /// \b Synopsis: namespace boost { namespace pfr { -BOOST_PFR_BEGIN_MODULE_EXPORT - ///////////////////// Comparisons /// \brief std::equal_to like comparator that returns \forcedlink{eq}(x, y) @@ -218,8 +220,8 @@ template struct hash { } }; -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_FUNCTORS_HPP diff --git a/include/boost/pfr/io.hpp b/include/boost/pfr/io.hpp index e5925b90..f254d949 100644 --- a/include/boost/pfr/io.hpp +++ b/include/boost/pfr/io.hpp @@ -9,6 +9,10 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include #include @@ -67,8 +71,6 @@ struct io_impl { T value; }; -BOOST_PFR_BEGIN_MODULE_EXPORT - template enable_not_ostreamable_t, T> operator<<(std::basic_ostream& out, io_impl&& x) { return out << boost::pfr::io_fields(std::forward(x.value)); @@ -89,12 +91,8 @@ enable_istreamable_t, T> operator>>(std::basic_ return in >> x.value; } -BOOST_PFR_END_MODULE_EXPORT - } // namespace detail -BOOST_PFR_BEGIN_MODULE_EXPORT - /// IO manipulator to read/write \aggregate `value` using its IO stream operators or using \forcedlink{io_fields} if operators are not available. /// /// \b Example: @@ -114,8 +112,8 @@ auto io(T&& value) noexcept { return detail::io_impl{std::forward(value)}; } -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_IO_HPP diff --git a/include/boost/pfr/io_fields.hpp b/include/boost/pfr/io_fields.hpp index f551ab88..6dbd4a4e 100644 --- a/include/boost/pfr/io_fields.hpp +++ b/include/boost/pfr/io_fields.hpp @@ -10,16 +10,23 @@ #include -#include - -#include -#include // metaprogramming stuff +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else +#include #include #include #include #include +#if defined(BOOST_USE_MODULES) +import std; +#else +#include +#include // metaprogramming stuff +#endif + /// \file boost/pfr/io_fields.hpp /// Contains IO manipulator \forcedlink{io_fields} to read/write any \aggregate field-by-field. /// @@ -118,8 +125,6 @@ std::basic_istream& operator>>(std::basic_istream& i return in; } -BOOST_PFR_BEGIN_MODULE_EXPORT - template std::basic_istream& operator>>(std::basic_istream& in, io_fields_impl&& ) { static_assert(sizeof(T) && false, "====================> Boost.PFR: Attempt to use istream operator on a boost::pfr::io_fields wrapped type T with const qualifier."); @@ -132,12 +137,8 @@ std::basic_istream& operator>>(std::basic_istream& i return in; } -BOOST_PFR_END_MODULE_EXPORT - } // namespace detail -BOOST_PFR_BEGIN_MODULE_EXPORT - /// IO manipulator to read/write \aggregate `value` field-by-field. /// /// \b Example: @@ -165,8 +166,8 @@ auto io_fields(T&& value) noexcept { return detail::io_fields_impl{std::forward(value)}; } -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_IO_FIELDS_HPP diff --git a/include/boost/pfr/ops.hpp b/include/boost/pfr/ops.hpp index 36271f40..afd87aee 100644 --- a/include/boost/pfr/ops.hpp +++ b/include/boost/pfr/ops.hpp @@ -9,6 +9,10 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include #include @@ -77,8 +81,6 @@ namespace detail { >; } // namespace detail -BOOST_PFR_BEGIN_MODULE_EXPORT - /// \brief Compares lhs and rhs for equality using their own comparison and conversion operators; if no operators available returns \forcedlink{eq_fields}(lhs, rhs). /// /// \returns true if lhs is equal to rhs; false otherwise @@ -183,8 +185,8 @@ constexpr detail::enable_hashable_t hash_value(const T& value) { return std::hash{}(value); } -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_OPS_HPP diff --git a/include/boost/pfr/ops_fields.hpp b/include/boost/pfr/ops_fields.hpp index d60c2e3c..8905cb2b 100644 --- a/include/boost/pfr/ops_fields.hpp +++ b/include/boost/pfr/ops_fields.hpp @@ -9,6 +9,10 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include #include @@ -33,8 +37,6 @@ /// \b Synopsis: namespace boost { namespace pfr { -BOOST_PFR_BEGIN_MODULE_EXPORT - /// Does a field-by-field equality comparison. /// /// \returns `L == R && tuple_size_v == tuple_size_v`, where `L` and @@ -125,8 +127,8 @@ BOOST_PFR_BEGIN_MODULE_EXPORT #endif } -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_OPS_HPP diff --git a/include/boost/pfr/traits.hpp b/include/boost/pfr/traits.hpp index 75f105f9..598e1abc 100644 --- a/include/boost/pfr/traits.hpp +++ b/include/boost/pfr/traits.hpp @@ -9,8 +9,17 @@ #include +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else + #include + +#if defined(BOOST_USE_MODULES) +import std; +#else #include +#endif /// \file boost/pfr/traits.hpp /// Contains traits \forcedlink{is_reflectable} and \forcedlink{is_implicitly_reflectable} for detecting an ability to reflect type. @@ -19,8 +28,6 @@ namespace boost { namespace pfr { -BOOST_PFR_BEGIN_MODULE_EXPORT - /// Has a static const member variable `value` when it is known that type T can or can't be reflected using Boost.PFR; otherwise, there is no member variable. /// Every user may (and in some difficult cases - should) specialize is_reflectable on his own. /// @@ -56,9 +63,9 @@ using is_implicitly_reflectable = std::integral_constant< bool, boost::pfr::deta template constexpr bool is_implicitly_reflectable_v = is_implicitly_reflectable::value; -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_TRAITS_HPP diff --git a/include/boost/pfr/traits_fwd.hpp b/include/boost/pfr/traits_fwd.hpp index 59148f18..1570b4b3 100644 --- a/include/boost/pfr/traits_fwd.hpp +++ b/include/boost/pfr/traits_fwd.hpp @@ -9,17 +9,19 @@ #include -namespace boost { namespace pfr { +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else -BOOST_PFR_BEGIN_MODULE_EXPORT +namespace boost { namespace pfr { template struct is_reflectable; -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_DETAIL_TRAITS_FWD_HPP diff --git a/include/boost/pfr/tuple_size.hpp b/include/boost/pfr/tuple_size.hpp index 8c6b949f..dbfef321 100644 --- a/include/boost/pfr/tuple_size.hpp +++ b/include/boost/pfr/tuple_size.hpp @@ -10,20 +10,26 @@ #include -#include -#include // metaprogramming stuff +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#else #include #include +#if defined(BOOST_USE_MODULES) +import std; +#else +#include +#include // metaprogramming stuff +#endif + /// \file boost/pfr/tuple_size.hpp /// Contains tuple-like interfaces to get fields count \forcedlink{tuple_size}, \forcedlink{tuple_size_v}. /// /// \b Synopsis: namespace boost { namespace pfr { -BOOST_PFR_BEGIN_MODULE_EXPORT - /// Has a static const member variable `value` that contains fields count in a T. /// Works for any T that satisfies \aggregate. /// @@ -45,8 +51,8 @@ using tuple_size = detail::size_t_< boost::pfr::detail::fields_count() >; template constexpr std::size_t tuple_size_v = tuple_size::value; -BOOST_PFR_END_MODULE_EXPORT - }} // namespace boost::pfr +#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) + #endif // BOOST_PFR_TUPLE_SIZE_HPP diff --git a/misc/generate_cpp17.py b/misc/generate_cpp17.py index 47869767..3ebbe311 100644 --- a/misc/generate_cpp17.py +++ b/misc/generate_cpp17.py @@ -39,7 +39,7 @@ #include #include -#ifdef BOOST_PFR_HAS_STD_MODULE +#if defined(BOOST_USE_MODULES) import std; #else #include // for std::conditional_t, std::is_reference diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt deleted file mode 100644 index a7a00c1e..00000000 --- a/module/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2016-2025 Antony Polukhin -# -# Distributed under the Boost Software License, Version 1.0. -# https://www.boost.org/LICENSE_1_0.txt - -cmake_minimum_required(VERSION 3.28) - -function (_add_boost_pfr_module_impl NAME) - add_library(${NAME}) - target_compile_features(${NAME} PUBLIC cxx_std_20) - target_sources(${NAME} PUBLIC - FILE_SET modules_public TYPE CXX_MODULES FILES - ${CMAKE_CURRENT_LIST_DIR}/pfr.cppm - ) -endfunction() - -function (add_boost_pfr_module NAME) - _add_boost_pfr_module_impl(${NAME}) - target_include_directories(${NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../include) - - _add_boost_pfr_module_impl(${NAME}_migration) - target_include_directories(${NAME}_migration PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../include) - target_compile_definitions(${NAME}_migration PRIVATE BOOST_PFR_ATTACH_TO_GLOBAL_MODULE) -endfunction() - -add_boost_pfr_module(boost_pfr_module) -add_library(Boost::pfr_module ALIAS boost_pfr_module) -add_library(Boost::pfr_module_migration ALIAS boost_pfr_module_migration) - -if (BUILD_TESTING) - add_executable(boost_pfr_module_usage usage_sample.cpp) - target_link_libraries(boost_pfr_module_usage PRIVATE Boost::pfr_module) - - # Make sure that mixing includes and imports is fine for different TU - add_executable(boost_pfr_module_usage_mu usage_test_mu1.cpp usage_test_mu2.cpp) - target_link_libraries(boost_pfr_module_usage_mu PRIVATE Boost::pfr_module_migration) -endif() diff --git a/module/pfr.cppm b/module/pfr.cppm deleted file mode 100644 index 60e94242..00000000 --- a/module/pfr.cppm +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2016-2025 Antony Polukhin -// -// 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) - -// To compile manually use a command like the folowing: -// clang++ -I ../include -std=c++20 --precompile -x c++-module pfr.cppm - -#define BOOST_PFR_BEGIN_MODULE_EXPORT export { -#define BOOST_PFR_END_MODULE_EXPORT } - -#ifndef BOOST_PFR_HAS_STD_MODULE -module; -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -export module Boost.PFR; - -#ifdef BOOST_PFR_HAS_STD_MODULE -import std; -#endif - -#ifdef __clang__ -# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" -#endif - -#ifdef BOOST_PFR_ATTACH_TO_GLOBAL_MODULE -extern "C++" { -#include -} -#else -#include -#endif diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 00000000..caded1a2 --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2016-2025 Antony Polukhin +# +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +cmake_minimum_required(VERSION 3.28) + +function (_add_boost_pfr_module NAME) +endfunction() + + diff --git a/modules/pfr.cppm b/modules/pfr.cppm new file mode 100644 index 00000000..e22b9899 --- /dev/null +++ b/modules/pfr.cppm @@ -0,0 +1,83 @@ +// Copyright (c) 2016-2025 Antony Polukhin +// +// 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) + +// To compile manually use a command like the folowing: +// clang++ -I ../include -std=c++20 --precompile -x c++-module pfr.cppm + +module; + +#define BOOST_PFR_INTERFACE_UNIT +#include + +export module boost.pfr; + +export namespace boost::pfr { + +// core.hpp +using pfr::get; +using pfr::tuple_element; +using pfr::tuple_element_t; +using pfr::structure_to_tuple; +using pfr::structure_tie; +using pfr::for_each_field; +using pfr::tie_from_structure; + +// core_name.hpp +using pfr::get_name; +using pfr::names_as_array; +using pfr::for_each_field_with_name; + +// functors.hpp +using pfr::equal_to; +using pfr::not_equal; +using pfr::greater; +using pfr::less; +using pfr::greater_equal; +using pfr::less_equal; +using pfr::hash; + +// io.hpp and io_fields.hpp +export namespace detail { + using detail::operator<<; + using detail::operator>>; +} // namespace detail +using pfr::io; +using pfr::io_fields; + +// ops.hpp +using pfr::eq; +using pfr::ne; +using pfr::lt; +using pfr::gt; +using pfr::le; +using pfr::ge; +using pfr::hash_value; + +// ops_fields.hpp +using pfr::eq_fields; +using pfr::ne_fields; +using pfr::lt_fields; +using pfr::gt_fields; +using pfr::le_fields; +using pfr::ge_fields; +using pfr::hash_fields; + +// traits.hpp +using pfr::is_reflectable; +using pfr::is_implicitly_reflectable; +using pfr::is_implicitly_reflectable_v; + +using pfr:: +using pfr:: +using pfr:: +using pfr:: +using pfr:: +using pfr:: +using pfr:: +using pfr:: +using pfr:: + + +} diff --git a/module/usage_sample.cpp b/modules/usage_sample.cpp similarity index 92% rename from module/usage_sample.cpp rename to modules/usage_sample.cpp index 8ad23846..c59b9984 100644 --- a/module/usage_sample.cpp +++ b/modules/usage_sample.cpp @@ -7,11 +7,8 @@ // clang++ -std=c++20 -fmodule-file=pfr.pcm pfr.pcm usage_sample.cpp //[pfr_module_example -#include -#include -#include - -import Boost.PFR; +import std; +import boost.pfr; struct some_person { std::string name; diff --git a/module/usage_test_mu1.cpp b/modules/usage_test_mu1.cpp similarity index 97% rename from module/usage_test_mu1.cpp rename to modules/usage_test_mu1.cpp index 21432da1..01ca1b8d 100644 --- a/module/usage_test_mu1.cpp +++ b/modules/usage_test_mu1.cpp @@ -6,10 +6,10 @@ // To compile manually use a command like the folowing: // clang++ -std=c++20 -fmodule-file=pfr.pcm pfr.pcm usage_sample.cpp -#include - #include +import std; + struct some_person { std::string name; unsigned birth_year; diff --git a/module/usage_test_mu2.cpp b/modules/usage_test_mu2.cpp similarity index 93% rename from module/usage_test_mu2.cpp rename to modules/usage_test_mu2.cpp index 175e2690..387a6306 100644 --- a/module/usage_test_mu2.cpp +++ b/modules/usage_test_mu2.cpp @@ -6,10 +6,8 @@ // To compile manually use a command like the folowing: // clang++ -std=c++20 -fmodule-file=pfr.pcm pfr.pcm usage_sample.cpp -#include -#include - -import Boost.PFR; +import std; +import boost.pfr; struct some_person { std::string name; From 3792637a879f2ffa63347175ea1fe94f7c7c8833 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 19:04:51 +0300 Subject: [PATCH 02/16] fixes and tests --- CMakeLists.txt | 13 ++++++++++--- include/boost/pfr/core.hpp | 2 +- include/boost/pfr/core_name.hpp | 2 +- include/boost/pfr/detail/core14_classic.hpp | 2 +- include/boost/pfr/detail/core14_loophole.hpp | 2 +- include/boost/pfr/detail/core17_generated.hpp | 2 +- .../boost/pfr/detail/core_name20_static.hpp | 2 +- include/boost/pfr/detail/detectors.hpp | 2 +- include/boost/pfr/detail/fields_count.hpp | 2 +- include/boost/pfr/detail/for_each_field.hpp | 2 +- .../boost/pfr/detail/for_each_field_impl.hpp | 2 +- include/boost/pfr/detail/functional.hpp | 2 +- include/boost/pfr/detail/io.hpp | 2 +- .../detail/make_flat_tuple_of_references.hpp | 2 +- .../boost/pfr/detail/make_integer_sequence.hpp | 2 +- .../boost/pfr/detail/offset_based_getter.hpp | 2 +- .../boost/pfr/detail/possible_reflectable.hpp | 2 +- include/boost/pfr/detail/rvalue_t.hpp | 2 +- include/boost/pfr/detail/sequence_tuple.hpp | 2 +- include/boost/pfr/detail/size_array.hpp | 2 +- include/boost/pfr/detail/size_t_.hpp | 2 +- include/boost/pfr/detail/stdarray.hpp | 2 +- include/boost/pfr/detail/stdtuple.hpp | 2 +- .../pfr/detail/tie_from_structure_tuple.hpp | 2 +- include/boost/pfr/detail/unsafe_declval.hpp | 2 +- include/boost/pfr/io_fields.hpp | 2 +- include/boost/pfr/traits.hpp | 2 +- include/boost/pfr/tuple_size.hpp | 2 +- modules/CMakeLists.txt | 11 ----------- modules/pfr.cppm | 15 ++++----------- modules/usage_sample.cpp | 5 ++++- modules/usage_test_mu1.cpp | 4 ++-- modules/usage_test_mu2.cpp | 4 +++- test/CMakeLists.txt | 18 ++++++++++++++++++ test/core/run/core17_generated.cpp | 2 +- test/core/run/error_pfr_c1202.cpp | 7 +++++++ test/core/run/get_const_field.cpp | 7 ++++++- test/core/run/is_implicitly_reflectable.cpp | 6 ++++++ test/core/run/template_constructor.cpp | 7 +++++++ test/core/run/template_forwarding_ref.cpp | 7 +++++++ test/core/run/template_unconstrained.cpp | 7 +++++++ 41 files changed, 109 insertions(+), 58 deletions(-) delete mode 100644 modules/CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a55b81e6..577bfcf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,13 +9,17 @@ cmake_minimum_required(VERSION 3.5...3.31) project(boost_pfr VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) - add_library(boost_pfr STATIC) - target_compile_features(boost_pfr PUBLIC cxx_std_23) + add_library(boost_pfr) + target_compile_features(boost_pfr PUBLIC cxx_std_20) target_sources(boost_pfr PUBLIC FILE_SET modules_public TYPE CXX_MODULES FILES ${CMAKE_CURRENT_LIST_DIR}/modules/pfr.cppm ) - set_target_properties(boost_pfr PROPERTIES CXX_MODULE_STD 1) + if (CXX_MODULE_STD) + target_compile_definitions(boost_pfr PUBLIC BOOST_USE_STD_MODULE) + target_compile_features(boost_pfr PUBLIC cxx_std_23) + endif() + target_compile_definitions(boost_pfr PUBLIC BOOST_USE_MODULES) target_include_directories(boost_pfr PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) else() @@ -25,6 +29,7 @@ endif() add_library(Boost::pfr ALIAS boost_pfr) +enable_testing() if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") add_subdirectory(test) endif() @@ -32,9 +37,11 @@ endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES AND BUILD_TESTING) add_executable(boost_pfr_module_usage modules/usage_sample.cpp) target_link_libraries(boost_pfr_module_usage PRIVATE Boost::pfr) + add_test(NAME boost_pfr_module_usage COMMAND boost_pfr_module_usage) # Make sure that mixing includes and imports is fine for different TU add_executable(boost_pfr_module_usage_mu modules/usage_test_mu1.cpp modules/usage_test_mu2.cpp) target_link_libraries(boost_pfr_module_usage_mu PRIVATE Boost::pfr) + add_test(NAME boost_pfr_module_usage_mu COMMAND boost_pfr_module_usage_mu) endif() diff --git a/include/boost/pfr/core.hpp b/include/boost/pfr/core.hpp index ce0803db..94d9bfc4 100644 --- a/include/boost/pfr/core.hpp +++ b/include/boost/pfr/core.hpp @@ -23,7 +23,7 @@ import boost.pfr; #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/core_name.hpp b/include/boost/pfr/core_name.hpp index 277632f4..a2599011 100644 --- a/include/boost/pfr/core_name.hpp +++ b/include/boost/pfr/core_name.hpp @@ -26,7 +26,7 @@ import boost.pfr; #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // for std::size_t diff --git a/include/boost/pfr/detail/core14_classic.hpp b/include/boost/pfr/detail/core14_classic.hpp index 789738ff..600270d5 100644 --- a/include/boost/pfr/detail/core14_classic.hpp +++ b/include/boost/pfr/detail/core14_classic.hpp @@ -18,7 +18,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/core14_loophole.hpp b/include/boost/pfr/detail/core14_loophole.hpp index 2990fa58..5471633c 100644 --- a/include/boost/pfr/detail/core14_loophole.hpp +++ b/include/boost/pfr/detail/core14_loophole.hpp @@ -24,7 +24,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/core17_generated.hpp b/include/boost/pfr/detail/core17_generated.hpp index 8c9a2a61..b4c0b992 100644 --- a/include/boost/pfr/detail/core17_generated.hpp +++ b/include/boost/pfr/detail/core17_generated.hpp @@ -22,7 +22,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // for std::conditional_t, std::is_reference diff --git a/include/boost/pfr/detail/core_name20_static.hpp b/include/boost/pfr/detail/core_name20_static.hpp index 3f3c5a62..753d6cbb 100644 --- a/include/boost/pfr/detail/core_name20_static.hpp +++ b/include/boost/pfr/detail/core_name20_static.hpp @@ -22,7 +22,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/detectors.hpp b/include/boost/pfr/detail/detectors.hpp index a3a19344..10e10ee8 100644 --- a/include/boost/pfr/detail/detectors.hpp +++ b/include/boost/pfr/detail/detectors.hpp @@ -9,7 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/fields_count.hpp b/include/boost/pfr/detail/fields_count.hpp index 11f1f969..2271c424 100644 --- a/include/boost/pfr/detail/fields_count.hpp +++ b/include/boost/pfr/detail/fields_count.hpp @@ -12,7 +12,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // CHAR_BIT diff --git a/include/boost/pfr/detail/for_each_field.hpp b/include/boost/pfr/detail/for_each_field.hpp index 810f7014..79182d0d 100644 --- a/include/boost/pfr/detail/for_each_field.hpp +++ b/include/boost/pfr/detail/for_each_field.hpp @@ -14,7 +14,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/for_each_field_impl.hpp b/include/boost/pfr/detail/for_each_field_impl.hpp index 3686fbfb..9922c556 100644 --- a/include/boost/pfr/detail/for_each_field_impl.hpp +++ b/include/boost/pfr/detail/for_each_field_impl.hpp @@ -12,7 +12,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/functional.hpp b/include/boost/pfr/detail/functional.hpp index 75a7a189..3d82ad06 100644 --- a/include/boost/pfr/detail/functional.hpp +++ b/include/boost/pfr/detail/functional.hpp @@ -11,7 +11,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/io.hpp b/include/boost/pfr/detail/io.hpp index 90b72659..b70903df 100644 --- a/include/boost/pfr/detail/io.hpp +++ b/include/boost/pfr/detail/io.hpp @@ -11,7 +11,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // stream operators diff --git a/include/boost/pfr/detail/make_flat_tuple_of_references.hpp b/include/boost/pfr/detail/make_flat_tuple_of_references.hpp index 55928e50..2d7dc7a9 100644 --- a/include/boost/pfr/detail/make_flat_tuple_of_references.hpp +++ b/include/boost/pfr/detail/make_flat_tuple_of_references.hpp @@ -13,7 +13,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/make_integer_sequence.hpp b/include/boost/pfr/detail/make_integer_sequence.hpp index f1c0b99b..2cfce437 100644 --- a/include/boost/pfr/detail/make_integer_sequence.hpp +++ b/include/boost/pfr/detail/make_integer_sequence.hpp @@ -10,7 +10,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/offset_based_getter.hpp b/include/boost/pfr/detail/offset_based_getter.hpp index 9c3f2f2c..7cfe658b 100644 --- a/include/boost/pfr/detail/offset_based_getter.hpp +++ b/include/boost/pfr/detail/offset_based_getter.hpp @@ -14,7 +14,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/possible_reflectable.hpp b/include/boost/pfr/detail/possible_reflectable.hpp index 990adeb5..7d69b868 100644 --- a/include/boost/pfr/detail/possible_reflectable.hpp +++ b/include/boost/pfr/detail/possible_reflectable.hpp @@ -10,7 +10,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // for std::is_aggregate diff --git a/include/boost/pfr/detail/rvalue_t.hpp b/include/boost/pfr/detail/rvalue_t.hpp index ede795bf..8318ba3a 100644 --- a/include/boost/pfr/detail/rvalue_t.hpp +++ b/include/boost/pfr/detail/rvalue_t.hpp @@ -7,7 +7,7 @@ #define BOOST_PFR_DETAIL_RVALUE_T_HPP #pragma once -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/sequence_tuple.hpp b/include/boost/pfr/detail/sequence_tuple.hpp index 8814bd01..fb9e9b59 100644 --- a/include/boost/pfr/detail/sequence_tuple.hpp +++ b/include/boost/pfr/detail/sequence_tuple.hpp @@ -10,7 +10,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/size_array.hpp b/include/boost/pfr/detail/size_array.hpp index eb33083e..67825143 100644 --- a/include/boost/pfr/detail/size_array.hpp +++ b/include/boost/pfr/detail/size_array.hpp @@ -9,7 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/size_t_.hpp b/include/boost/pfr/detail/size_t_.hpp index b6dc82fb..c8ece609 100644 --- a/include/boost/pfr/detail/size_t_.hpp +++ b/include/boost/pfr/detail/size_t_.hpp @@ -7,7 +7,7 @@ #define BOOST_PFR_DETAIL_SIZE_T_HPP #pragma once -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/stdarray.hpp b/include/boost/pfr/detail/stdarray.hpp index dc2452d1..8af927a4 100644 --- a/include/boost/pfr/detail/stdarray.hpp +++ b/include/boost/pfr/detail/stdarray.hpp @@ -11,7 +11,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/stdtuple.hpp b/include/boost/pfr/detail/stdtuple.hpp index c4183071..7501ccbf 100644 --- a/include/boost/pfr/detail/stdtuple.hpp +++ b/include/boost/pfr/detail/stdtuple.hpp @@ -11,7 +11,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/tie_from_structure_tuple.hpp b/include/boost/pfr/detail/tie_from_structure_tuple.hpp index ae75b394..e829dc04 100644 --- a/include/boost/pfr/detail/tie_from_structure_tuple.hpp +++ b/include/boost/pfr/detail/tie_from_structure_tuple.hpp @@ -16,7 +16,7 @@ #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/detail/unsafe_declval.hpp b/include/boost/pfr/detail/unsafe_declval.hpp index 3cb0a8ee..dd040689 100644 --- a/include/boost/pfr/detail/unsafe_declval.hpp +++ b/include/boost/pfr/detail/unsafe_declval.hpp @@ -9,7 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/io_fields.hpp b/include/boost/pfr/io_fields.hpp index 6dbd4a4e..eb419651 100644 --- a/include/boost/pfr/io_fields.hpp +++ b/include/boost/pfr/io_fields.hpp @@ -20,7 +20,7 @@ import boost.pfr; #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/traits.hpp b/include/boost/pfr/traits.hpp index 598e1abc..163b8141 100644 --- a/include/boost/pfr/traits.hpp +++ b/include/boost/pfr/traits.hpp @@ -15,7 +15,7 @@ import boost.pfr; #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/include/boost/pfr/tuple_size.hpp b/include/boost/pfr/tuple_size.hpp index dbfef321..e84718a0 100644 --- a/include/boost/pfr/tuple_size.hpp +++ b/include/boost/pfr/tuple_size.hpp @@ -17,7 +17,7 @@ import boost.pfr; #include #include -#if defined(BOOST_USE_MODULES) +#if defined(BOOST_USE_STD_MODULE) import std; #else #include diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt deleted file mode 100644 index caded1a2..00000000 --- a/modules/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) 2016-2025 Antony Polukhin -# -# Distributed under the Boost Software License, Version 1.0. -# https://www.boost.org/LICENSE_1_0.txt - -cmake_minimum_required(VERSION 3.28) - -function (_add_boost_pfr_module NAME) -endfunction() - - diff --git a/modules/pfr.cppm b/modules/pfr.cppm index e22b9899..02fbcaf0 100644 --- a/modules/pfr.cppm +++ b/modules/pfr.cppm @@ -39,7 +39,7 @@ using pfr::less_equal; using pfr::hash; // io.hpp and io_fields.hpp -export namespace detail { +namespace detail { using detail::operator<<; using detail::operator>>; } // namespace detail @@ -69,15 +69,8 @@ using pfr::is_reflectable; using pfr::is_implicitly_reflectable; using pfr::is_implicitly_reflectable_v; -using pfr:: -using pfr:: -using pfr:: -using pfr:: -using pfr:: -using pfr:: -using pfr:: -using pfr:: -using pfr:: - +// tuple_size.hpp +using pfr::tuple_size; +using pfr::tuple_size_v; } diff --git a/modules/usage_sample.cpp b/modules/usage_sample.cpp index c59b9984..5d6b3c18 100644 --- a/modules/usage_sample.cpp +++ b/modules/usage_sample.cpp @@ -7,7 +7,10 @@ // clang++ -std=c++20 -fmodule-file=pfr.pcm pfr.pcm usage_sample.cpp //[pfr_module_example -import std; +#include +#include +#include + import boost.pfr; struct some_person { diff --git a/modules/usage_test_mu1.cpp b/modules/usage_test_mu1.cpp index 01ca1b8d..21432da1 100644 --- a/modules/usage_test_mu1.cpp +++ b/modules/usage_test_mu1.cpp @@ -6,9 +6,9 @@ // To compile manually use a command like the folowing: // clang++ -std=c++20 -fmodule-file=pfr.pcm pfr.pcm usage_sample.cpp -#include +#include -import std; +#include struct some_person { std::string name; diff --git a/modules/usage_test_mu2.cpp b/modules/usage_test_mu2.cpp index 387a6306..7ef07c64 100644 --- a/modules/usage_test_mu2.cpp +++ b/modules/usage_test_mu2.cpp @@ -6,7 +6,9 @@ // To compile manually use a command like the folowing: // clang++ -std=c++20 -fmodule-file=pfr.pcm pfr.pcm usage_sample.cpp -import std; +#include +#include + import boost.pfr; struct some_person { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..1238f9b3 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2016-2025 Antony Polukhin +# 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 + +# Does not work +#include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) +#if(NOT HAVE_BOOST_TEST) +# return() +#endif() + +file(GLOB CORE_RUN_FILES "core/run/*.cpp") + +foreach (testsourcefile ${CORE_RUN_FILES}) + get_filename_component(testname ${testsourcefile} NAME_WLE) + add_executable(pfr_core_${testname} ${testsourcefile}) + target_link_libraries(pfr_core_${testname} Boost::pfr) + add_test(NAME pfr_core_${testname} COMMAND pfr_core_${testname}) +endforeach() diff --git a/test/core/run/core17_generated.cpp b/test/core/run/core17_generated.cpp index 3dd3845d..6ee57a2a 100644 --- a/test/core/run/core17_generated.cpp +++ b/test/core/run/core17_generated.cpp @@ -24,7 +24,7 @@ struct A { }; int main() { -#if BOOST_PFR_USE_CPP17 +#if defined(BOOST_PFR_USE_CPP17) && !defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES const volatile int cv_value = 0; volatile int v_value = 0; const int c_value = 0; diff --git a/test/core/run/error_pfr_c1202.cpp b/test/core/run/error_pfr_c1202.cpp index 0041a13f..8efafcf9 100644 --- a/test/core/run/error_pfr_c1202.cpp +++ b/test/core/run/error_pfr_c1202.cpp @@ -13,6 +13,11 @@ #include #include +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else + template class CfgAttrib { public: @@ -99,3 +104,5 @@ int main() { boost::pfr::get<0>(aCfg); // also C1202 #endif } + +#endif diff --git a/test/core/run/get_const_field.cpp b/test/core/run/get_const_field.cpp index cb1cce6c..28007d67 100644 --- a/test/core/run/get_const_field.cpp +++ b/test/core/run/get_const_field.cpp @@ -10,6 +10,11 @@ #include +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else + namespace testing { namespace { @@ -52,4 +57,4 @@ int main() { return boost::report_errors(); } - +#endif diff --git a/test/core/run/is_implicitly_reflectable.cpp b/test/core/run/is_implicitly_reflectable.cpp index 38ff816e..0dc9879a 100644 --- a/test/core/run/is_implicitly_reflectable.cpp +++ b/test/core/run/is_implicitly_reflectable.cpp @@ -7,6 +7,10 @@ #include #include // for std::true_type, std::false_type and std::is_aggregate +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else namespace boost { namespace pfr { struct boost_fusion_tag; struct boost_json_tag; @@ -81,3 +85,5 @@ int main() { #endif // #if BOOST_PFR_ENABLE_IMPLICIT_REFLECTION } +#endif + diff --git a/test/core/run/template_constructor.cpp b/test/core/run/template_constructor.cpp index 2aea08ad..b3ba3004 100644 --- a/test/core/run/template_constructor.cpp +++ b/test/core/run/template_constructor.cpp @@ -7,6 +7,11 @@ #include +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else + template struct constrained_template { constrained_template() = default; @@ -54,3 +59,5 @@ int main() { aggregate_constrained aggr{s, 4}; return boost::pfr::get<1>(aggr).value_.value_ - 4; } + +#endif diff --git a/test/core/run/template_forwarding_ref.cpp b/test/core/run/template_forwarding_ref.cpp index fcb0a00f..3ea8d0e9 100644 --- a/test/core/run/template_forwarding_ref.cpp +++ b/test/core/run/template_forwarding_ref.cpp @@ -7,6 +7,11 @@ #include +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else + template struct unconstrained_forwarding_ref { unconstrained_forwarding_ref() = default; @@ -67,3 +72,5 @@ int main() { aggregate_unconstrained aggr{3, 4}; return boost::pfr::get<1>(aggr).value_.value_ - 4; } + +#endif diff --git a/test/core/run/template_unconstrained.cpp b/test/core/run/template_unconstrained.cpp index 047741a4..d09fecbd 100644 --- a/test/core/run/template_unconstrained.cpp +++ b/test/core/run/template_unconstrained.cpp @@ -7,6 +7,11 @@ #include +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else + template struct unconstrained_template { unconstrained_template() = default; @@ -67,3 +72,5 @@ int main() { aggregate_unconstrained aggr{3, 4}; return boost::pfr::get<1>(aggr).value_.value_ - 4; } + +#endif From 56a0f2dfd2f4571c18465071f3825688a2f190ef Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 19:16:18 +0300 Subject: [PATCH 03/16] fix --- include/boost/pfr/config.hpp | 2 +- test/CMakeLists.txt | 9 ++++++++- test/core_name/run/fields_names_internal_parser.cpp | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/boost/pfr/config.hpp b/include/boost/pfr/config.hpp index 8db4b75c..63109edf 100644 --- a/include/boost/pfr/config.hpp +++ b/include/boost/pfr/config.hpp @@ -8,7 +8,7 @@ #define BOOST_PFR_CONFIG_HPP #pragma once -#if !defined(BOOST_USE_MODULES) +#if !defined(BOOST_USE_MODULES) && (__cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900)) #include // to get non standard platform macro definitions (__GLIBCXX__ for example) #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1238f9b3..688336a2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,10 +9,17 @@ #endif() file(GLOB CORE_RUN_FILES "core/run/*.cpp") - foreach (testsourcefile ${CORE_RUN_FILES}) get_filename_component(testname ${testsourcefile} NAME_WLE) add_executable(pfr_core_${testname} ${testsourcefile}) target_link_libraries(pfr_core_${testname} Boost::pfr) add_test(NAME pfr_core_${testname} COMMAND pfr_core_${testname}) endforeach() + +file(GLOB CORE_NAME_RUN_FILES "core_name/run/*.cpp") +foreach (testsourcefile ${CORE_NAME_RUN_FILES}) + get_filename_component(testname ${testsourcefile} NAME_WLE) + add_executable(pfr_corename_${testname} ${testsourcefile}) + target_link_libraries(pfr_corename_${testname} Boost::pfr) + add_test(NAME pfr_corename_${testname} COMMAND pfr_corename_${testname}) +endforeach() diff --git a/test/core_name/run/fields_names_internal_parser.cpp b/test/core_name/run/fields_names_internal_parser.cpp index c53fbd28..f06ed073 100644 --- a/test/core_name/run/fields_names_internal_parser.cpp +++ b/test/core_name/run/fields_names_internal_parser.cpp @@ -13,6 +13,11 @@ #include +#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +int main() {} + +#else + namespace testing { constexpr std::string_view fake_func_name = " ******************** [fake_text1->fake_text2->fake_text3] **********"; @@ -45,3 +50,5 @@ int main() { return boost::report_errors(); } +#endif + From 709a25df11ef8f62859eaedb61765fb5bccb1900 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 19:25:19 +0300 Subject: [PATCH 04/16] fix --- .github/workflows/ci.yml | 12 ++++++++++++ test/core/run/core17_generated.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1c04728..d4870dff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,9 @@ jobs: - toolset: clang-15 cxxstd: "03,11,14,17,20" os: ubuntu-22.04 + - toolset: clang-19 + cxxstd: "20,23" + os: ubuntu-24.04 # - toolset: clang # cxxstd: "03,11,14,17,2a" # os: macos-10.15 @@ -87,6 +90,15 @@ jobs: ./b2 -d0 headers ./b2 variant=debug tools/inspect/build + - name: Run modules tests + if: ${{matrix.toolset == 'clang-19'}} + run: | + cd ../boost-root/libs/pfr + mkdir build_module + cd build_module + cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 .. + cmake --build . && ctest -V + - name: Run tests run: | cd ../boost-root diff --git a/test/core/run/core17_generated.cpp b/test/core/run/core17_generated.cpp index 6ee57a2a..92ca910f 100644 --- a/test/core/run/core17_generated.cpp +++ b/test/core/run/core17_generated.cpp @@ -24,7 +24,7 @@ struct A { }; int main() { -#if defined(BOOST_PFR_USE_CPP17) && !defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES +#if BOOST_PFR_USE_CPP17 && !defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES const volatile int cv_value = 0; volatile int v_value = 0; const int c_value = 0; From 6be268d8b9c019a2846e2420fe4f50db5140aeee Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 19:30:26 +0300 Subject: [PATCH 05/16] more fixes --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4870dff..40bf7037 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,7 @@ jobs: - toolset: clang-19 cxxstd: "20,23" os: ubuntu-24.04 + install: clang-19 llvm-19-tools # - toolset: clang # cxxstd: "03,11,14,17,2a" # os: macos-10.15 From 8971c38567647bf56eeb5c79e9a5240183e4336b Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 19:40:16 +0300 Subject: [PATCH 06/16] CI fixes --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40bf7037..0dff45f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - toolset: clang-19 cxxstd: "20,23" os: ubuntu-24.04 - install: clang-19 llvm-19-tools + install: clang-19 clang-tools-19 # - toolset: clang # cxxstd: "03,11,14,17,2a" # os: macos-10.15 diff --git a/CMakeLists.txt b/CMakeLists.txt index 577bfcf7..b5adbc3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) ) if (CXX_MODULE_STD) target_compile_definitions(boost_pfr PUBLIC BOOST_USE_STD_MODULE) - target_compile_features(boost_pfr PUBLIC cxx_std_23) + target_compile_features(boost_pfr PUBLIC cxx_std_23) endif() target_compile_definitions(boost_pfr PUBLIC BOOST_USE_MODULES) @@ -31,7 +31,7 @@ add_library(Boost::pfr ALIAS boost_pfr) enable_testing() if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") - add_subdirectory(test) + add_subdirectory(test) endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES AND BUILD_TESTING) From 0c8d6e4a8ea389ddcb42ba6c47364d5590876bd4 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 20:10:49 +0300 Subject: [PATCH 07/16] fix attempt --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0dff45f4..848a41de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: cd ../boost-root/libs/pfr mkdir build_module cd build_module - cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 .. + cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-I../../../ .. cmake --build . && ctest -V - name: Run tests From 282f64532b2b4b6bc1a7e6f533e1af9bf20e1473 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 7 Apr 2025 20:22:50 +0300 Subject: [PATCH 08/16] CI fixes --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 848a41de..6d040e0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,6 +99,8 @@ jobs: cd build_module cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-I../../../ .. cmake --build . && ctest -V + cd .. + rm -rf build_module - name: Run tests run: | From b120be8567b28733c7b59a71f17e3212ef66d077 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 10 Apr 2025 17:41:40 +0300 Subject: [PATCH 09/16] Review fixes (more to come) --- .github/workflows/ci.yml | 12 ++++++++++++ CMakeLists.txt | 4 ++-- doc/pfr.qbk | 16 ++++++++-------- include/boost/pfr/config.hpp | 2 ++ include/boost/pfr/detail/fields_count.hpp | 8 ++++---- include/boost/pfr/detail/functional.hpp | 3 ++- .../boost/pfr/detail/possible_reflectable.hpp | 1 + 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d040e0e..9dbeb239 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -192,6 +192,18 @@ jobs: cmd /c bootstrap b2 -d0 headers + - name: Run modules tests + if: ${{matrix.toolset == 'msvc-14.3'}} + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/libs/pfr + mkdir build_module + cd build_module + cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja -DCMAKE_CXX_FLAGS=-I../../../ .. + cmake --build . && ctest --no-tests=error -V + cd .. + rm -rf build_module + - name: Run tests shell: cmd run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index b5adbc3a..66f4bd93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,10 +21,10 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) endif() target_compile_definitions(boost_pfr PUBLIC BOOST_USE_MODULES) - target_include_directories(boost_pfr PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) + target_include_directories(boost_pfr PUBLIC include) else() add_library(boost_pfr INTERFACE) - target_include_directories(boost_pfr INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include) + target_include_directories(boost_pfr INTERFACE include) endif() add_library(Boost::pfr ALIAS boost_pfr) diff --git a/doc/pfr.qbk b/doc/pfr.qbk index 88d10282..db0d8f34 100644 --- a/doc/pfr.qbk +++ b/doc/pfr.qbk @@ -556,20 +556,20 @@ parameters provided to `BOOST_PFR_CORE_NAME_PARSING` macro [*and] the initial ou [caution C++20 PFR module support is on early stage, targets and flags may change in the future] -If using CMake of version 3.28.0 or higher define CMake option `-DBUILD_MODULE=1` -to make the `Boost::pfr_module` and `Boost::pfr_module_migration` libraries -available. With `Boost::pfr_module` C++20 module Boost.PFR could be used: +If using CMake of version 3.28.0 or higher define CMake option `-DBOOST_USE_MODULES=1` +to make the `Boost::pfr` target build C++20 module. After that an explicit usage of C++20 module `boost.pfr` is allowed: [import ../module/usage_sample.cpp] [pfr_module_example] -The `Boost::pfr_module_migration` CMake target gives an ability to -mix includes and imports of the PFR library in different translation units. +The `Boost::pfr` CMake target gives an ability to +mix includes and imports of the PFR library in different translation units. Moreover, +if `BOOST_USE_MODULES` macro is defined then all the `boost/pfr/...` includes +implicilty do `import boost.pfr;` to give all the benifits of modules without +changing the code base. If not using CMake, then the module could be build manually from the -`module/pfr.cppm` file. If mixing of includes in imports is desired, additionally -define `BOOST_PFR_ATTACH_TO_GLOBAL_MODULE` preprocessor macro to attach all the -module entities to a global module and avoid ODR issues. +`module/pfr.cppm` file. For manual module build the following commands could be used for clang compiler: diff --git a/include/boost/pfr/config.hpp b/include/boost/pfr/config.hpp index 63109edf..555abce2 100644 --- a/include/boost/pfr/config.hpp +++ b/include/boost/pfr/config.hpp @@ -10,6 +10,8 @@ #if !defined(BOOST_USE_MODULES) && (__cplusplus >= 201402L || (defined(_MSC_VER) && defined(_MSVC_LANG) && _MSC_VER > 1900)) #include // to get non standard platform macro definitions (__GLIBCXX__ for example) +#elif defined(BOOST_USE_MODULES) +#include #endif /// \file boost/pfr/config.hpp diff --git a/include/boost/pfr/detail/fields_count.hpp b/include/boost/pfr/detail/fields_count.hpp index 2271c424..afe06fe3 100644 --- a/include/boost/pfr/detail/fields_count.hpp +++ b/include/boost/pfr/detail/fields_count.hpp @@ -13,10 +13,10 @@ #include #if defined(BOOST_USE_STD_MODULE) +#include import std; #else -#include // CHAR_BIT -#include // SIZE_MAX +#include #include #include // metaprogramming stuff #endif @@ -218,13 +218,13 @@ constexpr std::size_t fields_count_compiler_limitation_next(std::size_t n) noexc #else static_cast(n); #endif - return SIZE_MAX; + return (std::numeric_limits::max)(); } ///////////////////// Fields count upper bound based on sizeof(T) template constexpr std::size_t fields_count_upper_bound_loose() noexcept { - return sizeof(T) * CHAR_BIT; + return sizeof(T) * std::numeric_limits::digits; } ///////////////////// Fields count binary search. diff --git a/include/boost/pfr/detail/functional.hpp b/include/boost/pfr/detail/functional.hpp index 3d82ad06..67438ce3 100644 --- a/include/boost/pfr/detail/functional.hpp +++ b/include/boost/pfr/detail/functional.hpp @@ -11,11 +11,12 @@ #include +#include + #if defined(BOOST_USE_STD_MODULE) import std; #else #include -#include #endif namespace boost { namespace pfr { namespace detail { diff --git a/include/boost/pfr/detail/possible_reflectable.hpp b/include/boost/pfr/detail/possible_reflectable.hpp index 7d69b868..8b790b9f 100644 --- a/include/boost/pfr/detail/possible_reflectable.hpp +++ b/include/boost/pfr/detail/possible_reflectable.hpp @@ -11,6 +11,7 @@ #include #if defined(BOOST_USE_STD_MODULE) +#include import std; #else #include // for std::is_aggregate From d3b3904e4d4b4e114b5f956153f20b4ae1757a60 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 10 Apr 2025 17:56:40 +0300 Subject: [PATCH 10/16] CI fixes --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9dbeb239..cac496b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,7 +194,9 @@ jobs: - name: Run modules tests if: ${{matrix.toolset == 'msvc-14.3'}} + shell: cmd run: | + choco install --no-progress ninja call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 cd ../boost-root/libs/pfr mkdir build_module From 34a98909b1dffedbd98cef5d7059eac4e21d210a Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 14 Apr 2025 14:46:33 +0300 Subject: [PATCH 11/16] Attempt to reduce boilerplate --- .github/workflows/ci.yml | 11 ++++++++++ CMakeLists.txt | 12 +++++----- include/boost/pfr/config.hpp | 4 ++++ include/boost/pfr/core.hpp | 10 +++------ include/boost/pfr/core_name.hpp | 10 +++------ include/boost/pfr/detail/core14_classic.hpp | 5 +---- include/boost/pfr/detail/core14_loophole.hpp | 10 +++------ include/boost/pfr/detail/core17_generated.hpp | 4 +--- .../boost/pfr/detail/core_name20_static.hpp | 4 +--- include/boost/pfr/detail/detectors.hpp | 4 +--- include/boost/pfr/detail/fields_count.hpp | 5 +---- include/boost/pfr/detail/for_each_field.hpp | 4 +--- .../boost/pfr/detail/for_each_field_impl.hpp | 4 +--- include/boost/pfr/detail/functional.hpp | 5 +---- include/boost/pfr/detail/io.hpp | 4 +--- .../detail/make_flat_tuple_of_references.hpp | 4 +--- .../pfr/detail/make_integer_sequence.hpp | 4 +--- .../boost/pfr/detail/offset_based_getter.hpp | 4 +--- .../boost/pfr/detail/possible_reflectable.hpp | 5 +---- include/boost/pfr/detail/rvalue_t.hpp | 4 +--- include/boost/pfr/detail/sequence_tuple.hpp | 4 +--- include/boost/pfr/detail/size_array.hpp | 4 +--- include/boost/pfr/detail/size_t_.hpp | 4 +--- include/boost/pfr/detail/stdarray.hpp | 4 +--- include/boost/pfr/detail/stdtuple.hpp | 4 +--- .../pfr/detail/tie_from_structure_tuple.hpp | 4 +--- include/boost/pfr/detail/unsafe_declval.hpp | 4 +--- include/boost/pfr/functions_for.hpp | 6 ++--- include/boost/pfr/functors.hpp | 6 ++--- include/boost/pfr/io.hpp | 6 ++--- include/boost/pfr/io_fields.hpp | 10 +++------ include/boost/pfr/ops.hpp | 6 ++--- include/boost/pfr/ops_fields.hpp | 6 ++--- include/boost/pfr/traits.hpp | 10 +++------ include/boost/pfr/traits_fwd.hpp | 7 ++---- include/boost/pfr/tuple_size.hpp | 8 ++----- misc/generate_cpp17.py | 4 +--- modules/pfr.cppm | 22 +++++++++++++++++++ test/CMakeLists.txt | 6 ----- 39 files changed, 95 insertions(+), 147 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cac496b8..2370cea0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,17 @@ jobs: ./b2 variant=debug tools/inspect/build - name: Run modules tests + if: ${{matrix.toolset == 'clang-19'}} + run: | + cd ../boost-root/libs/pfr + mkdir build_module + cd build_module + cmake -DBUILD_TESTING=1 -DCMAKE_CXX_FLAGS=-I../../../ -DBOOST_USE_MODULES=1 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + cmake --build . && ctest -V + cd .. + rm -rf build_module + + - name: Run modules tests wihtout 'import std;' if: ${{matrix.toolset == 'clang-19'}} run: | cd ../boost-root/libs/pfr diff --git a/CMakeLists.txt b/CMakeLists.txt index 66f4bd93..eac06ce0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,17 +10,19 @@ project(boost_pfr VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) add_library(boost_pfr) - target_compile_features(boost_pfr PUBLIC cxx_std_20) target_sources(boost_pfr PUBLIC FILE_SET modules_public TYPE CXX_MODULES FILES ${CMAKE_CURRENT_LIST_DIR}/modules/pfr.cppm ) - if (CXX_MODULE_STD) - target_compile_definitions(boost_pfr PUBLIC BOOST_USE_STD_MODULE) - target_compile_features(boost_pfr PUBLIC cxx_std_23) - endif() + target_compile_features(boost_pfr PUBLIC cxx_std_20) target_compile_definitions(boost_pfr PUBLIC BOOST_USE_MODULES) + if (CMAKE_CXX_COMPILER_IMPORT_STD) + target_compile_definitions(boost_pfr PRIVATE BOOST_PFR_USE_STD_MODULE) + message(STATUS "Using `import std;`") + else() + message(STATUS "`import std;` is not awailable") + endif() target_include_directories(boost_pfr PUBLIC include) else() add_library(boost_pfr INTERFACE) diff --git a/include/boost/pfr/config.hpp b/include/boost/pfr/config.hpp index 555abce2..607fedee 100644 --- a/include/boost/pfr/config.hpp +++ b/include/boost/pfr/config.hpp @@ -149,4 +149,8 @@ #undef BOOST_PFR_NOT_SUPPORTED +#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +import boost.pfr; +#endif + #endif // BOOST_PFR_CONFIG_HPP diff --git a/include/boost/pfr/core.hpp b/include/boost/pfr/core.hpp index 94d9bfc4..a79d0649 100644 --- a/include/boost/pfr/core.hpp +++ b/include/boost/pfr/core.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include @@ -23,9 +21,7 @@ import boost.pfr; #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include // metaprogramming stuff #endif @@ -253,6 +249,6 @@ constexpr detail::tie_from_structure_tuple tie_from_structure(Eleme }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_CORE_HPP diff --git a/include/boost/pfr/core_name.hpp b/include/boost/pfr/core_name.hpp index a2599011..ed11affe 100644 --- a/include/boost/pfr/core_name.hpp +++ b/include/boost/pfr/core_name.hpp @@ -14,9 +14,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include @@ -26,9 +24,7 @@ import boost.pfr; #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // for std::size_t #endif @@ -114,6 +110,6 @@ constexpr void for_each_field_with_name(T&& value, F&& func) { }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_CORE_NAME_HPP diff --git a/include/boost/pfr/detail/core14_classic.hpp b/include/boost/pfr/detail/core14_classic.hpp index 600270d5..7d50f1e3 100644 --- a/include/boost/pfr/detail/core14_classic.hpp +++ b/include/boost/pfr/detail/core14_classic.hpp @@ -18,10 +18,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else -#include +#if !defined(BOOST_PFR_INTERFACE_UNIT)#include #include // metaprogramming stuff #endif diff --git a/include/boost/pfr/detail/core14_loophole.hpp b/include/boost/pfr/detail/core14_loophole.hpp index 5471633c..8358397d 100644 --- a/include/boost/pfr/detail/core14_loophole.hpp +++ b/include/boost/pfr/detail/core14_loophole.hpp @@ -24,13 +24,6 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else -#include -#include -#endif - #include #include #include @@ -39,6 +32,9 @@ import std; #include #include +#if !defined(BOOST_PFR_INTERFACE_UNIT) +#include +#endif #ifdef __clang__ # pragma clang diagnostic push diff --git a/include/boost/pfr/detail/core17_generated.hpp b/include/boost/pfr/detail/core17_generated.hpp index b4c0b992..70964131 100644 --- a/include/boost/pfr/detail/core17_generated.hpp +++ b/include/boost/pfr/detail/core17_generated.hpp @@ -22,9 +22,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // for std::conditional_t, std::is_reference #endif diff --git a/include/boost/pfr/detail/core_name20_static.hpp b/include/boost/pfr/detail/core_name20_static.hpp index 753d6cbb..551564f2 100644 --- a/include/boost/pfr/detail/core_name20_static.hpp +++ b/include/boost/pfr/detail/core_name20_static.hpp @@ -22,9 +22,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include #include diff --git a/include/boost/pfr/detail/detectors.hpp b/include/boost/pfr/detail/detectors.hpp index 10e10ee8..b87da012 100644 --- a/include/boost/pfr/detail/detectors.hpp +++ b/include/boost/pfr/detail/detectors.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include #endif diff --git a/include/boost/pfr/detail/fields_count.hpp b/include/boost/pfr/detail/fields_count.hpp index afe06fe3..625159ac 100644 --- a/include/boost/pfr/detail/fields_count.hpp +++ b/include/boost/pfr/detail/fields_count.hpp @@ -12,10 +12,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -#include -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include #include // metaprogramming stuff diff --git a/include/boost/pfr/detail/for_each_field.hpp b/include/boost/pfr/detail/for_each_field.hpp index 79182d0d..979226e0 100644 --- a/include/boost/pfr/detail/for_each_field.hpp +++ b/include/boost/pfr/detail/for_each_field.hpp @@ -14,9 +14,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #endif diff --git a/include/boost/pfr/detail/for_each_field_impl.hpp b/include/boost/pfr/detail/for_each_field_impl.hpp index 9922c556..24bd7153 100644 --- a/include/boost/pfr/detail/for_each_field_impl.hpp +++ b/include/boost/pfr/detail/for_each_field_impl.hpp @@ -12,9 +12,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #endif diff --git a/include/boost/pfr/detail/functional.hpp b/include/boost/pfr/detail/functional.hpp index 67438ce3..fbdb5afe 100644 --- a/include/boost/pfr/detail/functional.hpp +++ b/include/boost/pfr/detail/functional.hpp @@ -11,11 +11,8 @@ #include +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include - -#if defined(BOOST_USE_STD_MODULE) -import std; -#else #include #endif diff --git a/include/boost/pfr/detail/io.hpp b/include/boost/pfr/detail/io.hpp index b70903df..715ad03f 100644 --- a/include/boost/pfr/detail/io.hpp +++ b/include/boost/pfr/detail/io.hpp @@ -11,9 +11,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // stream operators #include diff --git a/include/boost/pfr/detail/make_flat_tuple_of_references.hpp b/include/boost/pfr/detail/make_flat_tuple_of_references.hpp index 2d7dc7a9..be47735a 100644 --- a/include/boost/pfr/detail/make_flat_tuple_of_references.hpp +++ b/include/boost/pfr/detail/make_flat_tuple_of_references.hpp @@ -13,9 +13,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #endif diff --git a/include/boost/pfr/detail/make_integer_sequence.hpp b/include/boost/pfr/detail/make_integer_sequence.hpp index 2cfce437..ac9b391f 100644 --- a/include/boost/pfr/detail/make_integer_sequence.hpp +++ b/include/boost/pfr/detail/make_integer_sequence.hpp @@ -10,9 +10,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include #include diff --git a/include/boost/pfr/detail/offset_based_getter.hpp b/include/boost/pfr/detail/offset_based_getter.hpp index 7cfe658b..63a43ebf 100644 --- a/include/boost/pfr/detail/offset_based_getter.hpp +++ b/include/boost/pfr/detail/offset_based_getter.hpp @@ -14,9 +14,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include #include // std::addressof diff --git a/include/boost/pfr/detail/possible_reflectable.hpp b/include/boost/pfr/detail/possible_reflectable.hpp index 8b790b9f..2da06467 100644 --- a/include/boost/pfr/detail/possible_reflectable.hpp +++ b/include/boost/pfr/detail/possible_reflectable.hpp @@ -10,10 +10,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -#include -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // for std::is_aggregate #endif diff --git a/include/boost/pfr/detail/rvalue_t.hpp b/include/boost/pfr/detail/rvalue_t.hpp index 8318ba3a..750bf0a3 100644 --- a/include/boost/pfr/detail/rvalue_t.hpp +++ b/include/boost/pfr/detail/rvalue_t.hpp @@ -7,9 +7,7 @@ #define BOOST_PFR_DETAIL_RVALUE_T_HPP #pragma once -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include // std::enable_if_t #endif diff --git a/include/boost/pfr/detail/sequence_tuple.hpp b/include/boost/pfr/detail/sequence_tuple.hpp index fb9e9b59..5399c399 100644 --- a/include/boost/pfr/detail/sequence_tuple.hpp +++ b/include/boost/pfr/detail/sequence_tuple.hpp @@ -10,9 +10,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #include // std::size_t #endif diff --git a/include/boost/pfr/detail/size_array.hpp b/include/boost/pfr/detail/size_array.hpp index 67825143..81a33fba 100644 --- a/include/boost/pfr/detail/size_array.hpp +++ b/include/boost/pfr/detail/size_array.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #endif diff --git a/include/boost/pfr/detail/size_t_.hpp b/include/boost/pfr/detail/size_t_.hpp index c8ece609..0eb25df7 100644 --- a/include/boost/pfr/detail/size_t_.hpp +++ b/include/boost/pfr/detail/size_t_.hpp @@ -7,9 +7,7 @@ #define BOOST_PFR_DETAIL_SIZE_T_HPP #pragma once -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include #endif diff --git a/include/boost/pfr/detail/stdarray.hpp b/include/boost/pfr/detail/stdarray.hpp index 8af927a4..f17b2c4f 100644 --- a/include/boost/pfr/detail/stdarray.hpp +++ b/include/boost/pfr/detail/stdarray.hpp @@ -11,9 +11,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #include #include // for std::common_type_t diff --git a/include/boost/pfr/detail/stdtuple.hpp b/include/boost/pfr/detail/stdtuple.hpp index 7501ccbf..c0c86712 100644 --- a/include/boost/pfr/detail/stdtuple.hpp +++ b/include/boost/pfr/detail/stdtuple.hpp @@ -11,9 +11,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #include #endif diff --git a/include/boost/pfr/detail/tie_from_structure_tuple.hpp b/include/boost/pfr/detail/tie_from_structure_tuple.hpp index e829dc04..ab8b82dd 100644 --- a/include/boost/pfr/detail/tie_from_structure_tuple.hpp +++ b/include/boost/pfr/detail/tie_from_structure_tuple.hpp @@ -16,9 +16,7 @@ #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #endif diff --git a/include/boost/pfr/detail/unsafe_declval.hpp b/include/boost/pfr/detail/unsafe_declval.hpp index dd040689..3209ad44 100644 --- a/include/boost/pfr/detail/unsafe_declval.hpp +++ b/include/boost/pfr/detail/unsafe_declval.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #endif diff --git a/include/boost/pfr/functions_for.hpp b/include/boost/pfr/functions_for.hpp index a2b63ee8..6820b8f7 100644 --- a/include/boost/pfr/functions_for.hpp +++ b/include/boost/pfr/functions_for.hpp @@ -9,12 +9,10 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include #include -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif /// \file boost/pfr/functions_for.hpp /// Contains BOOST_PFR_FUNCTIONS_FOR macro that defined comparison and stream operators for T along with hash_value function. diff --git a/include/boost/pfr/functors.hpp b/include/boost/pfr/functors.hpp index e21faf27..96852780 100644 --- a/include/boost/pfr/functors.hpp +++ b/include/boost/pfr/functors.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include @@ -222,6 +220,6 @@ template struct hash { }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_FUNCTORS_HPP diff --git a/include/boost/pfr/io.hpp b/include/boost/pfr/io.hpp index f254d949..1b9badf4 100644 --- a/include/boost/pfr/io.hpp +++ b/include/boost/pfr/io.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include #include @@ -114,6 +112,6 @@ auto io(T&& value) noexcept { }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_IO_HPP diff --git a/include/boost/pfr/io_fields.hpp b/include/boost/pfr/io_fields.hpp index eb419651..91df7d27 100644 --- a/include/boost/pfr/io_fields.hpp +++ b/include/boost/pfr/io_fields.hpp @@ -10,9 +10,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include #include @@ -20,9 +18,7 @@ import boost.pfr; #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include // metaprogramming stuff #endif @@ -168,6 +164,6 @@ auto io_fields(T&& value) noexcept { }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_IO_FIELDS_HPP diff --git a/include/boost/pfr/ops.hpp b/include/boost/pfr/ops.hpp index afd87aee..f0ab42d7 100644 --- a/include/boost/pfr/ops.hpp +++ b/include/boost/pfr/ops.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include #include @@ -187,6 +185,6 @@ constexpr detail::enable_hashable_t hash_value(const T& value) { }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_OPS_HPP diff --git a/include/boost/pfr/ops_fields.hpp b/include/boost/pfr/ops_fields.hpp index 8905cb2b..75f49dbc 100644 --- a/include/boost/pfr/ops_fields.hpp +++ b/include/boost/pfr/ops_fields.hpp @@ -9,9 +9,7 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include #include @@ -129,6 +127,6 @@ namespace boost { namespace pfr { }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_OPS_HPP diff --git a/include/boost/pfr/traits.hpp b/include/boost/pfr/traits.hpp index 163b8141..b653677d 100644 --- a/include/boost/pfr/traits.hpp +++ b/include/boost/pfr/traits.hpp @@ -9,15 +9,11 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #endif @@ -65,7 +61,7 @@ constexpr bool is_implicitly_reflectable_v = is_implicitly_reflectable -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) namespace boost { namespace pfr { @@ -20,8 +18,7 @@ struct is_reflectable; }} // namespace boost::pfr -#endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) +#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #endif // BOOST_PFR_DETAIL_TRAITS_FWD_HPP - diff --git a/include/boost/pfr/tuple_size.hpp b/include/boost/pfr/tuple_size.hpp index e84718a0..c2d20294 100644 --- a/include/boost/pfr/tuple_size.hpp +++ b/include/boost/pfr/tuple_size.hpp @@ -10,16 +10,12 @@ #include -#if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) -import boost.pfr; -#else +#if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) #include #include -#if defined(BOOST_USE_STD_MODULE) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include #include // metaprogramming stuff #endif diff --git a/misc/generate_cpp17.py b/misc/generate_cpp17.py index 3ebbe311..7ecaf6aa 100644 --- a/misc/generate_cpp17.py +++ b/misc/generate_cpp17.py @@ -39,9 +39,7 @@ #include #include -#if defined(BOOST_USE_MODULES) -import std; -#else +#if !defined(BOOST_PFR_INTERFACE_UNIT) #include // for std::conditional_t, std::is_reference #endif diff --git a/modules/pfr.cppm b/modules/pfr.cppm index 02fbcaf0..d55a8f78 100644 --- a/modules/pfr.cppm +++ b/modules/pfr.cppm @@ -8,6 +8,28 @@ module; +#include +#include +#include + +#ifdef BOOST_PFR_USE_STD_MODULE +import std; +#else +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #define BOOST_PFR_INTERFACE_UNIT #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 688336a2..b2ba54a4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,12 +2,6 @@ # 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 -# Does not work -#include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) -#if(NOT HAVE_BOOST_TEST) -# return() -#endif() - file(GLOB CORE_RUN_FILES "core/run/*.cpp") foreach (testsourcefile ${CORE_RUN_FILES}) get_filename_component(testname ${testsourcefile} NAME_WLE) From 622e4c97fc9af5c0bdd938e057621a9bcbf8bcf9 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 14 Apr 2025 14:52:14 +0300 Subject: [PATCH 12/16] CI fix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2370cea0..8a145fac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - toolset: clang-19 cxxstd: "20,23" os: ubuntu-24.04 - install: clang-19 clang-tools-19 + install: clang-19 llvm-19 libclang-rt-19-dev libc++-19-dev libc++abi-19-dev clang-tools-19 # - toolset: clang # cxxstd: "03,11,14,17,2a" # os: macos-10.15 From 9e43d26ee815ffcce721027840a32a61d7b1bcf6 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 14 Apr 2025 15:16:48 +0300 Subject: [PATCH 13/16] CI fix attempt --- .github/workflows/ci.yml | 15 +++++++++------ CMakeLists.txt | 4 ++-- test/CMakeLists.txt | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a145fac..ec456359 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,8 +97,9 @@ jobs: cd ../boost-root/libs/pfr mkdir build_module cd build_module - cmake -DBUILD_TESTING=1 -DCMAKE_CXX_FLAGS=-I../../../ -DBOOST_USE_MODULES=1 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. - cmake --build . && ctest -V + cmake -DBUILD_TESTING=1 -DBOOST_USE_MODULES=1 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + cmake --build . + ctest -V cd .. rm -rf build_module @@ -108,8 +109,9 @@ jobs: cd ../boost-root/libs/pfr mkdir build_module cd build_module - cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-I../../../ .. - cmake --build . && ctest -V + cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 .. + cmake --build . + ctest -V cd .. rm -rf build_module @@ -212,8 +214,9 @@ jobs: cd ../boost-root/libs/pfr mkdir build_module cd build_module - cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja -DCMAKE_CXX_FLAGS=-I../../../ .. - cmake --build . && ctest --no-tests=error -V + cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + cmake --build . + ctest --no-tests=error -V cd .. rm -rf build_module diff --git a/CMakeLists.txt b/CMakeLists.txt index eac06ce0..f119fc5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.5...3.31) project(boost_pfr VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES) +if (BOOST_USE_MODULES) add_library(boost_pfr) target_sources(boost_pfr PUBLIC FILE_SET modules_public TYPE CXX_MODULES FILES @@ -36,7 +36,7 @@ if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") add_subdirectory(test) endif() -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" AND BOOST_USE_MODULES AND BUILD_TESTING) +if (BOOST_USE_MODULES AND BUILD_TESTING) add_executable(boost_pfr_module_usage modules/usage_sample.cpp) target_link_libraries(boost_pfr_module_usage PRIVATE Boost::pfr) add_test(NAME boost_pfr_module_usage COMMAND boost_pfr_module_usage) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b2ba54a4..efb910ed 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,6 +7,7 @@ foreach (testsourcefile ${CORE_RUN_FILES}) get_filename_component(testname ${testsourcefile} NAME_WLE) add_executable(pfr_core_${testname} ${testsourcefile}) target_link_libraries(pfr_core_${testname} Boost::pfr) + target_include_directories(pfr_core_${testname} PRIVATE ../../../) add_test(NAME pfr_core_${testname} COMMAND pfr_core_${testname}) endforeach() @@ -15,5 +16,6 @@ foreach (testsourcefile ${CORE_NAME_RUN_FILES}) get_filename_component(testname ${testsourcefile} NAME_WLE) add_executable(pfr_corename_${testname} ${testsourcefile}) target_link_libraries(pfr_corename_${testname} Boost::pfr) + target_include_directories(pfr_corename_${testname} PRIVATE ../../../) add_test(NAME pfr_corename_${testname} COMMAND pfr_corename_${testname}) endforeach() From 5182bda27727791fc6a7825de9c12c7698300b9b Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 14 Apr 2025 15:17:43 +0300 Subject: [PATCH 14/16] fix --- include/boost/pfr/detail/core14_classic.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/pfr/detail/core14_classic.hpp b/include/boost/pfr/detail/core14_classic.hpp index 7d50f1e3..7c60b689 100644 --- a/include/boost/pfr/detail/core14_classic.hpp +++ b/include/boost/pfr/detail/core14_classic.hpp @@ -18,7 +18,8 @@ #include #include -#if !defined(BOOST_PFR_INTERFACE_UNIT)#include +#if !defined(BOOST_PFR_INTERFACE_UNIT) +#include #include // metaprogramming stuff #endif From bb1bc0ae40134ace2db2f00a8824d37dcacbfb7f Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 14 Apr 2025 15:36:19 +0300 Subject: [PATCH 15/16] CI fixes --- .github/workflows/ci.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec456359..b821eead 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,8 @@ jobs: ./b2 variant=debug tools/inspect/build - name: Run modules tests - if: ${{matrix.toolset == 'clang-19'}} + if: false + # if: ${{matrix.toolset == 'clang-19'}} run: | cd ../boost-root/libs/pfr mkdir build_module @@ -206,7 +207,8 @@ jobs: b2 -d0 headers - name: Run modules tests - if: ${{matrix.toolset == 'msvc-14.3'}} + if: false + # if: ${{matrix.toolset == 'msvc-14.3'}} shell: cmd run: | choco install --no-progress ninja @@ -220,6 +222,21 @@ jobs: cd .. rm -rf build_module + - name: Run modules tests wihtout 'import std;' + if: ${{matrix.toolset == 'msvc-14.3'}} + shell: cmd + run: | + choco install --no-progress ninja + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/libs/pfr + mkdir build_module + cd build_module + cmake -DBOOST_USE_MODULES=1 -DBUILD_TESTING=1 -DCMAKE_CXX_STANDARD=20 -G Ninja .. + cmake --build . + ctest --no-tests=error -V + cd .. + rm -rf build_module + - name: Run tests shell: cmd run: | From 1a996e946c739584ddd56b10151faf328bf0014b Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 14 Apr 2025 16:40:35 +0300 Subject: [PATCH 16/16] Force non-global module fragment usage for PFR --- doc/pfr.qbk | 20 +++++----- include/boost/pfr/config.hpp | 8 ++++ include/boost/pfr/core.hpp | 4 ++ include/boost/pfr/core_name.hpp | 4 ++ include/boost/pfr/functors.hpp | 4 ++ include/boost/pfr/io.hpp | 8 ++++ include/boost/pfr/io_fields.hpp | 7 ++++ include/boost/pfr/ops.hpp | 4 ++ include/boost/pfr/ops_fields.hpp | 4 ++ include/boost/pfr/traits.hpp | 4 ++ include/boost/pfr/traits_fwd.hpp | 4 ++ include/boost/pfr/tuple_size.hpp | 4 ++ modules/pfr.cppm | 64 ++------------------------------ 13 files changed, 69 insertions(+), 70 deletions(-) diff --git a/doc/pfr.qbk b/doc/pfr.qbk index db0d8f34..f9d79634 100644 --- a/doc/pfr.qbk +++ b/doc/pfr.qbk @@ -554,22 +554,22 @@ parameters provided to `BOOST_PFR_CORE_NAME_PARSING` macro [*and] the initial ou [section PFR as a C++20 module] -[caution C++20 PFR module support is on early stage, targets and flags may change in the future] +[caution C++20 PFR module support is on early stage, targets, flags and behavior may change in the future] -If using CMake of version 3.28.0 or higher define CMake option `-DBOOST_USE_MODULES=1` -to make the `Boost::pfr` target build C++20 module. After that an explicit usage of C++20 module `boost.pfr` is allowed: +If using modern CMake define CMake option `-DBOOST_USE_MODULES=1` to build a C++20 module and +make the `Boost::pfr` CMake target provide it. After that an explicit usage of C++20 module `boost.pfr` is allowed: [import ../module/usage_sample.cpp] [pfr_module_example] -The `Boost::pfr` CMake target gives an ability to -mix includes and imports of the PFR library in different translation units. Moreover, -if `BOOST_USE_MODULES` macro is defined then all the `boost/pfr/...` includes -implicilty do `import boost.pfr;` to give all the benifits of modules without -changing the code base. +The `Boost::pfr` CMake target gives an ability to mix includes and imports of the PFR library in different translation units. Moreover, +if `BOOST_USE_MODULES` macro is defined then all the `boost/pfr/...` includes implicilty do `import boost.pfr;` to give all the +benifits of modules without changing the existing code. -If not using CMake, then the module could be build manually from the -`module/pfr.cppm` file. +[note For better compile times make sure that `import std;` is available when building the `boost.pfr` module (in CMake logs there should be + a 'Using `import std;`' message). ] + +If not using CMake, then the module could be build manually from the `module/pfr.cppm` file. For manual module build the following commands could be used for clang compiler: diff --git a/include/boost/pfr/config.hpp b/include/boost/pfr/config.hpp index 607fedee..4a88baa4 100644 --- a/include/boost/pfr/config.hpp +++ b/include/boost/pfr/config.hpp @@ -149,6 +149,14 @@ #undef BOOST_PFR_NOT_SUPPORTED +#ifdef BOOST_PFR_INTERFACE_UNIT +# define BOOST_PFR_BEGIN_MODULE_EXPORT export { +# define BOOST_PFR_END_MODULE_EXPORT } +#else +# define BOOST_PFR_BEGIN_MODULE_EXPORT +# define BOOST_PFR_END_MODULE_EXPORT +#endif + #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) import boost.pfr; #endif diff --git a/include/boost/pfr/core.hpp b/include/boost/pfr/core.hpp index a79d0649..6265f46e 100644 --- a/include/boost/pfr/core.hpp +++ b/include/boost/pfr/core.hpp @@ -33,6 +33,8 @@ namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + /// \brief Returns reference or const reference to a field with index `I` in \aggregate `val`. /// Overload taking the type `U` returns reference or const reference to a field /// with provided type `U` in \aggregate `val` if there's only one field of such type in `val`. @@ -247,6 +249,8 @@ constexpr detail::tie_from_structure_tuple tie_from_structure(Eleme return detail::tie_from_structure_tuple(args...); } +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/core_name.hpp b/include/boost/pfr/core_name.hpp index ed11affe..34cab9aa 100644 --- a/include/boost/pfr/core_name.hpp +++ b/include/boost/pfr/core_name.hpp @@ -37,6 +37,8 @@ namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + /// \brief Returns name of a field with index `I` in \aggregate `T`. /// /// \b Example: @@ -108,6 +110,8 @@ constexpr void for_each_field_with_name(T&& value, F&& func) { return boost::pfr::detail::for_each_field_with_name(std::forward(value), std::forward(func)); } +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/functors.hpp b/include/boost/pfr/functors.hpp index 96852780..0fb06885 100644 --- a/include/boost/pfr/functors.hpp +++ b/include/boost/pfr/functors.hpp @@ -37,6 +37,8 @@ /// \b Synopsis: namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + ///////////////////// Comparisons /// \brief std::equal_to like comparator that returns \forcedlink{eq}(x, y) @@ -218,6 +220,8 @@ template struct hash { } }; +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/io.hpp b/include/boost/pfr/io.hpp index 1b9badf4..b5882bd4 100644 --- a/include/boost/pfr/io.hpp +++ b/include/boost/pfr/io.hpp @@ -69,6 +69,8 @@ struct io_impl { T value; }; +BOOST_PFR_BEGIN_MODULE_EXPORT + template enable_not_ostreamable_t, T> operator<<(std::basic_ostream& out, io_impl&& x) { return out << boost::pfr::io_fields(std::forward(x.value)); @@ -89,8 +91,12 @@ enable_istreamable_t, T> operator>>(std::basic_ return in >> x.value; } +BOOST_PFR_END_MODULE_EXPORT + } // namespace detail +BOOST_PFR_BEGIN_MODULE_EXPORT + /// IO manipulator to read/write \aggregate `value` using its IO stream operators or using \forcedlink{io_fields} if operators are not available. /// /// \b Example: @@ -110,6 +116,8 @@ auto io(T&& value) noexcept { return detail::io_impl{std::forward(value)}; } +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/io_fields.hpp b/include/boost/pfr/io_fields.hpp index 91df7d27..f02812cb 100644 --- a/include/boost/pfr/io_fields.hpp +++ b/include/boost/pfr/io_fields.hpp @@ -55,6 +55,7 @@ struct io_fields_impl { T value; }; +BOOST_PFR_BEGIN_MODULE_EXPORT template std::basic_ostream& operator<<(std::basic_ostream& out, io_fields_impl&& x) { @@ -133,8 +134,12 @@ std::basic_istream& operator>>(std::basic_istream& i return in; } +BOOST_PFR_END_MODULE_EXPORT + } // namespace detail +BOOST_PFR_BEGIN_MODULE_EXPORT + /// IO manipulator to read/write \aggregate `value` field-by-field. /// /// \b Example: @@ -162,6 +167,8 @@ auto io_fields(T&& value) noexcept { return detail::io_fields_impl{std::forward(value)}; } +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/ops.hpp b/include/boost/pfr/ops.hpp index f0ab42d7..ed339db0 100644 --- a/include/boost/pfr/ops.hpp +++ b/include/boost/pfr/ops.hpp @@ -79,6 +79,8 @@ namespace detail { >; } // namespace detail +BOOST_PFR_BEGIN_MODULE_EXPORT + /// \brief Compares lhs and rhs for equality using their own comparison and conversion operators; if no operators available returns \forcedlink{eq_fields}(lhs, rhs). /// /// \returns true if lhs is equal to rhs; false otherwise @@ -183,6 +185,8 @@ constexpr detail::enable_hashable_t hash_value(const T& value) { return std::hash{}(value); } +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/ops_fields.hpp b/include/boost/pfr/ops_fields.hpp index 75f49dbc..c1617f18 100644 --- a/include/boost/pfr/ops_fields.hpp +++ b/include/boost/pfr/ops_fields.hpp @@ -35,6 +35,8 @@ /// \b Synopsis: namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + /// Does a field-by-field equality comparison. /// /// \returns `L == R && tuple_size_v == tuple_size_v`, where `L` and @@ -125,6 +127,8 @@ namespace boost { namespace pfr { #endif } +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/traits.hpp b/include/boost/pfr/traits.hpp index b653677d..753d4c59 100644 --- a/include/boost/pfr/traits.hpp +++ b/include/boost/pfr/traits.hpp @@ -24,6 +24,8 @@ namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + /// Has a static const member variable `value` when it is known that type T can or can't be reflected using Boost.PFR; otherwise, there is no member variable. /// Every user may (and in some difficult cases - should) specialize is_reflectable on his own. /// @@ -59,6 +61,8 @@ using is_implicitly_reflectable = std::integral_constant< bool, boost::pfr::deta template constexpr bool is_implicitly_reflectable_v = is_implicitly_reflectable::value; +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/traits_fwd.hpp b/include/boost/pfr/traits_fwd.hpp index 3b0b0f06..00162263 100644 --- a/include/boost/pfr/traits_fwd.hpp +++ b/include/boost/pfr/traits_fwd.hpp @@ -13,9 +13,13 @@ namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + template struct is_reflectable; +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/include/boost/pfr/tuple_size.hpp b/include/boost/pfr/tuple_size.hpp index c2d20294..4b1d553f 100644 --- a/include/boost/pfr/tuple_size.hpp +++ b/include/boost/pfr/tuple_size.hpp @@ -26,6 +26,8 @@ /// \b Synopsis: namespace boost { namespace pfr { +BOOST_PFR_BEGIN_MODULE_EXPORT + /// Has a static const member variable `value` that contains fields count in a T. /// Works for any T that satisfies \aggregate. /// @@ -47,6 +49,8 @@ using tuple_size = detail::size_t_< boost::pfr::detail::fields_count() >; template constexpr std::size_t tuple_size_v = tuple_size::value; +BOOST_PFR_END_MODULE_EXPORT + }} // namespace boost::pfr #endif // #if defined(BOOST_USE_MODULES) && !defined(BOOST_PFR_INTERFACE_UNIT) diff --git a/modules/pfr.cppm b/modules/pfr.cppm index d55a8f78..b013a231 100644 --- a/modules/pfr.cppm +++ b/modules/pfr.cppm @@ -31,68 +31,12 @@ import std; #endif #define BOOST_PFR_INTERFACE_UNIT -#include export module boost.pfr; -export namespace boost::pfr { - -// core.hpp -using pfr::get; -using pfr::tuple_element; -using pfr::tuple_element_t; -using pfr::structure_to_tuple; -using pfr::structure_tie; -using pfr::for_each_field; -using pfr::tie_from_structure; - -// core_name.hpp -using pfr::get_name; -using pfr::names_as_array; -using pfr::for_each_field_with_name; - -// functors.hpp -using pfr::equal_to; -using pfr::not_equal; -using pfr::greater; -using pfr::less; -using pfr::greater_equal; -using pfr::less_equal; -using pfr::hash; - -// io.hpp and io_fields.hpp -namespace detail { - using detail::operator<<; - using detail::operator>>; -} // namespace detail -using pfr::io; -using pfr::io_fields; - -// ops.hpp -using pfr::eq; -using pfr::ne; -using pfr::lt; -using pfr::gt; -using pfr::le; -using pfr::ge; -using pfr::hash_value; - -// ops_fields.hpp -using pfr::eq_fields; -using pfr::ne_fields; -using pfr::lt_fields; -using pfr::gt_fields; -using pfr::le_fields; -using pfr::ge_fields; -using pfr::hash_fields; - -// traits.hpp -using pfr::is_reflectable; -using pfr::is_implicitly_reflectable; -using pfr::is_implicitly_reflectable_v; +#ifdef __clang__ +# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview" +#endif -// tuple_size.hpp -using pfr::tuple_size; -using pfr::tuple_size_v; +#include -}