Skip to content

Commit d1c97b6

Browse files
committed
Add more helpful message to constructor saying it cant be used
1 parent a5581d2 commit d1c97b6

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

include/boost/decimal/decimal128_t.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ BOOST_DECIMAL_EXPORT class decimal128_t final
257257
#endif
258258
constexpr decimal128_t(T1 coeff, T2 exp, bool sign = false) noexcept;
259259

260+
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
261+
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
262+
#else
263+
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
264+
#endif
265+
constexpr decimal128_t(T1, T2, bool) noexcept { static_assert(false, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
266+
260267
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
261268
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
262269
#else

include/boost/decimal/decimal32_t.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ BOOST_DECIMAL_EXPORT class decimal32_t final // NOLINT(cppcoreguidelines-special
282282
#endif
283283
constexpr decimal32_t(T1 coeff, T2 exp, bool sign = false) noexcept;
284284

285+
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
286+
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
287+
#else
288+
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
289+
#endif
290+
constexpr decimal32_t(T1, T2, bool) noexcept { static_assert(false, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
291+
285292
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
286293
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
287294
#else

include/boost/decimal/decimal64_t.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@ BOOST_DECIMAL_EXPORT class decimal64_t final
319319
#endif
320320
constexpr decimal64_t(T1 coeff, T2 exp, bool sign = false) noexcept;
321321

322+
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
323+
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
324+
#else
325+
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
326+
#endif
327+
constexpr decimal64_t(T1, T2, bool) noexcept { static_assert(false, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
328+
322329
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
323330
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
324331
#else

include/boost/decimal/decimal_fast128_t.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ BOOST_DECIMAL_EXPORT class decimal_fast128_t final
157157
#endif
158158
constexpr decimal_fast128_t(T1 coeff, T2 exp, bool sign = false) noexcept;
159159

160+
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
161+
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
162+
#else
163+
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
164+
#endif
165+
constexpr decimal_fast128_t(T1, T2, bool) noexcept { static_assert(false, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
166+
160167
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
161168
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
162169
#else

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
150150
template <typename T1, typename T2, std::enable_if_t<detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
151151
constexpr decimal_fast32_t(T1 coeff, T2 exp, bool sign = false) noexcept;
152152

153+
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
154+
constexpr decimal_fast32_t(T1, T2, bool) noexcept { static_assert(false, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
155+
153156
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
154157
constexpr decimal_fast32_t(T1 coeff, T2 exp) noexcept;
155158

include/boost/decimal/decimal_fast64_t.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
168168
#endif
169169
constexpr decimal_fast64_t(T1 coeff, T2 exp, bool sign = false) noexcept;
170170

171+
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
172+
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
173+
#else
174+
template <typename T1, typename T2, std::enable_if_t<!detail::is_unsigned_v<T1> && detail::is_integral_v<T2>, bool> = true>
175+
#endif
176+
constexpr decimal_fast64_t(T1, T2, bool) noexcept { static_assert(false, "Construction from signed integer, exponent, and sign is ambiguous, so it is disallowed. You must use an Unsigned Integer for the coefficient to construct from {coefficient, exponent, sign}"); }
177+
171178
#ifdef BOOST_DECIMAL_HAS_CONCEPTS
172179
template <BOOST_DECIMAL_SIGNED_INTEGRAL T1, BOOST_DECIMAL_INTEGRAL T2>
173180
#else

0 commit comments

Comments
 (0)