Skip to content

Commit 7af2aad

Browse files
authored
Add module support and tests. (#174)
1 parent f039773 commit 7af2aad

File tree

81 files changed

+3018
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3018
-321
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,41 @@ jobs:
135135
- name: Test
136136
run: ../../../b2 toolset=$TOOLSET define=CI_SUPPRESS_KNOWN_ISSUES define=SLOW_COMPILER
137137
working-directory: ../boost-root/libs/regex/test
138+
ubuntu-jammy-clang-18-modules:
139+
runs-on: ubuntu-22.04
140+
steps:
141+
- uses: actions/checkout@v2
142+
with:
143+
fetch-depth: '0'
144+
- uses: mstachniuk/ci-skip@v1
145+
with:
146+
commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[windows];[Windows];[WINDOWS];[apple];[Apple];[APPLE]'
147+
commit-filter-separator: ';'
148+
fail-fast: true
149+
- name: Grab install script
150+
run: wget https://apt.llvm.org/llvm.sh && chmod u+x llvm.sh
151+
- name: Install clang 18 packages
152+
run: sudo ./llvm.sh 18 && clang++-18 --version
153+
- name: Checkout main boost
154+
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
155+
- name: Update tools/boostdep
156+
run: git submodule update --init tools/boostdep
157+
working-directory: ../boost-root
158+
- name: Copy files
159+
run: cp -r $GITHUB_WORKSPACE/* libs/regex
160+
working-directory: ../boost-root
161+
- name: Install deps
162+
run: python tools/boostdep/depinst/depinst.py -I example -g "--jobs 3" regex
163+
working-directory: ../boost-root
164+
- name: Bootstrap
165+
run: ./bootstrap.sh
166+
working-directory: ../boost-root
167+
- name: Generate headers
168+
run: ./b2 headers
169+
working-directory: ../boost-root
170+
- name: Test
171+
run: CXX=clang++-18 LIBRARIES="-licuuc -licudata -licui18n" ./test_clang.sh
172+
working-directory: ../boost-root/libs/regex/test/module
138173
macos:
139174
runs-on: macos-latest
140175
strategy:
@@ -339,6 +374,9 @@ jobs:
339374
commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[apple];[Apple];[APPLE];[linux];[Linux];[LINUX]'
340375
commit-filter-separator: ';'
341376
fail-fast: true
377+
- uses: TheMrMilchmann/setup-msvc-dev@v3
378+
with:
379+
arch: x64
342380
- name: Checkout main boost
343381
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
344382
- name: Update tools/boostdep
@@ -365,6 +403,9 @@ jobs:
365403
- name: Test
366404
run: ..\..\..\b2 --hash %ARGS%
367405
working-directory: ../boost-root/libs/regex/test
406+
- name: Module Test
407+
run: msvc_test.bat
408+
working-directory: ../boost-root/libs/regex/test/module
368409
ubuntu-cmake-install:
369410
runs-on: ubuntu-20.04
370411
strategy:

doc/html/boost_regex/install.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="home" href="../index.html" title="Boost.Regex 7.0.1">
88
<link rel="up" href="../index.html" title="Boost.Regex 7.0.1">
99
<link rel="prev" href="configuration/tuning.html" title="Algorithm Tuning">
10-
<link rel="next" href="intro.html" title="Introduction and Overview">
10+
<link rel="next" href="modules.html" title="Module Support (Experimental)">
1111
<meta name="viewport" content="width=device-width, initial-scale=1">
1212
</head>
1313
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -21,7 +21,7 @@
2121
</tr></table>
2222
<hr>
2323
<div class="spirit-nav">
24-
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24+
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="modules.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
2525
</div>
2626
<div class="section">
2727
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
@@ -109,7 +109,7 @@ <h5>
109109
</div>
110110
<hr>
111111
<div class="spirit-nav">
112-
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
112+
<a accesskey="p" href="configuration/tuning.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="modules.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
113113
</div>
114114
</body>
115115
</html>

doc/html/boost_regex/intro.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
77
<link rel="home" href="../index.html" title="Boost.Regex 7.0.1">
88
<link rel="up" href="../index.html" title="Boost.Regex 7.0.1">
9-
<link rel="prev" href="install.html" title="Building and Installing the Library">
9+
<link rel="prev" href="modules.html" title="Module Support (Experimental)">
1010
<link rel="next" href="unicode.html" title="Unicode and Boost.Regex">
1111
<meta name="viewport" content="width=device-width, initial-scale=1">
1212
</head>
@@ -21,7 +21,7 @@
2121
</tr></table>
2222
<hr>
2323
<div class="spirit-nav">
24-
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24+
<a accesskey="p" href="modules.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
2525
</div>
2626
<div class="section">
2727
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
@@ -206,7 +206,7 @@
206206
</div>
207207
<hr>
208208
<div class="spirit-nav">
209-
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
209+
<a accesskey="p" href="modules.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="unicode.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
210210
</div>
211211
</body>
212212
</html>

doc/html/boost_regex/modules.html

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4+
<title>Module Support (Experimental)</title>
5+
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6+
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7+
<link rel="home" href="../index.html" title="Boost.Regex 7.0.1">
8+
<link rel="up" href="../index.html" title="Boost.Regex 7.0.1">
9+
<link rel="prev" href="install.html" title="Building and Installing the Library">
10+
<link rel="next" href="intro.html" title="Introduction and Overview">
11+
<meta name="viewport" content="width=device-width, initial-scale=1">
12+
</head>
13+
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14+
<table cellpadding="2" width="100%"><tr>
15+
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
16+
<td align="center"><a href="../../../../../index.html">Home</a></td>
17+
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
18+
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19+
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20+
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
21+
</tr></table>
22+
<hr>
23+
<div class="spirit-nav">
24+
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
25+
</div>
26+
<div class="section">
27+
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28+
<a name="boost_regex.modules"></a><a class="link" href="modules.html" title="Module Support (Experimental)">Module Support (Experimental)</a>
29+
</h2></div></div></div>
30+
<p>
31+
This library has experimental support for C++ modules (C++20 or later), currently
32+
the support is experimental not least because at the time of writing (2025)
33+
build tools have yet to catch up with module support.
34+
</p>
35+
<p>
36+
In order to use this library as a module you simply add a:
37+
</p>
38+
<pre class="programlisting"><span class="identifier">import</span> <span class="identifier">boost</span><span class="special">.</span><span class="identifier">regex</span><span class="special">;</span>
39+
</pre>
40+
<p>
41+
to your code.
42+
</p>
43+
<p>
44+
Before that you must first build the module, which consists of these steps:
45+
</p>
46+
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
47+
<li class="listitem">
48+
Depending on your compiler, you may need to build the standard library
49+
module, and place the standard module somewhere that your compiler can
50+
find it.
51+
</li>
52+
<li class="listitem">
53+
Build <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">module</span><span class="special">/</span><span class="identifier">regex</span><span class="special">.</span><span class="identifier">cxx</span></code> into the boost.regex module, and
54+
place the module definition file somewhere that your compiler can find
55+
it.
56+
</li>
57+
<li class="listitem">
58+
Build all the source files in <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">module</span></code>
59+
(including regex.cxx) into a library, and place the result somewhere your
60+
linker can find it.
61+
</li>
62+
</ul></div>
63+
<p>
64+
Visual studio users can simplify all of the above into one step, by placing
65+
everything in <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">module</span></code>
66+
into a static library project, and then adding the <code class="computeroutput"><span class="special">/</span><span class="identifier">interface</span></code> command line option to the regex.cxx
67+
source file.
68+
</p>
69+
<p>
70+
Known limitations:
71+
</p>
72+
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
73+
<li class="listitem">
74+
As of the start of 2025, only very recent versions of clang and msvc are
75+
supported. GCC is definitely not supported.
76+
</li>
77+
<li class="listitem">
78+
The regex library must always be consumed via <code class="computeroutput"><span class="identifier">import</span>
79+
<span class="identifier">boost</span><span class="special">.</span><span class="identifier">regex</span><span class="special">;</span></code>
80+
and you can never mix this with <code class="computeroutput"><span class="preprocessor">#includes</span>
81+
<span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">regex</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>.
82+
</li>
83+
<li class="listitem">
84+
Ideally the standard library should always be used via <code class="computeroutput"><span class="identifier">import</span>
85+
<span class="identifier">std</span></code> and not via #includes: more
86+
recent compilers are mostly making this work, but are still very fragile.
87+
</li>
88+
<li class="listitem">
89+
The regex version imported, is always the "standalone" version
90+
which includes no other Boost headers.
91+
</li>
92+
</ul></div>
93+
<p>
94+
Finally... there are some build and test scripts in <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">regex</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">module</span></code>
95+
for msvc and clang.
96+
</p>
97+
</div>
98+
<div class="copyright-footer">Copyright © 1998-2013 John Maddock<p>
99+
Distributed under the Boost Software License, Version 1.0. (See accompanying
100+
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
101+
</p>
102+
</div>
103+
<hr>
104+
<div class="spirit-nav">
105+
<a accesskey="p" href="install.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="intro.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
106+
</div>
107+
</body>
108+
</html>

doc/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<dt><span class="section"><a href="boost_regex/configuration/tuning.html">Algorithm Tuning</a></span></dt>
5151
</dl></dd>
5252
<dt><span class="section"><a href="boost_regex/install.html">Building and Installing the Library</a></span></dt>
53+
<dt><span class="section"><a href="boost_regex/modules.html">Module Support (Experimental)</a></span></dt>
5354
<dt><span class="section"><a href="boost_regex/intro.html">Introduction and Overview</a></span></dt>
5455
<dt><span class="section"><a href="boost_regex/unicode.html">Unicode and Boost.Regex</a></span></dt>
5556
<dt><span class="section"><a href="boost_regex/captures.html">Understanding Marked Sub-Expressions

doc/modules.qbk

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[/
2+
Copyright 2024 John Maddock.
3+
Distributed under the Boost Software License, Version 1.0.
4+
(See accompanying file LICENSE_1_0.txt or copy at
5+
http://www.boost.org/LICENSE_1_0.txt).
6+
]
7+
8+
[section:modules Module Support (Experimental)]
9+
10+
This library has experimental support for C++ modules (C++20 or later), currently the support is experimental
11+
not least because at the time of writing (2025) build tools have yet to catch up with module support.
12+
13+
In order to use this library as a module you simply add a:
14+
15+
```
16+
import boost.regex;
17+
```
18+
19+
to your code.
20+
21+
Before that you must first build the module, which consists of these steps:
22+
23+
* Depending on your compiler, you may need to build the standard library module, and place the standard module somewhere that your compiler can find it.
24+
* Build `libs/regex/module/regex.cxx` into the boost.regex module, and place the module definition file somewhere that your compiler can find it.
25+
* Build all the source files in `libs/regex/module` (including regex.cxx) into a library, and place the result somewhere your linker can find it.
26+
27+
Visual studio users can simplify all of the above into one step, by placing everything in `libs/regex/module` into a static library project, and then adding the `/interface`
28+
command line option to the regex.cxx source file.
29+
30+
Known limitations:
31+
32+
* As of the start of 2025, only very recent versions of clang and msvc are supported. GCC is definitely not supported.
33+
* The regex library must always be consumed via `import boost.regex;` and you can never mix this with `#includes <boost/regex.hpp>`.
34+
* Ideally the standard library should always be used via `import std` and not via #includes: more recent compilers are mostly making this work, but are still very fragile.
35+
* The regex version imported, is always the "standalone" version which includes no other Boost headers.
36+
37+
Finally... there are some build and test scripts in `libs/regex/test/module` for msvc and clang.
38+
39+
[endsect]
40+

doc/regex.qbk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ PDF version of this manual is also available].
5151

5252
[include configuration.qbk]
5353
[include install.qbk]
54+
[include modules.qbk]
5455
[include introduction.qbk]
5556
[include unicode.qbk]
5657
[include captures.qbk]

include/boost/regex/concepts.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <boost/type_traits/is_enum.hpp>
2525
#include <boost/type_traits/is_base_and_derived.hpp>
2626
#include <boost/static_assert.hpp>
27-
#ifndef BOOST_TEST_TR1_REGEX
27+
#if !defined(BOOST_TEST_TR1_REGEX) && !defined(BOOST_REGEX_TEST_MODULE)
2828
#include <boost/regex.hpp>
2929
#endif
3030
#include <bitset>
@@ -37,6 +37,16 @@
3737
#define RW_NS std
3838
#endif
3939

40+
41+
//
42+
// alter this to std::tr1, to test a std implementation:
43+
//
44+
#ifndef BOOST_TEST_TR1_REGEX
45+
namespace global_regex_namespace = ::boost;
46+
#else
47+
namespace global_regex_namespace = ::std::tr1;
48+
#endif
49+
4050
namespace boost{
4151

4252
//
@@ -178,15 +188,6 @@ struct regex_traits_architype
178188
regex_traits_architype& operator=(const regex_traits_architype&){ return *this; }
179189
};
180190

181-
//
182-
// alter this to std::tr1, to test a std implementation:
183-
//
184-
#ifndef BOOST_TEST_TR1_REGEX
185-
namespace global_regex_namespace = ::boost;
186-
#else
187-
namespace global_regex_namespace = ::std::tr1;
188-
#endif
189-
190191
template <class Bitmask>
191192
struct BitmaskConcept
192193
{
@@ -273,7 +274,7 @@ template <class Regex>
273274
struct regex_traits_computer;
274275

275276
template <class charT, class traits>
276-
struct regex_traits_computer< global_regex_namespace::basic_regex<charT, traits> >
277+
struct regex_traits_computer< ::boost::basic_regex<charT, traits> >
277278
{
278279
typedef traits type;
279280
};

include/boost/regex/config.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
#endif
3030
#endif
3131

32+
#ifndef BOOST_REGEX_MODULE_EXPORT
33+
#define BOOST_REGEX_MODULE_EXPORT
34+
#define BOOST_REGEX_STATIC_CONST static const
35+
#else
36+
#define BOOST_REGEX_STATIC_CONST inline constexpr
37+
#define BOOST_REGEX_STANDALONE
38+
#endif
39+
40+
/*
41+
* Borland C++ Fix/error check
42+
* this has to go *before* we include any std lib headers:
43+
*/
44+
#if defined(__BORLANDC__) && !defined(__clang__)
45+
# include <boost/regex/config/borland.hpp>
46+
#endif
47+
3248
#ifndef BOOST_REGEX_STANDALONE
3349
#include <boost/version.hpp>
3450
#endif
@@ -40,9 +56,13 @@
4056
*************************************************************************/
4157

4258
#ifdef BOOST_REGEX_STANDALONE
59+
#ifndef BOOST_REGEX_AS_MODULE
4360
#include <cassert>
4461
# define BOOST_REGEX_ASSERT(x) assert(x)
4562
#else
63+
# define BOOST_REGEX_ASSERT(x) do{ if(x == 0) { std::printf("%s:%d Assertion Failed", __FILE__, __LINE__); std::abort(); } }while(0)
64+
#endif
65+
#else
4666
#include <boost/assert.hpp>
4767
# define BOOST_REGEX_ASSERT(x) BOOST_ASSERT(x)
4868
#endif
@@ -284,8 +304,6 @@
284304
* If there are no exceptions then we must report critical-errors
285305
* the only way we know how; by terminating.
286306
*/
287-
#include <cassert>
288-
289307
# define BOOST_REGEX_NOEH_ASSERT(x) assert(x);
290308
#else
291309
/*

0 commit comments

Comments
 (0)