Skip to content

Commit f6577ec

Browse files
committed
deprecate accumulators::sum::small and ::large as workaround for bug in windows.h (#343)
1 parent dcd2315 commit f6577ec

File tree

9 files changed

+69
-17
lines changed

9 files changed

+69
-17
lines changed

include/boost/histogram/accumulators/ostream.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>&
6363
template <class CharT, class Traits, class U>
6464
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os,
6565
const sum<U>& x) {
66-
if (os.width() == 0) return os << "sum(" << x.large() << " + " << x.small() << ")";
66+
if (os.width() == 0)
67+
return os << "sum(" << x.large_part() << " + " << x.small_part() << ")";
6768
return detail::handle_nonzero_width(os, x);
6869
}
6970

include/boost/histogram/accumulators/sum.hpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class sum {
4343

4444
/// Allow implicit conversion from sum<T>
4545
template <class T>
46-
sum(const sum<T>& s) noexcept : sum(s.large(), s.small()) {}
46+
sum(const sum<T>& s) noexcept : sum(s.large_part(), s.small_part()) {}
4747

4848
/// Initialize sum explicitly with large and small parts
49-
sum(const_reference large, const_reference small) noexcept
50-
: large_(large), small_(small) {}
49+
sum(const_reference large_part, const_reference small_part) noexcept
50+
: large_(large_part), small_(small_part) {}
5151

5252
/// Increment sum by one
5353
sum& operator++() noexcept { return operator+=(1); }
@@ -96,10 +96,10 @@ class sum {
9696
value_type value() const noexcept { return large_ + small_; }
9797

9898
/// Return large part of the sum.
99-
const_reference large() const noexcept { return large_; }
99+
const_reference large_part() const noexcept { return large_; }
100100

101101
/// Return small part of the sum.
102-
const_reference small() const noexcept { return small_; }
102+
const_reference small_part() const noexcept { return small_; }
103103

104104
// lossy conversion to value type must be explicit
105105
explicit operator value_type() const noexcept { return value(); }
@@ -156,6 +156,25 @@ class sum {
156156

157157
// end: extra operators
158158

159+
// windows.h illegially uses `#define small char` which breaks this now deprecated API
160+
#if !defined(small)
161+
162+
/// Return large part of the sum.
163+
[[deprecated("use large_part() instead; "
164+
"large() will be removed in boost-1.80")]] const_reference
165+
large() const noexcept {
166+
return large_;
167+
}
168+
169+
/// Return small part of the sum.
170+
[[deprecated("use small_part() instead; "
171+
"small() will be removed in boost-1.80")]] const_reference
172+
small() const noexcept {
173+
return small_;
174+
}
175+
176+
#endif
177+
159178
private:
160179
value_type large_{};
161180
value_type small_{};

include/boost/histogram/algorithm/reduce.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace algorithm {
3333
*/
3434
using reduce_command = detail::reduce_command;
3535

36-
using reduce_option [[deprecated("use reduce_command instead")]] =
36+
using reduce_option [[deprecated("use reduce_command instead; "
37+
"reduce_option will be removed in boost-1.80")]] =
3738
reduce_command; ///< deprecated
3839

3940
/** Shrink command to be used in `reduce`.

include/boost/histogram/axis/traits.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ template <class Axis>
194194
using get_options = decltype(detail::traits_options<Axis>(detail::priority<2>{}));
195195

196196
template <class Axis>
197-
using static_options [[deprecated("use get_options instead")]] = get_options<Axis>;
197+
using static_options [[deprecated("use get_options instead; "
198+
"static_options will be removed in boost-1.80")]] =
199+
get_options<Axis>;
198200

199201
#else
200202
struct get_options;
@@ -223,7 +225,10 @@ template <class Axis>
223225
using is_inclusive = decltype(detail::traits_is_inclusive<Axis>(detail::priority<1>{}));
224226

225227
template <class Axis>
226-
using static_is_inclusive [[deprecated("use is_inclusive instead")]] = is_inclusive<Axis>;
228+
using static_is_inclusive
229+
[[deprecated("use is_inclusive instead; "
230+
"static_is_inclusive will be removed in boost-1.80")]] =
231+
is_inclusive<Axis>;
227232

228233
#else
229234
struct is_inclusive;

include/boost/histogram/indexed.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class BOOST_ATTRIBUTE_NODISCARD indexed_range {
6464
using value_type = typename std::iterator_traits<value_iterator>::value_type;
6565

6666
class iterator;
67-
using range_iterator [[deprecated("use iterator instead")]] = iterator; ///< deprecated
67+
using range_iterator [[deprecated("use iterator instead; "
68+
"range_iterator will be removed in boost-1.80")]] =
69+
iterator; ///< deprecated
6870

6971
/** Lightweight view to access value and index of current cell.
7072
@@ -84,7 +86,8 @@ class BOOST_ATTRIBUTE_NODISCARD indexed_range {
8486

8587
public:
8688
using const_reference = const axis::index_type&;
87-
using reference [[deprecated("use const_reference instead")]] =
89+
using reference [[deprecated("use const_reference instead; "
90+
"reference will be removed in boost-1.80")]] =
8891
const_reference; ///< deprecated
8992

9093
/// implementation detail

test/Jamfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,14 @@ alias libserial :
157157
# for builds without optional boost dependencies
158158
alias minimal : cxx14 cxx17 failure threading ;
159159

160+
# for builds with optional boost dependencies
161+
alias optional_boost : accumulators range units serialization ;
162+
160163
# all tests
161-
alias all : minimal not_windows odr accumulators range units serialization ;
164+
alias all : minimal not_windows odr optional_boost ;
162165

163166
# all except "failure", because it is distracting during development
164-
alias develop : cxx14 cxx17 threading not_windows odr accumulators range units serialization ;
167+
alias develop : odr cxx14 cxx17 threading not_windows optional_boost ;
165168

166169
explicit minimal ;
167170
explicit all ;
@@ -176,3 +179,4 @@ explicit range ;
176179
explicit units ;
177180
explicit serialization ;
178181
explicit libserial ;
182+
explicit optional_boost ;

test/accumulators_sum_test.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ int main() {
2626
++sum;
2727
BOOST_TEST_EQ(sum, 1);
2828
BOOST_TEST_EQ(sum.value(), 1);
29-
BOOST_TEST_EQ(sum.large(), 1);
30-
BOOST_TEST_EQ(sum.small(), 0);
29+
BOOST_TEST_EQ(sum.large_part(), 1);
30+
BOOST_TEST_EQ(sum.small_part(), 0);
3131
BOOST_TEST_EQ(str(sum), "sum(1 + 0)"s);
3232
BOOST_TEST_EQ(str(sum, 15, false), " sum(1 + 0)"s);
3333
BOOST_TEST_EQ(str(sum, 15, true), "sum(1 + 0) "s);
3434

35+
#include <boost/histogram/detail/ignore_deprecation_warning_begin.hpp>
36+
37+
BOOST_TEST_EQ(sum.large(), 1);
38+
BOOST_TEST_EQ(sum.small(), 0);
39+
40+
#include <boost/histogram/detail/ignore_deprecation_warning_end.hpp>
41+
3542
sum += 1e100;
3643
BOOST_TEST_EQ(sum, (s_t{1e100, 1}));
3744
++sum;
@@ -40,8 +47,8 @@ int main() {
4047
BOOST_TEST_EQ(sum, (s_t{0, 2}));
4148
BOOST_TEST_EQ(sum, 2); // correct answer
4249
BOOST_TEST_EQ(sum.value(), 2);
43-
BOOST_TEST_EQ(sum.large(), 0);
44-
BOOST_TEST_EQ(sum.small(), 2);
50+
BOOST_TEST_EQ(sum.large_part(), 0);
51+
BOOST_TEST_EQ(sum.small_part(), 2);
4552

4653
sum = s_t{1e100, 1};
4754
sum += s_t{1e100, 1};

test/issue_327_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright 2021 Hans Dembinski
2+
//
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
17
#include <boost/core/lightweight_test.hpp>
28
#include <boost/histogram.hpp>
39
#include <boost/histogram/ostream.hpp>

test/odr_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
// (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
66

7+
// The header windows.h and possibly others illegially do the following
8+
#define small char
9+
// which violates the C++ standard. We make sure here that including our headers work
10+
// nevertheless by avoiding the preprocessing token `small`. For more details, see
11+
// https://github.com/boostorg/histogram/issues/342
12+
713
// include all Boost.Histogram header here; see odr_main_test.cpp for details
814
#include <boost/histogram.hpp>
915
#include <boost/histogram/ostream.hpp>

0 commit comments

Comments
 (0)