Skip to content

Commit

Permalink
Merge pull request #347 from cppalliance/concepts
Browse files Browse the repository at this point in the history
Implement concepts
  • Loading branch information
mborland authored Nov 22, 2023
2 parents beb2ad6 + ea1a1e1 commit a17135d
Show file tree
Hide file tree
Showing 58 changed files with 926 additions and 433 deletions.
196 changes: 98 additions & 98 deletions include/boost/decimal/decimal128.hpp

Large diffs are not rendered by default.

198 changes: 99 additions & 99 deletions include/boost/decimal/decimal32.hpp

Large diffs are not rendered by default.

196 changes: 98 additions & 98 deletions include/boost/decimal/decimal64.hpp

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/config.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
-> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/acosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/numbers.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto acosh(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
const auto fpc = fpclassify(x);
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/asinh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/numbers.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto asinh(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T> // NOLINT(misc-no-recursion)
{
T result { };
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/atanh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/numbers.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto atanh(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
T result { };
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/ceil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
#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>
#include <boost/decimal/detail/cmath/fpclassify.hpp>
#include <boost/decimal/detail/cmath/frexp10.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto ceil BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T val) noexcept
-> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/cos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
#include <boost/decimal/fwd.hpp>
#include <boost/decimal/numbers.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/detail/cmath/cos.hpp>
#include <boost/decimal/detail/cmath/remquo.hpp>
#include <boost/decimal/detail/cmath/impl/sin_impl.hpp>
#include <boost/decimal/detail/cmath/impl/cos_impl.hpp>
#include <type_traits>
#include <cstdint>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto cos(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T> // NOLINT(misc-no-recursion)
{
T result { };
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/cosh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/numbers.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto cosh(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T> // NOLINT(misc-no-recursion)
{
const auto fpc = fpclassify(x);
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/exp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/cmath/impl/pow_impl.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/numbers.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto exp(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T> // NOLINT(misc-no-recursion)
{
const auto fpc = fpclassify(x);
Expand Down
3 changes: 2 additions & 1 deletion include/boost/decimal/detail/cmath/exp2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#define BOOST_DECIMAL_DETAIL_CMATH_EXP2_HPP

#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/detail/cmath/pow.hpp>

namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto exp2(T num) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
constexpr T two {2, 0};
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/expm1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/numbers.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto expm1(T x) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T> // NOLINT(misc-no-recursion)
{
const auto fpc = fpclassify(x);
Expand Down
10 changes: 5 additions & 5 deletions include/boost/decimal/detail/cmath/fabs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

// TODO(mborland): Allow conversion between decimal types via a promotion system

template<typename T, std::enable_if_t<detail::is_decimal_floating_point_v<T>, bool> = true>
constexpr auto fabs(T a) noexcept -> T
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto fabs(T a) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
return abs(a);
}
Expand Down
8 changes: 5 additions & 3 deletions include/boost/decimal/detail/cmath/fdim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <limits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T, std::enable_if_t<detail::is_decimal_floating_point_v<T>, bool> = true>
constexpr auto fdim(T x, T y) noexcept -> T
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto fdim(T x, T y) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
constexpr T zero {0, 0};

Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include <boost/decimal/detail/cmath/fpclassify.hpp>
#include <boost/decimal/detail/cmath/frexp10.hpp>
#include <boost/decimal/detail/emulated128.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto floor BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T val) noexcept
-> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
Expand Down
11 changes: 6 additions & 5 deletions include/boost/decimal/detail/cmath/fmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

// TODO(mborland): Allow conversion between decimal types via a promotion system

template<typename T, std::enable_if_t<detail::is_decimal_floating_point_v<T>, bool> = true>
constexpr auto fmax(T lhs, T rhs) noexcept -> T
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto fmax(T lhs, T rhs) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
if (isnan(lhs) && !isnan(rhs))
{
Expand Down
8 changes: 5 additions & 3 deletions include/boost/decimal/detail/cmath/fmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T, std::enable_if_t<detail::is_decimal_floating_point_v<T>, bool> = true>
constexpr auto fmin(T lhs, T rhs) noexcept -> T
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto fmin(T lhs, T rhs) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
if (isnan(lhs) && !isnan(rhs))
{
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/fmod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto fmod(T lhs, T rhs) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
return lhs % rhs;
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/fpclassify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/config.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto fpclassify BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
-> std::enable_if_t<detail::is_decimal_floating_point_v<T>, int>
{
Expand Down
8 changes: 5 additions & 3 deletions include/boost/decimal/detail/cmath/frexp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/cmath/impl/pow_impl.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template<typename T, std::enable_if_t<detail::is_decimal_floating_point_v<T>, bool> = true>
constexpr auto frexp(T v, int* expon) noexcept -> T
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto frexp(T v, int* expon) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
// This implementation of frexp follows closely that of eval_frexp
// in Boost.Multiprecision's cpp_dec_float template class.
Expand Down
3 changes: 2 additions & 1 deletion include/boost/decimal/detail/cmath/frexp10.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/normalize.hpp>
#include <boost/decimal/detail/emulated128.hpp>
#include <boost/decimal/detail/concepts.hpp>

namespace boost {
namespace decimal {
Expand All @@ -19,7 +20,7 @@ namespace decimal {
// Returns num in the range [1'000'000, 9'999'999]
//
// If the conversion can not be performed returns UINT32_MAX and exp = 0
template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto frexp10(T num, int* expptr) noexcept
-> std::enable_if_t<detail::is_decimal_floating_point_v<T>,
std::conditional_t<std::is_same<T, decimal32>::value, std::uint32_t,
Expand Down
8 changes: 5 additions & 3 deletions include/boost/decimal/detail/cmath/hypot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
#include <boost/decimal/detail/cmath/sqrt.hpp>
#include <boost/decimal/detail/cmath/fmax.hpp>
#include <boost/decimal/detail/utilities.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto hypot(T x, T y) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
constexpr T zero {0, 0};
Expand Down Expand Up @@ -60,7 +62,7 @@ constexpr auto hypot(T x, T y) noexcept -> std::enable_if_t<detail::is_decimal_f
return x * sqrt(1 + rat * rat);
}

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto hypot(T x, T y, T z) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, T>
{
if (isinf(x) || isinf(y) || isinf(z))
Expand Down
3 changes: 2 additions & 1 deletion include/boost/decimal/detail/cmath/ilogb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

#include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order)
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>

namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto ilogb(T d) noexcept -> std::enable_if_t<detail::is_decimal_floating_point_v<T>, int>
{
const auto fpc_d = fpclassify(d);
Expand Down
6 changes: 4 additions & 2 deletions include/boost/decimal/detail/cmath/isfinite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <boost/decimal/fwd.hpp>
#include <boost/decimal/detail/config.hpp>
#include <boost/decimal/detail/type_traits.hpp>
#include <boost/decimal/detail/concepts.hpp>
#include <type_traits>
#include <cmath>

namespace boost { namespace decimal {
namespace boost {
namespace decimal {

template <typename T>
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
constexpr auto isfinite BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
-> std::enable_if_t<detail::is_decimal_floating_point_v<T>, bool>
{
Expand Down
Loading

0 comments on commit a17135d

Please sign in to comment.