Skip to content

Commit 36521a8

Browse files
committed
Use concepts
1 parent 7a0cec6 commit 36521a8

File tree

12 files changed

+343
-313
lines changed

12 files changed

+343
-313
lines changed

include/boost/decimal/decimal128.hpp

Lines changed: 95 additions & 95 deletions
Large diffs are not rendered by default.

include/boost/decimal/decimal32.hpp

Lines changed: 96 additions & 96 deletions
Large diffs are not rendered by default.

include/boost/decimal/decimal64.hpp

Lines changed: 95 additions & 95 deletions
Large diffs are not rendered by default.

include/boost/decimal/detail/comparison.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
#include <boost/decimal/detail/to_decimal.hpp>
1414
#include <boost/decimal/detail/shrink_significand.hpp>
1515
#include <boost/decimal/detail/cmath/isfinite.hpp>
16+
#include <boost/decimal/detail/concepts.hpp>
1617
#include <cstdint>
1718

1819
namespace boost {
1920
namespace decimal {
2021

21-
template <typename DecimalType = decimal32, typename T1, typename T2>
22+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType = decimal32, typename T1, typename T2>
2223
constexpr auto equal_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
2324
T2 rhs_sig, std::int32_t rhs_exp, bool rhs_sign) noexcept -> bool
2425
{
@@ -44,7 +45,7 @@ constexpr auto equal_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
4445
new_lhs_sig == new_rhs_sig;
4546
}
4647

47-
template <typename Decimal, typename Integer>
48+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL Integer>
4849
constexpr auto mixed_equality_impl(Decimal lhs, Integer rhs) noexcept
4950
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal> && detail::is_integral_v<Integer>), bool>
5051
{
@@ -68,7 +69,7 @@ constexpr auto mixed_equality_impl(Decimal lhs, Integer rhs) noexcept
6869
rhs_significand, INT32_C(0), rhs_isneg);
6970
}
7071

71-
template <typename Decimal1, typename Decimal2>
72+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
7273
constexpr auto mixed_decimal_equality_impl(Decimal1 lhs, Decimal2 rhs) noexcept
7374
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
7475
detail::is_decimal_floating_point_v<Decimal2>), bool>
@@ -87,23 +88,23 @@ constexpr auto mixed_decimal_equality_impl(Decimal1 lhs, Decimal2 rhs) noexcept
8788
return new_lhs == new_rhs;
8889
}
8990

90-
template <typename Decimal1, typename Decimal2>
91+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
9192
constexpr auto operator==(Decimal1 lhs, Decimal2 rhs) noexcept
9293
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
9394
detail::is_decimal_floating_point_v<Decimal2>), bool>
9495
{
9596
return mixed_decimal_equality_impl(lhs, rhs);
9697
}
9798

98-
template <typename Decimal1, typename Decimal2>
99+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
99100
constexpr auto operator!=(Decimal1 lhs, Decimal2 rhs) noexcept
100101
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
101102
detail::is_decimal_floating_point_v<Decimal2>), bool>
102103
{
103104
return !(mixed_decimal_equality_impl(lhs, rhs));
104105
}
105106

106-
template <typename DecimalType = decimal32, typename T1, typename T2>
107+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType = decimal32, typename T1, typename T2>
107108
constexpr auto less_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
108109
T2 rhs_sig, std::int32_t rhs_exp, bool rhs_sign) noexcept -> bool
109110
{
@@ -163,7 +164,7 @@ constexpr auto less_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
163164
}
164165
}
165166

166-
template <typename Decimal, typename Integer>
167+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL Integer>
167168
constexpr auto less_impl(Decimal lhs, Integer rhs) noexcept
168169
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal> && detail::is_integral_v<Integer>), bool>
169170
{
@@ -209,7 +210,7 @@ constexpr auto less_impl(Decimal lhs, Integer rhs) noexcept
209210
rhs_significand, INT32_C(0), rhs_sign);
210211
}
211212

212-
template <typename Decimal1, typename Decimal2>
213+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
213214
constexpr auto mixed_decimal_less_impl(Decimal1 lhs, Decimal2 rhs) noexcept
214215
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
215216
detail::is_decimal_floating_point_v<Decimal2>), bool>
@@ -240,15 +241,15 @@ constexpr auto mixed_decimal_less_impl(Decimal1 lhs, Decimal2 rhs) noexcept
240241
rhs.full_significand(), rhs.biased_exponent(), rhs.isneg());
241242
}
242243

243-
template <typename Decimal1, typename Decimal2>
244+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
244245
constexpr auto operator<(Decimal1 lhs, Decimal2 rhs) noexcept
245246
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
246247
detail::is_decimal_floating_point_v<Decimal2>), bool>
247248
{
248249
return mixed_decimal_less_impl(lhs, rhs);
249250
}
250251

251-
template <typename Decimal1, typename Decimal2>
252+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
252253
constexpr auto operator<=(Decimal1 lhs, Decimal2 rhs) noexcept
253254
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
254255
detail::is_decimal_floating_point_v<Decimal2>), bool>
@@ -261,15 +262,15 @@ constexpr auto operator<=(Decimal1 lhs, Decimal2 rhs) noexcept
261262
return !(rhs < lhs);
262263
}
263264

264-
template <typename Decimal1, typename Decimal2>
265+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
265266
constexpr auto operator>(Decimal1 lhs, Decimal2 rhs) noexcept
266267
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
267268
detail::is_decimal_floating_point_v<Decimal2>), bool>
268269
{
269270
return rhs < lhs;
270271
}
271272

272-
template <typename Decimal1, typename Decimal2>
273+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
273274
constexpr auto operator>=(Decimal1 lhs, Decimal2 rhs) noexcept
274275
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
275276
detail::is_decimal_floating_point_v<Decimal2>), bool>
@@ -284,7 +285,7 @@ constexpr auto operator>=(Decimal1 lhs, Decimal2 rhs) noexcept
284285

285286
#ifdef BOOST_DECIMAL_HAS_SPACESHIP_OPERATOR
286287

287-
template <typename Decimal1, typename Decimal2>
288+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
288289
constexpr auto operator<=>(Decimal1 lhs, Decimal2 rhs) noexcept
289290
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
290291
detail::is_decimal_floating_point_v<Decimal2>), std::partial_ordering>

include/boost/decimal/detail/concepts.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ BOOST_DECIMAL_HAS_MEMBER_FUNCTION(imag)
8585
} // Namespace detail
8686

8787
template <typename T>
88-
concept integral = std::is_integral_v<T>;
88+
concept integral = boost::decimal::detail::is_integral_v<T>;
8989

9090
template <typename T>
9191
concept signed_integral = integral<T> && std::is_signed_v<T>;
@@ -94,7 +94,7 @@ template <typename T>
9494
concept unsigned_integral = integral<T> && std::is_unsigned_v<T>;
9595

9696
template <typename T>
97-
concept real = std::is_floating_point_v<T>;
97+
concept real = boost::decimal::detail::is_floating_point_v<T>;
9898

9999
template <typename T>
100100
concept complex = std::is_same_v<T, std::complex<float>>
@@ -197,7 +197,7 @@ concept random_access_container = is_container<T> &&
197197
boost::decimal::concepts::random_access_iterator<typename T::iterator>;
198198

199199
template <typename T>
200-
concept decimal_floating_point_type = detail::is_decimal_floating_point_v<T>;
200+
concept decimal_floating_point_type = boost::decimal::detail::is_decimal_floating_point_v<T>;
201201

202202
} // boost::decimal::concepts
203203

include/boost/decimal/detail/io.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace boost {
2727
namespace decimal {
2828

2929
// 3.2.10 Formatted input:
30-
template <typename charT, typename traits, typename DecimalType>
30+
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
3131
auto operator>>(std::basic_istream<charT, traits>& is, DecimalType& d)
3232
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_istream<charT, traits>&>
3333
{
@@ -106,7 +106,7 @@ void print_buffer(char* buffer, std::size_t buffer_size, const char*, Integer si
106106
}
107107

108108
// 3.2.11 Formatted output
109-
template <typename charT, typename traits, typename DecimalType>
109+
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
110110
auto operator<<(std::basic_ostream<charT, traits>& os, const DecimalType& d)
111111
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_ostream<charT, traits>&>
112112
{

include/boost/decimal/detail/mixed_decimal_arithmetic.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
#include <boost/decimal/detail/attributes.hpp>
1010
#include <boost/decimal/detail/type_traits.hpp>
1111
#include <boost/decimal/detail/promotion.hpp>
12+
#include <boost/decimal/detail/concepts.hpp>
1213
#include <type_traits>
1314

1415
namespace boost {
1516
namespace decimal {
1617

17-
template <typename Decimal1, typename Decimal2>
18+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
1819
constexpr auto operator+(Decimal1 lhs, Decimal2 rhs) noexcept
1920
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
2021
detail::is_decimal_floating_point_v<Decimal2>),
@@ -24,7 +25,7 @@ constexpr auto operator+(Decimal1 lhs, Decimal2 rhs) noexcept
2425
return static_cast<Promoted_Type>(lhs) + static_cast<Promoted_Type>(rhs);
2526
}
2627

27-
template <typename Decimal1, typename Decimal2>
28+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
2829
constexpr auto operator-(Decimal1 lhs, Decimal2 rhs) noexcept
2930
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
3031
detail::is_decimal_floating_point_v<Decimal2>),
@@ -34,7 +35,7 @@ constexpr auto operator-(Decimal1 lhs, Decimal2 rhs) noexcept
3435
return static_cast<Promoted_Type>(lhs) - static_cast<Promoted_Type>(rhs);
3536
}
3637

37-
template <typename Decimal1, typename Decimal2>
38+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
3839
constexpr auto operator*(Decimal1 lhs, Decimal2 rhs) noexcept
3940
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
4041
detail::is_decimal_floating_point_v<Decimal2>),
@@ -44,7 +45,7 @@ constexpr auto operator*(Decimal1 lhs, Decimal2 rhs) noexcept
4445
return static_cast<Promoted_Type>(lhs) * static_cast<Promoted_Type>(rhs);
4546
}
4647

47-
template <typename Decimal1, typename Decimal2>
48+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
4849
constexpr auto operator/(Decimal1 lhs, Decimal2 rhs) noexcept
4950
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
5051
detail::is_decimal_floating_point_v<Decimal2>),

include/boost/decimal/detail/to_decimal.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
#include <boost/decimal/fwd.hpp>
1212
#include <boost/decimal/detail/config.hpp>
1313
#include <boost/decimal/detail/attributes.hpp>
14+
#include <boost/decimal/detail/concepts.hpp>
1415

1516
namespace boost {
1617
namespace decimal {
1718

1819
#ifndef BOOST_DECIMAL_NO_CXX17_IF_CONSTEXPR
1920

20-
template <typename TargetType, typename Decimal>
21+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetType, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal>
2122
constexpr auto to_decimal(Decimal val) noexcept -> TargetType
2223
{
2324
if (isinf(val))
@@ -48,7 +49,7 @@ constexpr auto to_decimal(Decimal val) noexcept -> TargetType
4849

4950
#else
5051

51-
template <typename TargetType, typename Decimal>
52+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetType, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal>
5253
constexpr auto to_decimal(Decimal val) noexcept -> TargetType
5354
{
5455
if (isinf(val))

include/boost/decimal/detail/to_float.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
#include <boost/decimal/detail/fast_float/compute_float32.hpp>
1515
#include <boost/decimal/detail/fast_float/compute_float64.hpp>
1616
#include <boost/decimal/detail/fast_float/compute_float80_128.hpp>
17+
#include <boost/decimal/detail/concepts.hpp>
1718

1819
namespace boost {
1920
namespace decimal {
2021

21-
template <typename Decimal, typename TargetType>
22+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_REAL TargetType>
2223
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_float(Decimal val) noexcept -> TargetType
2324
{
2425
bool success {};

include/boost/decimal/detail/to_integral.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <boost/decimal/detail/type_traits.hpp>
1212
#include <boost/decimal/detail/power_tables.hpp>
1313
#include <boost/decimal/detail/apply_sign.hpp>
14+
#include <boost/decimal/detail/concepts.hpp>
1415

1516
namespace boost {
1617
namespace decimal {
@@ -25,7 +26,7 @@ namespace decimal {
2526
// Attempts conversion to integral type:
2627
// If this is nan sets errno to EINVAL and returns 0
2728
// If this is not representable sets errno to ERANGE and returns 0
28-
template <typename Decimal, typename TargetType>
29+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL TargetType>
2930
constexpr auto to_integral(Decimal val) noexcept -> TargetType
3031
{
3132
using Conversion_Type = std::conditional_t<std::numeric_limits<TargetType>::is_signed, std::int64_t, std::uint64_t>;
@@ -63,7 +64,7 @@ constexpr auto to_integral(Decimal val) noexcept -> TargetType
6364
return static_cast<TargetType>(result);
6465
}
6566

66-
template <typename Decimal, typename TargetType>
67+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL TargetType>
6768
constexpr auto to_integral_128(Decimal val) noexcept -> TargetType
6869
{
6970
constexpr Decimal max_target_type { (std::numeric_limits<TargetType>::max)() };

0 commit comments

Comments
 (0)