-
Notifications
You must be signed in to change notification settings - Fork 3k
Add functions to create a Span from an std::array #13868
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
Conversation
|
@marcemmers, thank you for your changes. |
kjbracey
left a comment
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.
If you're in the mood for spans, I'd love to see this migrated to mstd::span in the cxxsupport to follow the newer Mbed model of tracking modern C++ - would also give you the opportunity to redo the ptrdiff_t/size_t thing that changed during C++20 drafting without upsetting existing mbed::Span users.
| Span(std::array<OtherElementType, Count> &array): | ||
| _data(array.data()), _size(Count) | ||
| { | ||
| MBED_STATIC_ASSERT( |
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 has been open for ages, not sure what's holding it up: #13085
I'd suggest using static_assert directly in this new code.
| _data(array.data()) | ||
| { | ||
| MBED_STATIC_ASSERT( | ||
| (span_detail::is_convertible<OtherElementType (*)[1], ElementType (*)[1]>::value), |
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.
You can now rely on the std type traits stuff, no need for the span_detail any more.
I can see what I can do but have a couple of questions then though.
|
|
@marcemmers How do you want to use |
|
Yes, I'm suggesting you could make an updated version in cxxsupport, and leave this for backward compatibility (and maybe deprecate). |
Instead of adding a static_assert to certain constructors and functions to check if they are valid I would prevent the usage by enable_if. |
|
I remember I used |
|
Yes, that makes sense when it hits the right wrong overload. You can be told off with a sensible message. But the catch is that sometimes there's a different overload that would work, so the enable_if stops it picking this invalid one, letting it unambiguously land on another one. I'm absolutely rubbish at analysing any of this stuff, so when doing C++-standard-imitation things I just stick to what the standard says, which is almost exclusively the |
|
I have a basic implementation, most of the stuff should be there: https://github.com/marcemmers/mbed-os/blob/add-mstd-span/platform/cxxsupport/mstd_span I don't really know how to implement the container constructor though. Also, I didn't implement some of the constructors correctly because they need some constraints I couldn't really figure out so for now I used the span's element_type pointer for that. So what's the best way forward now? I suppose there will be plenty to do before it is ready to be merged, so can you review it on my repo or should I just make a PR and work from there?
I can see what you mean. I'll have to look into that then. Guess its also dependant on the compiler used what kind of errors you get. |
|
Note that the C++20 spec reworked the Standardese for methods to quickly address these common forms - "Constraints" wants an |
|
So I implemented the container constructor and changed some constructors to take a template argument as type instead of the span::pointer type. This should be more like the standard already. There is a warning when I try to get a subspan with offset 0 because there is a pointless comparison there: |
|
I'd suggest making a separate PR for the
I'd say using What if you change it to |
|
Opened a PR: #13881 for the mstd::span I suppose this one can be closed then? |
Don't know - this one is a possible extension for people who aren't interested in reworking their code, or it could be used for a Mbed 5.15 backport? |
|
I'll close this. It can be reopened if anyone objects this still should get in with #13881 |
Summary of changes
Add functions to create a Span from an std::array to further align with the std::span implementation.
Impact of changes
Migration actions required
Documentation
None
Pull request type
Test results
Reviewers