...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
There is limited support for constexpr
in the library, currently the number
front end supports constexpr
on default construction and all forwarding constructors, but not on any of
the non-member operators. So if some type B
is a literal type, then number<B>
is also a literal type, and you will be able to compile-time-construct such
a type from any literal that B
is compile-time-constructible from. However, you will not be able to perform
compile-time arithmetic on such types.
Currently the only backend type provided by the library that is also a literal
type are instantiations of cpp_int_backend
where the Allocator parameter is type void
,
and the Checked parameter is boost::multiprecision::unchecked
.
For example:
using namespace boost::multiprecision; constexpr int128_t i = 0; // OK, fixed precision int128_t has no allocator. constexpr uint1024_t j = 0xFFFFFFFF00000000uLL; // OK, fixed precision uint1024_t has no allocator. constexpr checked_uint128_t k = -1; // Error, checked type is not a literal type as we need runtime error checking. constexpr cpp_int l = 2; // Error, type is not a literal as it performs memory management.