You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
iterator_facade_base::operator[] returns the iterator's value type if the iterated values are const and POD, as determined by boost::iterators::detail::operator_brackets_result. This results in subtle object lifetime errors in places where a reference is expected.
For example, if you use such an iterator with iterator_range, iterator_range::operator[] becomes UB, as it attempts to return the reference type:
std::vector<double> data{1.0, 3.14, 42.7, 2.618, 9.8};
std::vector<std::size_t> indices{1, 0, 2, 1, 3, 2, 4, 3};
auto const begin = boost::make_permutation_iterator(data.cbegin(), indices.cbegin());
auto const end = boost::make_permutation_iterator(data.cbegin(), indices.cend());
auto const range = boost::make_iterator_range(begin, end);
auto const& e = range[0]; // Returns reference to temporary, UB
Is there any reason why in this case iterator_facade_base::operator[] cannot return the reference type, or even a proxy object, instead?
The text was updated successfully, but these errors were encountered:
iterator_facade_base::operator[]
returns the iterator's value type if the iterated values are const and POD, as determined byboost::iterators::detail::operator_brackets_result
. This results in subtle object lifetime errors in places where a reference is expected.For example, if you use such an iterator with
iterator_range
,iterator_range::operator[]
becomes UB, as it attempts to return the reference type:Is there any reason why in this case
iterator_facade_base::operator[]
cannot return the reference type, or even a proxy object, instead?The text was updated successfully, but these errors were encountered: