2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Rewrite modules following the new recommended Boost practice (#196)

Changes:

1) `#include <boost/pfr...` is now implicitly does `import boost.pfr` if the modules are supported 
2) CI now tests modules on Ubuntu 24.04 with existing runtime tests
3) Renamed module to `boost.pfr`
4) CMakeLists.txt now uses modules for `Boost::pfr` target if modules are supported
5) All the library internals now have unconditional module level linkage. `1)` allows users to mix `#include <boost/pfr...` and `import boost.pfr` in user code without ODR-violations.

Significant differences from https://anarthal.github.io/cppblog/modules3:
* PFR uses a `BOOST_PFR_USE_STD_MODULE` macro for `import std;` / `includes` while building module. This allows to use `boost.pfr` module in C++20 and even without usable  `std` module.
This commit is contained in:
Antony Polukhin
2025-04-16 09:16:09 +03:00
committed by GitHub
parent 3fe5ce61ee
commit 5a48d7456f
52 changed files with 321 additions and 193 deletions

21
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,21 @@
# 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
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)
target_include_directories(pfr_core_${testname} PRIVATE ../../../)
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)
target_include_directories(pfr_corename_${testname} PRIVATE ../../../)
add_test(NAME pfr_corename_${testname} COMMAND pfr_corename_${testname})
endforeach()

View File

@@ -24,7 +24,7 @@ struct A {
};
int main() {
#if BOOST_PFR_USE_CPP17
#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;

View File

@@ -13,6 +13,11 @@
#include <iostream>
#include <type_traits>
#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES
int main() {}
#else
template <typename T>
class CfgAttrib {
public:
@@ -99,3 +104,5 @@ int main() {
boost::pfr::get<0>(aCfg); // also C1202
#endif
}
#endif

View File

@@ -10,6 +10,11 @@
#include <boost/core/lightweight_test.hpp>
#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

View File

@@ -7,6 +7,10 @@
#include <boost/pfr/traits.hpp>
#include <type_traits> // 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

View File

@@ -7,6 +7,11 @@
#include <boost/pfr/core.hpp>
#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES
int main() {}
#else
template <class T>
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

View File

@@ -7,6 +7,11 @@
#include <boost/pfr/core.hpp>
#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES
int main() {}
#else
template <class T>
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

View File

@@ -7,6 +7,11 @@
#include <boost/pfr/core.hpp>
#if defined(BOOST_USE_MODULES) // TODO: fix for BOOST_USE_MODULES
int main() {}
#else
template <class T>
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

View File

@@ -13,6 +13,11 @@
#include <boost/core/lightweight_test.hpp>
#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