Skip to content

Commit ce34d1e

Browse files
authored
Merge pull request #136 from boostorg/develop
Merge to master for Boost 1.89
2 parents 2233847 + 4f9e990 commit ce34d1e

File tree

7 files changed

+86
-31
lines changed

7 files changed

+86
-31
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,22 @@ jobs:
9191
- toolset: gcc-11
9292
cxxstd: "11,14,17,20,23"
9393
address_model: 32,64
94-
os: ubuntu-22.04
94+
os: ubuntu-latest
95+
container: ubuntu:22.04
9596
install:
9697
- g++-11-multilib
9798
- toolset: gcc-12
9899
cxxstd: "11,14,17,20,23"
99100
address_model: 32,64
100-
os: ubuntu-22.04
101+
os: ubuntu-latest
102+
container: ubuntu:22.04
101103
install:
102104
- g++-12-multilib
103105
- toolset: gcc-12
104106
cxxstd: "11-gnu,14-gnu,17-gnu,20-gnu,23-gnu"
105107
address_model: 32,64
106-
os: ubuntu-22.04
108+
os: ubuntu-latest
109+
container: ubuntu:22.04
107110
install:
108111
- g++-12-multilib
109112

@@ -184,37 +187,43 @@ jobs:
184187
- toolset: clang
185188
compiler: clang++-11
186189
cxxstd: "11,14,17,20"
187-
os: ubuntu-22.04
190+
os: ubuntu-latest
191+
container: ubuntu:22.04
188192
install:
189193
- clang-11
190194
- toolset: clang
191195
compiler: clang++-12
192196
cxxstd: "11,14,17,20"
193-
os: ubuntu-22.04
197+
os: ubuntu-latest
198+
container: ubuntu:22.04
194199
install:
195200
- clang-12
196201
- toolset: clang
197202
compiler: clang++-13
198203
cxxstd: "11,14,17,20"
199-
os: ubuntu-22.04
204+
os: ubuntu-latest
205+
container: ubuntu:22.04
200206
install:
201207
- clang-13
202208
- toolset: clang
203209
compiler: clang++-14
204210
cxxstd: "11,14,17,20"
205-
os: ubuntu-22.04
211+
os: ubuntu-latest
212+
container: ubuntu:22.04
206213
install:
207214
- clang-14
208215
- toolset: clang
209216
compiler: clang++-14
210217
cxxstd: "11-gnu,14-gnu,17-gnu,20-gnu"
211-
os: ubuntu-22.04
218+
os: ubuntu-latest
219+
container: ubuntu:22.04
212220
install:
213221
- clang-14
214222
- toolset: clang
215223
compiler: clang++-15
216224
cxxstd: "11,14,17,20"
217-
os: ubuntu-22.04
225+
os: ubuntu-latest
226+
container: ubuntu:22.04
218227
install:
219228
- clang-15
220229
sources:
@@ -224,7 +233,8 @@ jobs:
224233
- toolset: clang
225234
compiler: clang++-15
226235
cxxstd: "11,14,17,20,2b"
227-
os: ubuntu-22.04
236+
os: ubuntu-latest
237+
container: ubuntu:22.04
228238
install:
229239
- clang-15
230240
- libc++-15-dev
@@ -455,10 +465,6 @@ jobs:
455465
fail-fast: false
456466
matrix:
457467
include:
458-
- toolset: msvc-14.2
459-
cxxstd: "14,17,latest"
460-
addrmd: 64
461-
os: windows-2019
462468
- toolset: msvc-14.3
463469
cxxstd: "17,20,latest"
464470
addrmd: 64
@@ -470,7 +476,7 @@ jobs:
470476
- toolset: gcc
471477
cxxstd: "11,14,17,2a"
472478
addrmd: 64
473-
os: windows-2019
479+
os: windows-latest
474480

475481
runs-on: ${{matrix.os}}
476482

@@ -510,10 +516,10 @@ jobs:
510516
fail-fast: false
511517
matrix:
512518
include:
513-
- os: ubuntu-22.04
514519
- os: ubuntu-24.04
515520
- os: macos-13
516521
- os: macos-14
522+
- os: macos-15
517523

518524
runs-on: ${{matrix.os}}
519525

CMakeLists.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ cmake_minimum_required(VERSION 3.5...3.16)
77

88
project(boost_random VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
99

10-
add_library(boost_random
11-
src/random_device.cpp
12-
)
10+
option(BOOST_RANDOM_ENABLE_RANDOM_DEVICE "Build boost::random_device" ON)
11+
12+
if(BOOST_RANDOM_ENABLE_RANDOM_DEVICE)
13+
add_library(boost_random
14+
src/random_device.cpp
15+
)
16+
set(_populate PUBLIC)
17+
else()
18+
add_library(boost_random INTERFACE)
19+
set(_populate INTERFACE)
20+
endif()
1321

1422
add_library(Boost::random ALIAS boost_random)
1523

16-
target_include_directories(boost_random PUBLIC include)
24+
target_include_directories(boost_random ${_populate} include)
1725

1826
target_link_libraries(boost_random
19-
PUBLIC
27+
${_populate}
2028
Boost::assert
2129
Boost::config
2230
Boost::core
@@ -30,18 +38,20 @@ target_link_libraries(boost_random
3038
Boost::utility
3139
)
3240

33-
target_compile_features(boost_random PUBLIC cxx_std_11)
41+
target_compile_features(boost_random ${_populate} cxx_std_11)
3442

3543
target_compile_definitions(boost_random
36-
PUBLIC BOOST_RANDOM_NO_LIB
44+
${_populate} BOOST_RANDOM_NO_LIB
3745
# Source files already define BOOST_RANDOM_SOURCE
3846
# PRIVATE BOOST_RANDOM_SOURCE
3947
)
4048

41-
if(BUILD_SHARED_LIBS)
42-
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_DYN_LINK)
43-
else()
44-
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_STATIC_LINK)
49+
if(BOOST_RANDOM_ENABLE_RANDOM_DEVICE)
50+
if(BUILD_SHARED_LIBS)
51+
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_DYN_LINK)
52+
else()
53+
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_STATIC_LINK)
54+
endif()
4555
endif()
4656

4757
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")

build/Jamfile.v2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ lib boost_random
2424
: <link>shared:<define>BOOST_RANDOM_DYN_LINK=1
2525
<define>BOOST_RANDOM_SOURCE=1
2626

27-
[ requires cxx11_noexcept cxx11_rvalue_references sfinae_expr cxx11_auto_declarations cxx11_lambdas cxx11_unified_initialization_syntax cxx11_hdr_tuple cxx11_hdr_initializer_list cxx11_hdr_chrono cxx11_thread_local cxx11_constexpr cxx11_nullptr cxx11_numeric_limits cxx11_decltype cxx11_hdr_array cxx11_hdr_atomic cxx11_hdr_type_traits cxx11_allocator cxx11_explicit_conversion_operators ]
27+
[ requires cxx11_noexcept cxx11_rvalue_references sfinae_expr cxx11_auto_declarations cxx11_lambdas cxx11_unified_initialization_syntax cxx11_hdr_tuple cxx11_hdr_initializer_list cxx11_constexpr cxx11_nullptr cxx11_numeric_limits cxx11_decltype cxx11_hdr_array cxx11_hdr_type_traits cxx11_explicit_conversion_operators ]
2828

2929
# default-build
3030
:

include/boost/random/beta_distribution.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,18 @@ class beta_distribution {
101101
template<class URNG>
102102
RealType operator()(URNG& urng) const
103103
{
104-
RealType a = gamma_distribution<RealType>(_alpha, RealType(1.0))(urng);
105-
RealType b = gamma_distribution<RealType>(_beta, RealType(1.0))(urng);
104+
const auto alpha_dist = gamma_distribution<RealType>(_alpha, RealType(1.0));
105+
const auto beta_dist = gamma_distribution<RealType>(_beta, RealType(1.0));
106+
107+
RealType a = 0;
108+
RealType b = 0;
109+
110+
do
111+
{
112+
a = alpha_dist(urng);
113+
b = beta_dist(urng);
114+
} while (a + b == RealType(0));
115+
106116
return a / (a + b);
107117
}
108118

include/boost/random/gamma_distribution.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class gamma_distribution
159159
* the gamma distribution.
160160
*/
161161
template<class Engine>
162-
result_type operator()(Engine& eng)
162+
result_type operator()(Engine& eng) const
163163
{
164164
#ifndef BOOST_NO_STDC_NAMESPACE
165165
// allow for Koenig lookup

test/Jamfile.v2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ project /boost/random/test : requirements
1717
<library>/boost/random//boost_random
1818

1919
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
20+
21+
[ requires cxx11_noexcept cxx11_rvalue_references sfinae_expr cxx11_auto_declarations cxx11_lambdas cxx11_unified_initialization_syntax cxx11_hdr_tuple cxx11_hdr_initializer_list cxx11_constexpr cxx11_nullptr cxx11_numeric_limits cxx11_decltype cxx11_hdr_array cxx11_hdr_type_traits cxx11_explicit_conversion_operators ]
2022
;
2123

2224
run test_const_mod.cpp /boost/test//boost_unit_test_framework ;
@@ -84,6 +86,8 @@ run test_comp_xoshiro128mm.cpp ;
8486
run test_xoshiro128f.cpp /boost/test//boost_unit_test_framework ;
8587
run test_comp_xoshiro128f.cpp ;
8688

89+
run github_issue_133.cpp ;
90+
8791
run niederreiter_base2_validate.cpp /boost/test//boost_unit_test_framework ;
8892
run sobol_validate.cpp /boost/test//boost_unit_test_framework ;
8993
run faure_validate.cpp /boost/test//boost_unit_test_framework ;

test/github_issue_133.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2025 Matt Borland
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
//
5+
// See: https://github.com/boostorg/random/issues/133
6+
7+
#include <boost/core/lightweight_test.hpp>
8+
#include <boost/random/beta_distribution.hpp>
9+
#include <random>
10+
#include <cmath>
11+
12+
int main()
13+
{
14+
constexpr double beta_param = 0.0020368700639848774;
15+
boost::random::beta_distribution<double> dist(beta_param, beta_param);
16+
std::mt19937_64 gen(12345);
17+
18+
for (int i = 0; i < 10000; ++i)
19+
{
20+
const double Z = dist(gen);
21+
BOOST_TEST(!std::isnan(Z));
22+
}
23+
24+
return boost::report_errors();
25+
}

0 commit comments

Comments
 (0)