Skip to content
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

Initial implementation of digits -> Nat -> digits #120

Merged
merged 23 commits into from
Jun 10, 2022

Conversation

saxbophone
Copy link
Owner

@saxbophone saxbophone commented Jun 9, 2022

TODO:

  • initial CI tests passing?
  • add tests for leading zero elision
  • add ctor for digits initializer_list
  • add ctor for other iterables of digits?
  • consider what happens when Nat is initialised from an empty iterable
  • consider what happens when a Nat object with empty digits gets digits() called on it

Closes #114

This is expected to be the namespace it will live in once it's rolled out into its own library; thus when it is, code changes will be minimal for clients (should only require an additional include file if they want to be really strict about it, but technically speaking even that can be omitted as arby will include it itself)
These tests appear to actually hang, don't know why...
If you don't instruct Catch2 generators to take just 1 value, using random() will loop forever
…digits back out again

TODO:
- add ctor for digits initializer_list
- add ctor for other iterables of digits?
- consider what happens when Nat is initialised from an empty iterable
- consider what happens when a Nat object with empty digits gets digits() called on it
For some reason, the product test case one doesn't compile unless sign-conversion warnings are disabled. Not clear why...
This is due to a Catch2 bug in v2: catchorg/Catch2#2348
Time to move to Catch2 v3?
…O answer:"

This doesn't work on MSVC (but does on Clang)
This reverts commit 0fa8674.
Not required for it to work, but bypasses a manual push_back() of each element into the container in favour of passing the initializer_list directly to the container --not much different currently, as the container just does repeated push_back()s itself, but this leaves any future optimisation of these kinds of initialisation up to the container (for example, a container could read the size of the initializer_list and allocate the exact required amount of memory for the elements in advance, then just read the values into storage, rather than re-allocate memory each time).
Took this as an opportunity to also refactor out leading-zero-elision into a dedicated private method, given that it was already in use in 2 or 3 other places prior to the addition of these 3 additional uses.
Changed digits() to deliberately return a non-const reference to verify this (make it fail)
We don't have it as a reference for real, and we can't store the result of a stack value as reference type, so we've removed the test
@saxbophone saxbophone merged commit f4d4516 into master Jun 10, 2022
@saxbophone saxbophone deleted the josh/114-digits-accessor-ctor branch June 10, 2022 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nat.digits() read-only accessor and Nat::Nat({ ...digits sequence...}) ctor
1 participant