Skip to content
Snippets Groups Projects
Commit 7d2a12f8 authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

bigunsignedint: make overload unambiguous for all integer types

With just the two overloaded constructors

  bigunsignedint(int)
  bigunsigendint(uintmax_t)

trying to call the constructor with any integer type T different from
int and uintmax_t results in an ambiguous call: the promotion of T to
either int or uintmax_t are ranked the same. (Note that this does not
depend on the specific choice of int and uintmax_t.)

This patch provides a templated constructor for all signed integer
types which is ranked over the constructor taking an uintmax_t, making
overload resolution unambiguous for signed integer types. By also
"hiding" it for unsigned types using enable_if, the overload
resolution for unsigned integer types is also unambiguous; there is
only a single viable candidate left: the one taking an uintmax_t.
parent 541b3dfc
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
#include <limits>
#include <cstdint>
#include <cstdlib>
#include <type_traits>
#include <dune/common/exceptions.hh>
#include <dune/common/hash.hh>
......@@ -51,7 +52,8 @@ namespace Dune
bigunsignedint ();
//! Construct from signed int
bigunsignedint (int x);
template<typename Signed>
bigunsignedint (Signed x, typename std::enable_if<std::is_integral<Signed>::value && std::is_signed<Signed>::value>::type* = nullptr);
//! Construct from unsigned int
bigunsignedint (std::uintmax_t x);
......@@ -157,7 +159,8 @@ namespace Dune
}
template<int k>
bigunsignedint<k>::bigunsignedint (int y)
template<typename Signed>
bigunsignedint<k>::bigunsignedint (Signed y, typename std::enable_if<std::is_integral<Signed>::value && std::is_signed<Signed>::value>::type*)
{
std::uintmax_t x = std::abs(y);
assign(x);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment