-
-
Couldn't load subscription status.
- Fork 473
Add enable_if restriction for span constructor from c array #1055
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
Add enable_if restriction for span constructor from c array #1055
Conversation
| /// Construct from C array | ||
| //************************************************************************* | ||
| template<size_t Array_Size> | ||
| template<size_t Array_Size, typename = typename etl::enable_if<(Extent == etl::dynamic_extent) || (Array_Size == Extent), void>::type> |
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.
I don't think the (Extent == etl::dynamic_extent) test is necessary here, as this class specialisation is for fixed extent only.
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.
I think you are right! But I was following the style of the other code in the fixed span, where there are also checks for either == or != etl::dynamic_extent. Still I can try removing it in this constructor, I think all the unit tests should still be good.
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.
But I was following the style of the other code in the fixed span
I'll take a look at the other code.
a75d1d2
into
ETLCPP:pull-request/#1055-Add-enable_if-restriction-for-span-constructor-from-c-array
|
I was wondering whether I should add a runtime check for when a dynamic |
I took a look at how how gcc handles this. In the constructor for test2, there is a debug assert that I would hope that I wouldn't run into this case much. Constructing a fixed span from a dynamic just seems like a bad idea, but mistakes can happen. Edit: Ah, just realized the constructor is noexcept. So one more thing to keep in mind. |
…onstructor-from-c-array' into development # Conflicts: # include/etl/span.h # test/test_span_fixed_extent.cpp
A small change to the static span constructor from c array to require that
Extentis equal toArray_Size. std span on gcc also does this same check.This prevents the following code from compiling: