Created
March 20, 2023 07:14
-
-
Save afabri/acc723427888dc49c60099bdb6220c53 to your computer and use it in GitHub Desktop.
Minimal code showing a compilation problem for boost multiprecision and operator, combined with Eigen on VC2017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/operators.hpp> | |
#include <boost/multiprecision/cpp_int.hpp> | |
#include <Eigen/Dense> | |
// Quotient | |
template <class NT_> | |
class Toto | |
: boost::additive2 < Toto<NT_>, NT_ > | |
{ | |
public: | |
NT_ num, den; | |
Toto() {} | |
Toto(const NT_& a) {} | |
Toto(const NT_& a, const NT_&b) {} | |
template <class T> | |
Toto operator+=(const T&) { return *this; } | |
}; | |
// Sqrt_extension: | |
template <class NT_> | |
class Toto2 | |
: boost::additive2 < Toto2<NT_>, NT_ > | |
{ | |
public: | |
NT_ num, den; | |
Toto2() {} | |
Toto2(const NT_& nt) | |
{} | |
template <class T> | |
Toto2 operator+=(const T&) { return *this; } | |
}; | |
void toto(Toto<boost::multiprecision::cpp_int>& x) | |
{ | |
x.den; | |
} | |
// No idea if needed | |
namespace Eigen { | |
template<class> struct NumTraits; | |
template<class NT> struct NumTraits<Toto<NT> > | |
{ | |
typedef Toto<NT> Real; | |
typedef Toto<NT> NonInteger; | |
typedef Toto<NT> Nested; | |
typedef Toto<NT> Literal; | |
static inline Real epsilon() { return NumTraits<NT>::epsilon(); } | |
static inline Real dummy_precision() { return NumTraits<NT>::dummy_precision(); } | |
enum { | |
IsInteger = 0, | |
IsSigned = 1, | |
IsComplex = 0, | |
RequireInitialization = NumTraits<NT>::RequireInitialization, | |
ReadCost = 2 * NumTraits<NT>::ReadCost, | |
AddCost = 150, | |
MulCost = 100 | |
}; | |
}; | |
template<class NT> struct NumTraits<Toto2<NT> > | |
{ | |
typedef Toto2<NT> Real; | |
typedef Toto2<NT> NonInteger; | |
typedef Toto2<NT> Nested; | |
typedef Toto2<NT> Literal; | |
static inline Real epsilon() { return NumTraits<NT>::epsilon(); } | |
static inline Real dummy_precision() { return NumTraits<NT>::dummy_precision(); } | |
enum { | |
IsInteger = 0, | |
IsSigned = 1, | |
IsComplex = 0, | |
RequireInitialization = NumTraits<NT>::RequireInitialization, | |
ReadCost = 2 * NumTraits<NT>::ReadCost, | |
AddCost = 150, | |
MulCost = 100 | |
}; | |
}; | |
} | |
int main() { | |
typedef Toto2<int> NT; | |
Eigen::Matrix<NT, 3, 3> m(3, 3); | |
m + m; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It that fixes things, then I don't see why not - it would have to be to your code as a workaround, and you could predicate it on BOOST_VERSION should you wish - that would also protect you from any future changes to
is_byte_container
given that it's an implementation detail (not that I'm planning to change it, but you know, 12 months from now I'll probably have forgotten this conversation!).