[PATCH] D79740: Align mapped_iterator::reference type with mapped_iterator::operator*() return value.

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 14:20:57 PDT 2020


dblaikie added subscribers: EricWF, rsmith.
dblaikie added a comment.

In D79740#2041959 <https://reviews.llvm.org/D79740#2041959>, @ikelarev wrote:

> Boost documentation says the same: "If Reference is use_default then the reference member of transform_iterator is result_of<const UnaryFunction(iterator_traits<Iterator>::reference)>::type. Otherwise, reference is Reference" (https://www.boost.org/doc/libs/1_73_0/libs/iterator/doc/transform_iterator.html).
>
>   template <class UnaryFunction,
>             class Iterator,
>             class Reference = use_default,
>             class Value = use_default>
>   class transform_iterator
>   {
>   public:
>     typedef /* see below */ value_type;
>     typedef /* see below */ reference;
>   ...
>


Hrm - seems your original proposed change would be a bit more nuanced than Boost's solution, if I'm understanding things correctly - boost's solution is to use FuncReturnTy as the reference type unconditionally/as the default (so if your functor returns by value, you have a reference type that's a value, etc - if it returns by reference, you've got a reference, etc). Your proposed solution is to always use a value type as the reference type and to use the underlying iterator's pointer type if the FuncReturnTy (without reference - so, the value type essentially?) matches the value type of the underlying iterator?

Perhaps just do what Boost's doing here - reference type based on the functor's return type? So if you return a subobject of the underlying object by reference, it can continue to be a reference, but if you compute some value from the underlying object and return by value, it's a value.

(@rsmith @EricWF as C++ librarians in case they have some particular insight on this quirky corner)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79740/new/

https://reviews.llvm.org/D79740





More information about the llvm-commits mailing list