Skip to content

Commit

Permalink
Limit instantiation of GncInt128 constructors to integral values.
Browse files Browse the repository at this point in the history
Instead of using static_assert. This prevents the compiler from even
trying and avoids weird compilation errors when testing types for
instantiating other templates.
  • Loading branch information
jralls committed Oct 2, 2022
1 parent 23ca899 commit eb24099
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions libgnucash/engine/gnc-int128.hpp
Expand Up @@ -90,38 +90,25 @@ enum // Values for m_flags
*/
/** Default constructor. Makes 0. */
GncInt128();
template <typename T>
template <typename T,
std::enable_if_t<std::is_integral<T>::value, bool> = true>
GncInt128(T lower) : GncInt128(INT64_C(0), static_cast<int64_t>(lower))
{
static_assert (std::is_integral<T>(),
"GncInt128 can be constructed only with "
"integral arguments.");
}
{}
GncInt128(uint64_t lower) : GncInt128 {UINT64_C(0), lower} {}
/** Double-integer constructor template.
*/
template <typename T, typename U>
template <typename T, typename U,
std::enable_if_t<(std::is_integral<T>::value &&
std::is_integral<U>::value), bool> = true>
GncInt128(T upper, U lower, unsigned char flags = '\0') :
GncInt128 {static_cast<int64_t>(upper),
static_cast<int64_t>(lower), flags}
{
static_assert (std::is_integral<T>(),
"GncInt128 can be constructed only with "
"integral arguments.");
static_assert (std::is_integral<U>(),
"GncInt128 can be constructed only with "
"integral arguments.");
}
static_cast<int64_t>(lower), flags} {}

GncInt128 (int64_t upper, int64_t lower, unsigned char flags = '\0');
template <typename T>
template <typename T,
std::enable_if_t<std::is_integral<T>::value, bool> = true>
GncInt128(T upper, uint64_t lower) :
GncInt128 {static_cast<int64_t>(upper), lower}
{
static_assert (std::is_integral<T>(),
"GncInt128 can be constructed only with "
"integral arguments.");
}
GncInt128 {static_cast<int64_t>(upper), lower} {}

GncInt128 (int64_t upper, uint64_t lower, unsigned char flags = '\0');
GncInt128 (uint64_t upper, uint64_t lower, unsigned char flags = '\0');
Expand Down

0 comments on commit eb24099

Please sign in to comment.