Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use concepts
  • Loading branch information
mborland committed Nov 22, 2023
commit 36521a8c23ecb8d112ab89582dd0c1e416781220
190 changes: 95 additions & 95 deletions include/boost/decimal/decimal128.hpp

Large diffs are not rendered by default.

192 changes: 96 additions & 96 deletions include/boost/decimal/decimal32.hpp

Large diffs are not rendered by default.

190 changes: 95 additions & 95 deletions include/boost/decimal/decimal64.hpp

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions include/boost/decimal/detail/comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#include <boost/decimal/detail/to_decimal.hpp>
#include <boost/decimal/detail/shrink_significand.hpp>
#include <boost/decimal/detail/cmath/isfinite.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <cstdint>

namespace boost {
namespace decimal {

template <typename DecimalType = decimal32, typename T1, typename T2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType = decimal32, typename T1, typename T2>
constexpr auto equal_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
T2 rhs_sig, std::int32_t rhs_exp, bool rhs_sign) noexcept -> bool
{
Expand All @@ -44,7 +45,7 @@ constexpr auto equal_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
new_lhs_sig == new_rhs_sig;
}

template <typename Decimal, typename Integer>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL Integer>
constexpr auto mixed_equality_impl(Decimal lhs, Integer rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal> && detail::is_integral_v<Integer>), bool>
{
Expand All @@ -68,7 +69,7 @@ constexpr auto mixed_equality_impl(Decimal lhs, Integer rhs) noexcept
rhs_significand, INT32_C(0), rhs_isneg);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto mixed_decimal_equality_impl(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
Expand All @@ -87,23 +88,23 @@ constexpr auto mixed_decimal_equality_impl(Decimal1 lhs, Decimal2 rhs) noexcept
return new_lhs == new_rhs;
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator==(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
{
return mixed_decimal_equality_impl(lhs, rhs);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator!=(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
{
return !(mixed_decimal_equality_impl(lhs, rhs));
}

template <typename DecimalType = decimal32, typename T1, typename T2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType = decimal32, typename T1, typename T2>
constexpr auto less_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
T2 rhs_sig, std::int32_t rhs_exp, bool rhs_sign) noexcept -> bool
{
Expand Down Expand Up @@ -163,7 +164,7 @@ constexpr auto less_parts_impl(T1 lhs_sig, std::int32_t lhs_exp, bool lhs_sign,
}
}

template <typename Decimal, typename Integer>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL Integer>
constexpr auto less_impl(Decimal lhs, Integer rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal> && detail::is_integral_v<Integer>), bool>
{
Expand Down Expand Up @@ -209,7 +210,7 @@ constexpr auto less_impl(Decimal lhs, Integer rhs) noexcept
rhs_significand, INT32_C(0), rhs_sign);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto mixed_decimal_less_impl(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
Expand Down Expand Up @@ -240,15 +241,15 @@ constexpr auto mixed_decimal_less_impl(Decimal1 lhs, Decimal2 rhs) noexcept
rhs.full_significand(), rhs.biased_exponent(), rhs.isneg());
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator<(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
{
return mixed_decimal_less_impl(lhs, rhs);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator<=(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
Expand All @@ -261,15 +262,15 @@ constexpr auto operator<=(Decimal1 lhs, Decimal2 rhs) noexcept
return !(rhs < lhs);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator>(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
{
return rhs < lhs;
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator>=(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), bool>
Expand All @@ -284,7 +285,7 @@ constexpr auto operator>=(Decimal1 lhs, Decimal2 rhs) noexcept

#ifdef BOOST_DECIMAL_HAS_SPACESHIP_OPERATOR

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator<=>(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>), std::partial_ordering>
Expand Down
6 changes: 3 additions & 3 deletions include/boost/decimal/detail/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ BOOST_DECIMAL_HAS_MEMBER_FUNCTION(imag)
} // Namespace detail

template <typename T>
concept integral = std::is_integral_v<T>;
concept integral = boost::decimal::detail::is_integral_v<T>;

template <typename T>
concept signed_integral = integral<T> && std::is_signed_v<T>;
Expand All @@ -94,7 +94,7 @@ template <typename T>
concept unsigned_integral = integral<T> && std::is_unsigned_v<T>;

template <typename T>
concept real = std::is_floating_point_v<T>;
concept real = boost::decimal::detail::is_floating_point_v<T>;

template <typename T>
concept complex = std::is_same_v<T, std::complex<float>>
Expand Down Expand Up @@ -197,7 +197,7 @@ concept random_access_container = is_container<T> &&
boost::decimal::concepts::random_access_iterator<typename T::iterator>;

template <typename T>
concept decimal_floating_point_type = detail::is_decimal_floating_point_v<T>;
concept decimal_floating_point_type = boost::decimal::detail::is_decimal_floating_point_v<T>;

} // boost::decimal::concepts

Expand Down
4 changes: 2 additions & 2 deletions include/boost/decimal/detail/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace boost {
namespace decimal {

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

// 3.2.11 Formatted output
template <typename charT, typename traits, typename DecimalType>
template <typename charT, typename traits, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE DecimalType>
auto operator<<(std::basic_ostream<charT, traits>& os, const DecimalType& d)
-> std::enable_if_t<detail::is_decimal_floating_point_v<DecimalType>, std::basic_ostream<charT, traits>&>
{
Expand Down
9 changes: 5 additions & 4 deletions include/boost/decimal/detail/mixed_decimal_arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include <boost/decimal/detail/attributes.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>

namespace boost {
namespace decimal {

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator+(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>),
Expand All @@ -24,7 +25,7 @@ constexpr auto operator+(Decimal1 lhs, Decimal2 rhs) noexcept
return static_cast<Promoted_Type>(lhs) + static_cast<Promoted_Type>(rhs);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator-(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>),
Expand All @@ -34,7 +35,7 @@ constexpr auto operator-(Decimal1 lhs, Decimal2 rhs) noexcept
return static_cast<Promoted_Type>(lhs) - static_cast<Promoted_Type>(rhs);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator*(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>),
Expand All @@ -44,7 +45,7 @@ constexpr auto operator*(Decimal1 lhs, Decimal2 rhs) noexcept
return static_cast<Promoted_Type>(lhs) * static_cast<Promoted_Type>(rhs);
}

template <typename Decimal1, typename Decimal2>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal2>
constexpr auto operator/(Decimal1 lhs, Decimal2 rhs) noexcept
-> std::enable_if_t<(detail::is_decimal_floating_point_v<Decimal1> &&
detail::is_decimal_floating_point_v<Decimal2>),
Expand Down
5 changes: 3 additions & 2 deletions include/boost/decimal/detail/to_decimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/config.hpp>
#include <boost/decimal/detail/attributes.hpp>
#include <boost/decimal/detail/concepts.hpp>

namespace boost {
namespace decimal {

#ifndef BOOST_DECIMAL_NO_CXX17_IF_CONSTEXPR

template <typename TargetType, typename Decimal>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetType, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal>
constexpr auto to_decimal(Decimal val) noexcept -> TargetType
{
if (isinf(val))
Expand Down Expand Up @@ -48,7 +49,7 @@ constexpr auto to_decimal(Decimal val) noexcept -> TargetType

#else

template <typename TargetType, typename Decimal>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE TargetType, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal>
constexpr auto to_decimal(Decimal val) noexcept -> TargetType
{
if (isinf(val))
Expand Down
3 changes: 2 additions & 1 deletion include/boost/decimal/detail/to_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
#include <boost/decimal/detail/fast_float/compute_float32.hpp>
#include <boost/decimal/detail/fast_float/compute_float64.hpp>
#include <boost/decimal/detail/fast_float/compute_float80_128.hpp>
#include <boost/decimal/detail/concepts.hpp>

namespace boost {
namespace decimal {

template <typename Decimal, typename TargetType>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_REAL TargetType>
BOOST_DECIMAL_CXX20_CONSTEXPR auto to_float(Decimal val) noexcept -> TargetType
{
bool success {};
Expand Down
5 changes: 3 additions & 2 deletions include/boost/decimal/detail/to_integral.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/power_tables.hpp>
#include <boost/decimal/detail/apply_sign.hpp>
#include <boost/decimal/detail/concepts.hpp>

namespace boost {
namespace decimal {
Expand All @@ -25,7 +26,7 @@ namespace decimal {
// Attempts conversion to integral type:
// If this is nan sets errno to EINVAL and returns 0
// If this is not representable sets errno to ERANGE and returns 0
template <typename Decimal, typename TargetType>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL TargetType>
constexpr auto to_integral(Decimal val) noexcept -> TargetType
{
using Conversion_Type = std::conditional_t<std::numeric_limits<TargetType>::is_signed, std::int64_t, std::uint64_t>;
Expand Down Expand Up @@ -63,7 +64,7 @@ constexpr auto to_integral(Decimal val) noexcept -> TargetType
return static_cast<TargetType>(result);
}

template <typename Decimal, typename TargetType>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE Decimal, BOOST_DECIMAL_INTEGRAL TargetType>
constexpr auto to_integral_128(Decimal val) noexcept -> TargetType
{
constexpr Decimal max_target_type { (std::numeric_limits<TargetType>::max)() };
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ project : requirements
[ requires cxx14_decltype_auto cxx14_generic_lambdas cxx14_return_type_deduction cxx14_variable_templates cxx14_constexpr ]
;

compile-fail concepts_test.cpp ;
run ibm_abs.cpp ;
run ibm_add.cpp ;
run quick.cpp ;
Expand Down
24 changes: 24 additions & 0 deletions test/concepts_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>

template <typename T>
void test()
{
T res = T(1.0) + 1.0;
BOOST_TEST_EQ(res, T(2.0));
}


int main()
{
test<boost::decimal::decimal32>();
//test<boost::decimal::decimal64>();
//test<boost::decimal::decimal128>();

return boost::report_errors();
}