zoo
zoo copied to clipboard
New Literals Utils
moved this into a new PR for clarity. Literals can now be written like so:
static_assert(SWAR{Literals<32, u64>, {2, 1}}.value() == 0x00000002'00000001);
static_assert(SWAR{Literals<32, u64>, {1, 2}}.value() == 0x00000001'00000002);
static_assert(SWAR{Literals<16, u64>, {4, 3, 2, 1}}.value() == 0x0004'0003'0002'0001);
static_assert(SWAR{Literals<16, u64>, {1, 2, 3, 4}}.value() == 0x0001'0002'0003'0004);
Improvements all around, but, like in the movie "Whiplash", still not quite my tempo. Loving the feedback. Thank you! Since you have given us the construction from literals, perhaps it is a good idea to do the opposite of having a conversion operator to array of values,
constexpr operator std::array<T, Lanes>();
and a named conversionto_array
I like the idea of this, will check it out.
@thecppzoo maybe best to merge where we were happy and add the to_array
in a seperate PR if we think that is interesting?
My preference with this PR is to not just introduce the support for direct initialization of literals, but complete it with the following:
- Making the essential function
from_array
a part of the public interface (we ought to indicate the semantics is that of big endianness in the comments inline with the code), as a class-function, because it is a factory. - Keep the
Literals
infrastructure you already made, extend with a constructor fromstd::array
-
to_array
Separately, I think we can also add a header, such as SWAR_IO.h
where the insertion and extraction operators are implemented. I don't think these things are unrelated: The ergonomics of the literals are highly cohesive with stream insertion and extraction. We need this "yesterday" for debugging and tracing.
Indicate if you'd like to split these features with me or prefer to do them all yourself.
If you want to take on the std::array
stuff and getting that to that could be nice.
From what I understood from playing around with this today we will require C++ >17 in order to use constexpr std::array
in static_assert
tests, but this may be a limitation of my understanding.
Even with C++23 am seeing failures to compiler on g++
.