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)

in reply to:  description comment:1 by Steven Watanabe, 9 years ago

Replying to psiha:

AFAICT, should be safe WRT strict-aliasing-rules...

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.

comment:2 by Domagoj Šarić, 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 Domagoj Šarić, 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 Neil Groves, 9 years ago

Resolution: invalid
Status: newclosed

This request doesn't make sense. iterator_range<T const> is totally unrelated to iterator_range<T>.

Note: See TracTickets for help on using tickets.