Refactor: concat() is constexpr and can deal with std::array<>#3994
Refactor: concat() is constexpr and can deal with std::array<>#3994reneme merged 4 commits intorandombit:masterfrom
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
randombit
left a comment
There was a problem hiding this comment.
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?
| template <typename T0 = void, typename... Ts> | ||
| 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.
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_leand friends. Most notably, it is nowconstexprand 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::arraywith the appropriate size,concathandled 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.