gil
gil copied to clipboard
Provide base() member for adapted views or locators (Trac 2229)
Moved from https://svn.boost.org/trac10/ticket/2229 description:
I would like the result of
typename View::template add_deref<fn>::typeto include a member functionView& base(), much like the iterator adapters currently do (andstd::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 callbase().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)
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):
- Shall we discuss this idea and try implementing?
- Shall we drop the idea for now and come back in future if more users request it?