-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compile-time pack() / unpack() methods for digits #63
Comments
After briefly experimenting with this, I'm not that sure this is doable. It's worth a bit of further exploration before giving up, though. |
Note: this is analogous to encode/decode as bytes, except we don't care about portability across different environments —these functions are intended to be used for transfer of |
Rough working example of generating digits at compile-time: #include <arby/Nat.hpp>
using namespace com::saxbophone::arby;
constexpr std::size_t size_of_multipliation(std::uintmax_t a, std::uintmax_t b) {
return (Nat(a) * Nat(b)).digit_length();
}
#include <array>
template <std::uintmax_t a, std::uintmax_t b>
constexpr std::array<Nat::StorageType, size_of_multipliation(a, b)> multiply() {
Nat product = Nat(a) * Nat(b);
std::array<Nat::StorageType, size_of_multipliation(a, b)> digits;
std::size_t i = 0;
for (auto digit : product.digits()) {
digits[i] = digit;
i++;
}
return digits;
}
#include <iostream>
int main() {
constexpr auto digits = multiply<3294794728947982, 38998723498324>();
for (auto dig : digits) {
std::cout << dig << " ";
}
std::cout << std::endl;
} |
Purpose:
Allow "packing" the dynamic digits of an
arby::Uint
orcodlili::List
generated at compile-time into astd::array
that will persist the destruction of saidUint
object.This can then be used to "preserve" a Uint generated at compile-time into a
std::array
, then "resurrect" said object into a new run-time Uint for further use, circumventing the issue that memory "allocated" at compile-time can't be passed to runtime ;)Something like the following:
We'll need to use a helper method for the
pack()
method to derive the size of thestd::array
at compile-time into a deduced type, hence auto.The text was updated successfully, but these errors were encountered: