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
take span instead of std::vector to simplify interface #190
base: main
Are you sure you want to change the base?
Conversation
src/util.hpp
Outdated
}; | ||
|
||
using Bytes = span<uint8_t const>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bytes
still mean the same thing even though it's an alias to span
now
explicit Bytes(const std::vector<uint8_t>& vecBytes) | ||
: pData(vecBytes.data()), nSize(vecBytes.size()) | ||
|
||
span(const std::vector<typename std::remove_const<T>::type>& cont) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note how explicit
was removed here. This allows implicit conversion from a vector to a span. This lets you pass either a vector or a pointer+size to an interface that just wants a sequence of objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea with span
instead of vector
for the parameters but shouldn't this be done for all API calls then? Right now it would introduce a mix of both and imo it makes sense to have a consistent interface.
Also see some thoughts below
I marked this as a draft for now. I think I may pivot this into just doing the |
f551c57
to
e65d0a1
Compare
@@ -64,7 +64,7 @@ G1Element G1Element::FromBytes(const Bytes& bytes) | |||
|
|||
G1Element G1Element::FromByteVector(const std::vector<uint8_t>& bytevec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the FromByteVector()
functions don't really serve a purpose with this patch anymore, since the Bytes
overload can be used for std::vector
as well. Since it's part of the public API though, I'm hesitant to remove it.
This results in a smaller interface, since the conversion vector -> Bytes is done in the span constructor. Additionally it make the interface more flexible in that it no longer requires the caller to allocate the array in a std::vector
'This PR has been flagged as stale due to no activity for over 60 |
Is this something that we still want to do? or should we close it? @xdustinface |
I think there are a lot of opportunities to simplify the code by making changes like this, and embracing a |
OK, we can leave this open until someone decides to take this PR further, any help is welcome |
'This PR has been flagged as stale due to no activity for over 60 |
@arvidn can you help me out with resolving these merge conflicts? |
'This PR has been flagged as stale due to no activity for over 60 |
@justinengland sorry for the delay. this message got lost in my inbox. |
'This PR has been flagged as stale due to no activity for over 60 |
modernize the interface a bit to take
span
rather thanstd::vector
. For now, use our ownspan
type, but this could use GSL orstd::span
in the future. The main motivation for this is to allow passing ranges of values without having to first copy them into astd::vector
. It also simplifies some of the functions that currently take both aspan
and astd::vector
. By making span be implicitly constructed from a vector, we can remove one of the overloads.