I would like to serialize a custom class containing an boost::multiprecision::mpfr_float as a member. It says here in the Boost.Serialization documentation that a type T<
If you are using version 4.0.0 or higher, you can use mpfr_fpif_export and mpfr_fpif_import to serialize/deserialize it.
using realtype = number>;
#define MPFR_BUFFER_SIZE 1000
namespace boost {
namespace serialization {
template
void save(Archive& ar, const realtype& x, const boost::serialization::version_type&) {
static char buffer[MPFR_BUFFER_SIZE];
FILE* fid = fmemopen(buffer, MPFR_BUFFER_SIZE, "wb+");
mpfr_fpif_export(fid, const_cast(x.backend().data()));
fseek(fid, 0L, SEEK_END);
long length = ftell(fid);
ar& length;
ar& boost::serialization::make_array(buffer, length);
fclose(fid);
}
template
void load(Archive& ar, realtype& x, const boost::serialization::version_type&) {
static char buffer[MPFR_BUFFER_SIZE];
long length = 0;
ar& length;
ar& boost::serialization::make_array(buffer, length);
FILE* fid = fmemopen(buffer, length, "r");
mpfr_fpif_import(x.backend().data(), fid);
fclose(fid);
}
template
inline void
serialize(Archive& ar, realtype& t, const unsigned int file_version) {
split_free(ar, t, file_version);
}
}
}