Opened 9 years ago
Closed 9 years ago
#9750 closed Feature Requests (invalid)
iterator_range<T> to iterator_range<T const> & implicit conversion
Reported by: | Domagoj Šarić | Owned by: | Neil Groves |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost 1.55.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
Please add:
operator iterator_range<T const> /*const*/ & ( ) /*const*/ { return reinterpret_cast<iterator_range<T const> /*const*/ &>( *this ); }
...as this is more efficient with functions that take iterator_ranges by-ref on compilers w/o the SRA optimization (or on ABI boundaries) and, AFAICT, should be safe WRT strict-aliasing-rules...
Change History (4)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
I was thinking of the 'aggregate or union' bullet/"exception" of the strict aliasing rules, doesn't it come into play in this case?
comment:3 by , 9 years ago
Hmm, giving it more thought, I guess it doesn't apply here because iterator_range<T> is not a member of iterator_range<T const> (or vice verse), only their members are 'compatible' but the the aliasing rules/exception don't actually cover that?
i.e. struct A { int * p; }; struct B { int const * p; };
objects of A and B cannot alias each other?
comment:4 by , 9 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This request doesn't make sense. iterator_range<T const> is totally unrelated to iterator_range<T>.
Replying to psiha:
It is not. An iterator_range<T> is not an iterator_range<T const> and cannot safely be treated as such just because they happen to have the same layout.