[PATCH] D79740: Align mapped_iterator::reference type with mapped_iterator::operator*() return value.
Ivan Kelarev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 15 18:29:17 PDT 2020
ikelarev added a comment.
@dblaikie
Yes, David, you are right. reverse_iterator should not be used with such implementation. Talking about boost implementation I noticed this thing:
// By default, dereferencing the iterator yields the same as
// the function.
typedef typename ia_dflt_help<
Reference
#ifdef BOOST_RESULT_OF_USE_TR1
, result_of<const UnaryFunc(typename std::iterator_traits<Iterator>::reference)>
#else
, result_of<const UnaryFunc&(typename std::iterator_traits<Iterator>::reference)>
#endif
>::type reference;
In other words, for the function returning by value boost's transform_iterator::operator* will also return by value without any reference. Like I proposed at the very beginning - explicitly specify "reference" type as the resulting type of the functor. Yes, this solution does not 100% conform to iterator requirements, but it's simple and does not bring any UB into the code. And boost uses this approach.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79740/new/
https://reviews.llvm.org/D79740
More information about the llvm-commits
mailing list