saxbophone / arby

Arbitrary precision arithmetic in C++, even at compile-time
https://saxbophone.com/arby/
Mozilla Public License 2.0
8 stars 1 forks source link

Generic Uint::from<T>() static ctor-like method #46

Closed saxbophone closed 2 years ago

saxbophone commented 2 years ago

For "constructing" Uint objects from any reasonable numeric type:

template <typename T>
static constexprvector from(T value);

to be used somewhat like:

std::uint8_t data = ...;
arby::Uint value = arby::Uint::from<std::uint8_t>(data);

Definitely don't want this as a constructor, not even an explicit constructor, we want it as a constructor-like static method to prevent any issues with implicit conversions or promotions.

saxbophone commented 2 years ago

Might want to use concepts to specify the numeric operations need to be supported by a given generic type T such that its substitution into the template is valid. We could create this as a custom constraint ourself, only requiring the minimum number of operations on the type T needed to populate the Uint's digits from it.

saxbophone commented 2 years ago

The usefulness of this is questionable, I should verify that Uint can't be strictly initialised from unsigned types smaller than uintmax_t before doing serious work on this, ideally with an additional set of test cases...