boostorg / multiprecision

Boost.Multiprecision
Boost Software License 1.0
198 stars 112 forks source link

mpq_rational(enum) #36

Open mglisse opened 6 years ago

mglisse commented 6 years ago
#include <boost/multiprecision/gmp.hpp>
typedef boost::multiprecision::mpq_rational NT;
enum E { neg = -1, zero, pos } e;
int main(){
  NT a = e;
}

fails to compile, while it works for cpp_rational. (In my application, it is actually q == e that failed to compile, but I assume that is the same issue)

mglisse commented 6 years ago

Adding || boost::is_enum<V>::value in the constructor of number let me move forward with the testing, but that might not be a good way to handle it.

jzmaddock commented 6 years ago

It's as good a way as any, but I'm quite conflicted about this, consider:

enum { big1 = -2, big2 = ULLONG_MAX, };

What should happen when we assign from big1 and big2?

mglisse commented 6 years ago

I would expect the same behavior when interoperating with an enum E or its std::underlying_type_t<E>. If that's __int128... well, I seem to get a compile error currently with __int128, so the same looks fine for the enum. But I haven't thought about it much, we only use very small enums in this project.