-
Notifications
You must be signed in to change notification settings - Fork 574
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
Refactor: concat() is constexpr and can deal with std::array<> #3994
Refactor: concat() is constexpr and can deal with std::array<> #3994
Conversation
33c1953
to
8b16d52
Compare
8b16d52
to
251b613
Compare
* make Botan::detail::AutoDetect reusable * helper function to opportunistically unpack strong types
The helper is now constexpr (in certain configurations) and can handle std::arrays as well as statically sized spans.
251b613
to
d324f9f
Compare
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.
This is really nice, thanks.
Left one technical question just for my own understanding.
Also I noticed in the library src itself you avoid using the autodetection, instead always specifying the output type. Is there a reason for this?
struct all_same { | ||
static constexpr bool value = (std::is_same_v<T0, Ts> && ...); | ||
static constexpr bool value = (std::is_same_v<T0, Ts> && ... && true); |
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.
What's up with this?
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.
That's a default value, if the parameter pack (T0
) is empty.
The changes in this pull request in the usage locations remove the There are plenty places where no explicit out-type is given, they just don't show up in this diff. |
This reworks the
concat()
helper, giving it similar smartness asload_le
and friends. Most notably, it is nowconstexpr
and gains support for statically sized containers (std::array<>
andstd::span<T, size>
). Also, the desired output container can now be defined without using the (now removed)concat_as<>
crutch.The output container to use is determined along the following rules:
concat<std::vector<uint8_t>>(...)
orconcat<std::array<uint8_t, 32>>(...)
,std::array
with the appropriate size,concat
handled it),Example usages:
Currently, this implementation cannot handle range elements of move-only types (as it uses
std::copy()
internally). Technically, this could probably be resolved, but I refrained from doing that as we mostly concatenate strings anyway. Nevertheless, its worth to keep that in mind and extend it when necessary.