gil icon indicating copy to clipboard operation
gil copied to clipboard

Provide base() member for adapted views or locators (Trac 2229)

Open mloskot opened this issue 7 years ago • 1 comments

Moved from https://svn.boost.org/trac10/ticket/2229 description:

I would like the result of typename View::template add_deref<fn>::type to include a member function View& base(), much like the iterator adapters currently do (and std::reverse_iterator). Imagine I have an rgb-to-hsv converted view, and then want to convert it back to rgb. All I should have to do is call base().

The actual use case: I have a deref function that exposes a reference to the element in a gray pixel. I also have a function that takes a view to regular types and creates an adapted view to gray pixels with that element type.

I want to be ample to write them so that: same_types(make_pixel(remove_pixel(T)), T)

mloskot avatar Oct 08 '18 09:10 mloskot

I'm not sure how the OP imagined this suggestion in detail, but for View& base() we definitely need some extra info cached:

template <typename Loc>
class image_view
{
    using base_type = typename Loc::template add_deref<Deref>::type;
    {image_view<Loc> or base_type} & base_; //  ??? 

    image_view() : base_(*this) {}
    template <typename View>  
    image_view(const View& v) : base_(v) {}

    base_type& base() { return base_; }
};

Questions (/cc @stefanseefeld & @chhenning):

  1. Shall we discuss this idea and try implementing?
  2. Shall we drop the idea for now and come back in future if more users request it?

mloskot avatar Oct 08 '18 09:10 mloskot