-
-
Notifications
You must be signed in to change notification settings - Fork 480
etl::span: Add advance(), copy(), reinterpret_as() #1024
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
etl::span: Add advance(), copy(), reinterpret_as() #1024
Conversation
|
Is the purpose of i.e. |
|
Right. I will add this. |
| template <typename T1, size_t N1, typename T2, size_t N2> | ||
| typename etl::enable_if<etl::is_same<typename etl::remove_cv<T1>::type, typename etl::remove_cv<T2>::type>::value && | ||
| !etl::is_const<T2>::value, bool>::type | ||
| copy(const etl::span<T1, N1>& src, const etl::span<T2, N2>& dst) |
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 is a class member function, but it copies between two other spans.
This would be better implemented as a separate standalone function, or maybe as a member copy_to(dst)
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.
Are you sure?
As far as I can see, this free function etl::copy(), actually an overload, is outside the class, similar to the directly above etl::equal().
What is strange here is the line numbering. When I merge it on top of current master, it ends up in l.968, not l.830.
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.
Sorry, I see that it is already a standalone function. I got confused looking at diff view late last night. It made the copy function look like a member of the class.
I looked at the full file view this morning.
include/etl/span.h
Outdated
| ETL_NODISCARD ETL_CONSTEXPR14 etl::span<TNew, etl::dynamic_extent> reinterpret_as() const | ||
| { | ||
| #if ETL_USING_CPP11 | ||
| ETL_ASSERT(etl::is_aligned<alignof(TNew)>(pbegin), ETL_ERROR(span_alignment_exception)); |
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 use etl::alignment_of instead of alignof which works for C++03.
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.
Thanks for the hint! Updating it accordingly.
53b3752 to
bbb58b9
Compare
|
Regarding your remark about odd-numbered spans where you get rounding errors when reinterpreting: This is intended, and considered a feature. Consider the case of having a buffer from some protocol data, and only a part of it is the respective span, i.e. value array. Then the size is automatically rounded down to the next correct size, and we can only correctly assume the initial whole elements to be valid, and discard the rest:
I added further unit tests for reinterpret_as() to show what I mean. |
|
Yes, I realised that after I wrote the comment. I deleted the comment. |
Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef.
12c07f7 to
f8a70ed
Compare
|
After rebasing onto latest ETL with new unaligned_type, I encountered failing unit tests for reinterpret_as() on Windows. It was caused by the new multiple inheritance of unaligned_type because sizeof() now results in additional bytes counted for the second base class unaligned_copy which contributed an additional byte. (Even though empty class - but looks like 1 byte is reserved for that.) My solution in the branch is the change to single inheritance, moving unaligned_copy to a class member typedef. Including tests for that. |
d5bea3a
into
ETLCPP:pull-request/#1024-etl-span-Add-advance(),-copy(),-reinterpret_as()
* etl::span: Add advance(), copy(), reinterpret_as() * Added further tests for span::reinterpret_as * Fix size of unaligned_type on Windows Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef.
…terpret_as()' of https://github.com/ETLCPP/etl into pull-request/#1024-etl-span-Add-advance(),-copy(),-reinterpret_as() # Conflicts: # include/etl/span.h
* etl::span: Add advance(), copy(), reinterpret_as() * Added further tests for span::reinterpret_as * Fix size of unaligned_type on Windows Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef.
This commit adds to etl::span:
including tests.