forked from cppalliance/decimal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcepts_test.cpp
145 lines (139 loc) · 10.4 KB
/
concepts_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// 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>
/*
* With concepts we get the following error for the call to hypot
*
* ../../../boost/decimal/detail/cmath/hypot.hpp:23:16: note: candidate template ignored: constraints not satisfied [with T1 = boost::decimal::decimal32, T2 = double]
23 | constexpr auto hypot(T1 x, T2 y) noexcept
| ^
../../../boost/decimal/detail/cmath/hypot.hpp:22:51: note: because 'double' does not satisfy 'decimal_floating_point_type'
22 | template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T1, BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T2>
| ^
../../../boost/decimal/detail/concepts.hpp:224:45: note: expanded from macro 'BOOST_DECIMAL_DECIMAL_FLOATING_TYPE'
224 | #define BOOST_DECIMAL_DECIMAL_FLOATING_TYPE boost::decimal::concepts::decimal_floating_point_type
| ^
../../../boost/decimal/detail/concepts.hpp:200:39: note: because 'boost::decimal::detail::is_decimal_floating_point_v<double>' evaluated to false
200 | concept decimal_floating_point_type = boost::decimal::detail::is_decimal_floating_point_v<T>;
| ^
../../../boost/decimal/detail/cmath/hypot.hpp:63:16: note: candidate function template not viable: requires 3 arguments, but 2 were provided
63 | constexpr auto hypot(T1 x, T2 y, T3 z) noexcept
*
*
* Without we get endless template spaghetti:
*
*
* In file included from concepts_test.cpp:5:
In file included from ../../../boost/decimal.hpp:12:
In file included from ../../../boost/decimal/cmath.hpp:30:
../../../boost/decimal/detail/cmath/hypot.hpp:29:27: error: no matching function for call to 'isnan'
29 | if (abs(x) == zero || isnan(y))
| ^~~~~
concepts_test.cpp:13:19: note: in instantiation of function template specialization 'boost::decimal::hypot<boost::decimal::decimal32, double>' requested here
13 | BOOST_TEST_EQ(hypot(T(1), 1.0), 1.0);
| ^
concepts_test.cpp:19:5: note: in instantiation of function template specialization 'test<boost::decimal::decimal32>' requested here
19 | test<boost::decimal::decimal32>();
| ^
../../../boost/decimal/decimal32.hpp:740:16: note: candidate function not viable: no known conversion from 'double' to 'decimal32' for 1st argument
740 | constexpr auto isnan BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal32 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal64.hpp:967:16: note: candidate function not viable: no known conversion from 'double' to 'decimal64' for 1st argument
967 | constexpr auto isnan BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal64 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal128.hpp:996:16: note: candidate function not viable: no known conversion from 'double' to 'decimal128' for 1st argument
996 | constexpr auto isnan BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal128 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~~
In file included from concepts_test.cpp:5:
In file included from ../../../boost/decimal.hpp:12:
In file included from ../../../boost/decimal/cmath.hpp:30:
../../../boost/decimal/detail/cmath/hypot.hpp:33:14: error: no matching function for call to 'abs'
33 | else if (abs(y) == zero || isnan(x))
| ^~~
../../../boost/decimal/detail/cmath/abs.hpp:19:16: note: candidate template ignored: requirement 'detail::is_decimal_floating_point_v<double>' was not satisfied [with T = double]
19 | constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
| ^
In file included from concepts_test.cpp:5:
In file included from ../../../boost/decimal.hpp:12:
In file included from ../../../boost/decimal/cmath.hpp:30:
../../../boost/decimal/detail/cmath/hypot.hpp:37:26: error: no matching function for call to 'isinf'
37 | else if (isinf(x) || isinf(y))
| ^~~~~
../../../boost/decimal/decimal32.hpp:750:16: note: candidate function not viable: no known conversion from 'double' to 'decimal32' for 1st argument
750 | constexpr auto isinf BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal32 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal64.hpp:972:16: note: candidate function not viable: no known conversion from 'double' to 'decimal64' for 1st argument
972 | constexpr auto isinf BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal64 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal128.hpp:1001:16: note: candidate function not viable: no known conversion from 'double' to 'decimal128' for 1st argument
1001 | constexpr auto isinf BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (decimal128 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~~
In file included from concepts_test.cpp:5:
In file included from ../../../boost/decimal.hpp:12:
In file included from ../../../boost/decimal/cmath.hpp:30:
../../../boost/decimal/detail/cmath/hypot.hpp:44:44: error: no matching function for call to 'abs'
44 | auto new_y {static_cast<promoted_type>(abs(y))};
| ^~~
../../../boost/decimal/detail/cmath/abs.hpp:19:16: note: candidate template ignored: requirement 'detail::is_decimal_floating_point_v<double>' was not satisfied [with T = double]
19 | constexpr auto abs BOOST_DECIMAL_PREVENT_MACRO_SUBSTITUTION (T rhs) noexcept
| ^
In file included from concepts_test.cpp:6:
../../../boost/core/lightweight_test.hpp:217:62: error: invalid operands to binary expression ('const boost::decimal::decimal32' and 'const double')
217 | bool operator()(const T& t, const U& u) const { return t == u; }
| ~ ^ ~
../../../boost/core/lightweight_test.hpp:294:9: note: in instantiation of function template specialization 'boost::detail::lw_test_eq::operator()<boost::decimal::decimal32, double>' requested here
294 | if( pred(t, u) )
| ^
concepts_test.cpp:13:5: note: in instantiation of function template specialization 'boost::detail::test_with_impl<boost::detail::lw_test_eq, boost::decimal::decimal32, double>' requested here
13 | BOOST_TEST_EQ(hypot(T(1), 1.0), 1.0);
| ^
../../../boost/core/lightweight_test.hpp:539:55: note: expanded from macro 'BOOST_TEST_EQ'
539 | #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_with_impl(::boost::detail::lw_test_eq(), #expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
| ^
concepts_test.cpp:19:5: note: in instantiation of function template specialization 'test<boost::decimal::decimal32>' requested here
19 | test<boost::decimal::decimal32>();
| ^
../../../boost/decimal/decimal32.hpp:1214:16: note: candidate function not viable: no known conversion from 'const double' to 'decimal32' for 2nd argument
1214 | constexpr auto operator==(decimal32 lhs, decimal32 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal32.hpp:1232:16: note: candidate function template not viable: no known conversion from 'const double' to 'decimal32' for 2nd argument
1232 | constexpr auto operator==(Integer lhs, decimal32 rhs) noexcept -> std::enable_if_t<detail::is_integral_v<Integer>, bool>
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal64.hpp:1824:16: note: candidate function template not viable: no known conversion from 'const double' to 'decimal64' for 2nd argument
1824 | constexpr auto operator==(Integer lhs, decimal64 rhs) noexcept
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal128.hpp:1057:16: note: candidate function template not viable: no known conversion from 'const double' to 'decimal128' for 2nd argument
1057 | constexpr auto operator==(Integer lhs, decimal128 rhs) noexcept
| ^ ~~~~~~~~~~~~~~
../../../boost/decimal/decimal64.hpp:1804:16: note: candidate function not viable: no known conversion from 'const double' to 'decimal64' for 2nd argument
1804 | constexpr auto operator==(decimal64 lhs, decimal64 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~
../../../boost/decimal/decimal128.hpp:1037:16: note: candidate function not viable: no known conversion from 'const double' to 'decimal128' for 2nd argument
1037 | constexpr auto operator==(decimal128 lhs, decimal128 rhs) noexcept -> bool
| ^ ~~~~~~~~~~~~~~
../../../boost/decimal/detail/comparison.hpp:92:16: note: candidate template ignored: requirement 'detail::is_decimal_floating_point_v<double>' was not satisfied [with Decimal1 = boost::decimal::decimal32, Decimal2 = double]
92 | constexpr auto operator==(Decimal1 lhs, Decimal2 rhs) noexcept
| ^
../../../boost/decimal/decimal32.hpp:1226:16: note: candidate template ignored: requirement 'detail::is_integral_v<double>' was not satisfied [with Integer = double]
1226 | constexpr auto operator==(decimal32 lhs, Integer rhs) noexcept -> std::enable_if_t<detail::is_integral_v<Integer>, bool>
| ^
../../../boost/decimal/decimal64.hpp:1817:16: note: candidate template ignored: requirement 'detail::is_integral_v<double>' was not satisfied [with Integer = double]
1817 | constexpr auto operator==(decimal64 lhs, Integer rhs) noexcept
| ^
../../../boost/decimal/decimal128.hpp:1050:16: note: candidate template ignored: requirement 'detail::is_integral_v<double>' was not satisfied [with Integer = double]
1050 | constexpr auto operator==(decimal128 lhs, Integer rhs) noexcept
*/
template <typename T>
void test()
{
T res = T(1.0) + 1.0;
BOOST_TEST_EQ(res, T(2.0));
BOOST_TEST_EQ(hypot(T(1), 1.0), 1.0);
}
int main()
{
test<boost::decimal::decimal32>();
return boost::report_errors();
}