Skip to content

Commit 04129c6

Browse files
committed
Initial support for C++20 modules
1 parent 449bf36 commit 04129c6

34 files changed

+208
-1
lines changed

Diff for: example/module_usage.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2016-2024 Antony Polukhin
2+
//
3+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
// Compile via:
7+
// clang++-15 -std=c++20 -fmodule-file=pfr.pcm pfr.pcm example/module_usage.cpp
8+
9+
//[pfr_module_example
10+
#include <cstdio>
11+
12+
import Boost.PFR;
13+
14+
struct some_person {
15+
const char* name;
16+
unsigned birth_year;
17+
};
18+
19+
int main() {
20+
some_person val{"Edgar Allan Poe", 1809};
21+
std::puts(boost::pfr::get<0>(val)); // Writes "Edgar Allan Poe"
22+
}
23+
//]

Diff for: include/boost/pfr/config.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,12 @@
145145

146146
#undef BOOST_PFR_NOT_SUPPORTED
147147

148+
#ifndef BOOST_PFR_BEGIN_MODULE_EXPORT
149+
# define BOOST_PFR_BEGIN_MODULE_EXPORT
150+
#endif
151+
152+
#ifndef BOOST_PFR_END_MODULE_EXPORT
153+
# define BOOST_PFR_END_MODULE_EXPORT
154+
#endif
155+
148156
#endif // BOOST_PFR_CONFIG_HPP

Diff for: include/boost/pfr/core.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
namespace boost { namespace pfr {
3131

32+
BOOST_PFR_BEGIN_MODULE_EXPORT
33+
3234
/// \brief Returns reference or const reference to a field with index `I` in \aggregate `val`.
3335
/// Overload taking the type `U` returns reference or const reference to a field
3436
/// with provided type `U` in \aggregate `val` if there's only one field of such type in `val`.
@@ -260,6 +262,8 @@ constexpr detail::tie_from_structure_tuple<Elements...> tie_from_structure(Eleme
260262
return detail::tie_from_structure_tuple<Elements...>(args...);
261263
}
262264

265+
BOOST_PFR_END_MODULE_EXPORT
266+
263267
}} // namespace boost::pfr
264268

265269
#endif // BOOST_PFR_CORE_HPP

Diff for: include/boost/pfr/core_name.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
namespace boost { namespace pfr {
3535

36+
BOOST_PFR_BEGIN_MODULE_EXPORT
37+
3638
/// \brief Returns name of a field with index `I` in \aggregate `T`.
3739
///
3840
/// \b Example:
@@ -82,6 +84,8 @@ names_as_array() noexcept {
8284
);
8385
}
8486

87+
BOOST_PFR_END_MODULE_EXPORT
88+
8589
}} // namespace boost::pfr
8690

8791
#endif // BOOST_PFR_CORE_NAME_HPP

Diff for: include/boost/pfr/detail/core14_classic.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <type_traits>
1316
#include <utility> // metaprogramming stuff
17+
#endif
1418

1519
#include <boost/pfr/detail/sequence_tuple.hpp>
1620
#include <boost/pfr/detail/offset_based_getter.hpp>

Diff for: include/boost/pfr/detail/core14_loophole.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424

2525
#include <boost/pfr/detail/config.hpp>
2626

27+
#ifdef BOOST_PFR_HAS_STD_MODULE
28+
import std;
29+
#else
2730
#include <type_traits>
2831
#include <utility>
32+
#endif
2933

3034
#include <boost/pfr/detail/offset_based_getter.hpp>
3135
#include <boost/pfr/detail/fields_count.hpp>

Diff for: include/boost/pfr/detail/core17_generated.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121

2222
#include <boost/pfr/detail/sequence_tuple.hpp>
2323
#include <boost/pfr/detail/size_t_.hpp>
24+
25+
#ifdef BOOST_PFR_HAS_STD_MODULE
26+
import std;
27+
#else
2428
#include <type_traits> // for std::conditional_t, std::is_reference
29+
#endif
2530

2631
namespace boost { namespace pfr { namespace detail {
2732

Diff for: include/boost/pfr/detail/core_name20_static.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
#include <boost/pfr/detail/fields_count.hpp>
2020
#include <boost/pfr/detail/stdarray.hpp>
2121
#include <boost/pfr/detail/fake_object.hpp>
22+
23+
#ifdef BOOST_PFR_HAS_STD_MODULE
24+
import std;
25+
#else
2226
#include <type_traits>
2327
#include <string_view>
2428
#include <array>
2529
#include <memory> // for std::addressof
30+
#endif
2631

2732
namespace boost { namespace pfr { namespace detail {
2833

Diff for: include/boost/pfr/detail/detectors.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <functional>
1316
#include <type_traits>
17+
#endif
1418

1519
namespace boost { namespace pfr { namespace detail {
1620
///////////////////// `value` is true if Detector<Tleft, Tright> does not compile (SFINAE)

Diff for: include/boost/pfr/detail/fields_count.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
#include <boost/pfr/detail/size_t_.hpp>
1313
#include <boost/pfr/detail/unsafe_declval.hpp>
1414

15+
#ifdef BOOST_PFR_HAS_STD_MODULE
16+
import std;
17+
#else
1518
#include <climits> // CHAR_BIT
1619
#include <type_traits>
1720
#include <utility> // metaprogramming stuff
21+
#endif
1822

1923
#ifdef __clang__
2024
# pragma clang diagnostic push

Diff for: include/boost/pfr/detail/for_each_field_impl.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <utility> // metaprogramming stuff
16+
#endif
1317

1418
#include <boost/pfr/detail/sequence_tuple.hpp>
1519
#include <boost/pfr/detail/rvalue_t.hpp>

Diff for: include/boost/pfr/detail/functional.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <functional>
1316
#include <cstdint>
17+
#endif
1418

1519
#include <boost/pfr/detail/sequence_tuple.hpp>
1620

Diff for: include/boost/pfr/detail/io.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <boost/pfr/detail/config.hpp>
1111

1212
#include <boost/pfr/detail/sequence_tuple.hpp>
13+
14+
#ifdef BOOST_PFR_HAS_STD_MODULE
15+
import std;
16+
#else
1317
#include <iosfwd> // stream operators
1418
#include <iomanip>
1519

@@ -19,6 +23,8 @@
1923
# endif
2024
#endif
2125

26+
#endif
27+
2228
namespace boost { namespace pfr { namespace detail {
2329

2430
inline auto quoted_helper(const std::string& s) noexcept {

Diff for: include/boost/pfr/detail/make_flat_tuple_of_references.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <utility> // metaprogramming stuff
16+
#endif
17+
1318
#include <boost/pfr/detail/sequence_tuple.hpp>
1419
#include <boost/pfr/detail/rvalue_t.hpp>
1520
#include <boost/pfr/detail/make_integer_sequence.hpp>

Diff for: include/boost/pfr/detail/make_integer_sequence.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010

1111
#include <boost/pfr/detail/config.hpp>
1212

13+
#ifdef BOOST_PFR_HAS_STD_MODULE
14+
import std;
15+
#else
1316
#include <type_traits>
1417
#include <utility>
1518
#include <cstddef>
19+
#endif
1620

1721
namespace boost { namespace pfr { namespace detail {
1822

Diff for: include/boost/pfr/detail/offset_based_getter.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010

1111
#include <boost/pfr/detail/config.hpp>
1212

13+
#ifdef BOOST_PFR_HAS_STD_MODULE
14+
import std;
15+
#else
1316
#include <type_traits>
1417
#include <utility>
1518
#include <memory> // std::addressof
19+
#endif
20+
1621
#include <boost/pfr/detail/sequence_tuple.hpp>
1722
#include <boost/pfr/detail/rvalue_t.hpp>
1823
#include <boost/pfr/detail/size_t_.hpp>

Diff for: include/boost/pfr/detail/possible_reflectable.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
#include <boost/pfr/detail/config.hpp>
1111
#include <boost/pfr/traits_fwd.hpp>
1212

13+
#ifdef BOOST_PFR_HAS_STD_MODULE
14+
import std;
15+
#else
1316
#include <type_traits> // for std::is_aggregate
17+
#endif
1418

1519
namespace boost { namespace pfr { namespace detail {
1620

Diff for: include/boost/pfr/detail/rvalue_t.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#define BOOST_PFR_DETAIL_RVALUE_T_HPP
88
#pragma once
99

10+
#ifdef BOOST_PFR_HAS_STD_MODULE
11+
import std;
12+
#else
1013
#include <type_traits>
1114
#include <utility> // std::enable_if_t
15+
#endif
1216

1317
// This header provides aliases rvalue_t and lvalue_t.
1418
//

Diff for: include/boost/pfr/detail/sequence_tuple.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
#include <boost/pfr/detail/config.hpp>
1111
#include <boost/pfr/detail/make_integer_sequence.hpp>
1212

13+
#ifdef BOOST_PFR_HAS_STD_MODULE
14+
import std;
15+
#else
1316
#include <utility> // metaprogramming stuff
1417
#include <cstddef> // std::size_t
18+
#endif
1519

1620
///////////////////// Tuple that holds its values in the supplied order
1721
namespace boost { namespace pfr { namespace detail { namespace sequence_tuple {

Diff for: include/boost/pfr/detail/size_array.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12-
#include <cstddef> // metaprogramming stuff
12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
15+
#include <cstddef>
16+
#endif
1317

1418
namespace boost { namespace pfr { namespace detail {
1519

Diff for: include/boost/pfr/detail/stdarray.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <utility> // metaprogramming stuff
1316
#include <array>
1417
#include <type_traits> // for std::common_type_t
1518
#include <cstddef>
19+
#endif
1620

1721
#include <boost/pfr/detail/sequence_tuple.hpp>
1822

Diff for: include/boost/pfr/detail/stdtuple.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <utility> // metaprogramming stuff
1316
#include <tuple>
17+
#endif
1418

1519
#include <boost/pfr/detail/sequence_tuple.hpp>
1620

Diff for: include/boost/pfr/detail/tie_from_structure_tuple.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
#include <boost/pfr/tuple_size.hpp>
1717
#include <boost/pfr/detail/make_integer_sequence.hpp>
1818

19+
#ifdef BOOST_PFR_HAS_STD_MODULE
20+
import std;
21+
#else
1922
#include <tuple>
23+
#endif
2024

2125
namespace boost { namespace pfr { namespace detail {
2226

Diff for: include/boost/pfr/detail/unsafe_declval.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010
#include <boost/pfr/detail/config.hpp>
1111

12+
#ifdef BOOST_PFR_HAS_STD_MODULE
13+
import std;
14+
#else
1215
#include <type_traits>
16+
#endif
1317

1418
namespace boost { namespace pfr { namespace detail {
1519

Diff for: include/boost/pfr/functors.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
/// \b Synopsis:
3636
namespace boost { namespace pfr {
3737

38+
BOOST_PFR_BEGIN_MODULE_EXPORT
39+
3840
///////////////////// Comparisons
3941

4042
/// \brief std::equal_to like comparator that returns \forcedlink{eq}(x, y)
@@ -216,6 +218,8 @@ template <class T> struct hash {
216218
}
217219
};
218220

221+
BOOST_PFR_END_MODULE_EXPORT
222+
219223
}} // namespace boost::pfr
220224

221225
#endif // BOOST_PFR_FUNCTORS_HPP

Diff for: include/boost/pfr/io.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ enable_istreamable_t<std::basic_istream<Char, Traits>, T> operator>>(std::basic_
8989

9090
} // namespace detail
9191

92+
BOOST_PFR_BEGIN_MODULE_EXPORT
93+
9294
/// IO manipulator to read/write \aggregate `value` using its IO stream operators or using \forcedlink{io_fields} if operators are not available.
9395
///
9496
/// \b Example:
@@ -108,6 +110,8 @@ auto io(T&& value) noexcept {
108110
return detail::io_impl<T>{std::forward<T>(value)};
109111
}
110112

113+
BOOST_PFR_END_MODULE_EXPORT
114+
111115
}} // namespace boost::pfr
112116

113117
#endif // BOOST_PFR_IO_HPP

Diff for: include/boost/pfr/io_fields.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& i
132132

133133
} // namespace detail
134134

135+
BOOST_PFR_BEGIN_MODULE_EXPORT
136+
135137
/// IO manipulator to read/write \aggregate `value` field-by-field.
136138
///
137139
/// \b Example:
@@ -159,6 +161,8 @@ auto io_fields(T&& value) noexcept {
159161
return detail::io_fields_impl<T>{std::forward<T>(value)};
160162
}
161163

164+
BOOST_PFR_END_MODULE_EXPORT
165+
162166
}} // namespace boost::pfr
163167

164168
#endif // BOOST_PFR_IO_FIELDS_HPP

0 commit comments

Comments
 (0)