-
Notifications
You must be signed in to change notification settings - Fork 69
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
std::data() and std::span support #96
Comments
Sounds reasonable to me. |
I have no problem with a const version, but giving non-const access to the underlying data seems like it would open up for trouble. On the other hand, |
As a data point Although So, in short, I'm not a Boost.UUID maintainer, but I would prefer Boost.UUID evolve in a different direction, which would make |
@Lastique at least the current stduuid implementation offers a
actually this would be also required for |
I think, that was discussed in std-proposals list. I'm hesitant to speak for the participants of that discussion, but I got the impression that hiding internal representation was considered the right way to go, which would make
Most importantly, it will remove the need to deal with endianness. For example, if you look at the |
I don't think we'll ever be able to offer |
We could deprecate the public One downside of this transition is that |
Changing existing uses of I suppose we could add
and then |
I'm not sure if we want to encourage that any further; P0959 (correctly IMO) points out that
Although if we move away from an iterator interface, we shouldn't need
No, I don't think this would be wise. UUIDs are well defined portable entities with standard (also portable) string representations, so the operations depending on the native endianness would be horrible design (and isn't really required, as platforms generally have |
Well, even if UUID is considered as a distinct object, the APIs where it is interpreted as an array of bytes are not uncommon.
One example of such operation that was mentioned is |
Yes I know that An efficient |
I know next to nothing about ARM, but from a cursory look, one should be able to synthetize a byteswap for __uint128_t in a vector register with a sequence of |
Although I doubt that the result will be more efficient than the scalar code (https://godbolt.org/z/5KoPPoP8n). |
No, my point was that the result could be portable and the |
I suppose you could store the bytes in little-endian order, yes, which would make That's an interesting option, but I'm not sure whether it's worth it because it penalizes everything else in order to benefit |
Although, I admit, |
Yes. In my experience, I use UUIDs as keys quite often, and serialize them to bytes less often, so the tradeoff makes sense to me. And even then, where I serialize UUIDs I know I will be reading them on the same kind of machine, so I wouldn't even need the big-endian byte sequence, platform-specific representation would be fine. But this last part is specific to my use case, I suppose. |
I think, we could have a member function like We could also have a similar initializing constructor doing the reverse. |
That's true for most people, but today, no sane person should/would use |
It occurs to me that another advantage of having opaque representation and value-based accessors would be to enable better |
Something else I noticed - having |
IIRC stack protection generally activates for POD types (as defined by MS ABI) larger than 8 bytes, i.e. In retrospect, I see this as a misguided feature request on my part. I've come to the conclusion that accessing the internal representation for small-ish value types offers very little added value compared to explicit serialization functions.
I suppose a complementary |
No, stack protection is only activated by arrays on the stack, not POD types. I think that having The alternative is I suppose removing both the public One option is to have a variable |
In the specific case of So I went to the MSVC docs and they state (s. learn.microsoft.com):
To clarify my previous statement: I do agree with this part. However, I think the alternative (remove container interface) would be cleaner if a deprecation and upgrade path over multiple releases was feasible. OTOH I do appreciate backwards compatibility :/ |
I think the code I was trying was https://godbolt.org/z/nbjGKvrMW, and while "msvc x64 latest" does manage to optimize out the security cookie here, "x86 latest" (https://godbolt.org/z/xE7Y3nPG8) and "x64 19.29" (https://godbolt.org/z/oMT8qd6T1) do not. I suppose we shouldn't worry too much about that, then. (SSE2 doesn't seem to cause any trouble either: https://godbolt.org/z/P4nsz5Gns, https://godbolt.org/z/Pvbsdc6GP.) After giving this a bit of thought, it seems to me that what we need to be driving towards is something like
We'll annoy the people who want to poke directly into the octets ( However, one disadvantage of the above is that you won't be able to serialize an array of |
One example of the above optimization that comes to mind is N3980 which defines a function |
I do not think I also don't think constructing or producing 64/128-bit integers is good, as an UUID is not an integer or pair of integers. I think, such operations would be too confusing. (Also, |
The ability to construct a thing from other things does not imply that the first thing is the same as the other things. For example, you propose first/second is not an issue because the intended use is |
Interestingly, that's probably the reason for my intuitive preference for |
Another thought: There should be an explicit warning about
C++20 users would probably appreciate an |
UUID is a sequence of bytes, and the constructor would reflect this pretty well. It's the next best thing we have after
This use case will also work if you return a
Yes, an overload with |
As far as standard headers go, |
C++17 introduced
std::data()
as a means to access the underlying memory block of contiguous container like entities in a generic way. Furthermore C++20 will introducestd::span
which has a converting template constructor requiringstd::data(cont)
to be well formed (side note: we do satisfy the other requirements already). This would let me (and probably others) remove some special handling of uuid when doing IO.Supporting it is as easy as adding the following two public member function to the
uuid
class:The text was updated successfully, but these errors were encountered: