cmcstl2 icon indicating copy to clipboard operation
cmcstl2 copied to clipboard

Add single_ref_view to ext

Open daltonmwoodard opened this issue 6 years ago • 0 comments

@CaseyCarter @cjdb here's an implementation of the single_ref_view idea I bounced around in the slack channel earlier today. The implementation strategy basically follows that of rev_view, but the adapter behaves like single_view.

It achieves basically what you'd get from single_view{std::ref(obj)}, but in a first-class way without the reference_wrapper! I don't know how widely applicable this is, but at the moment I'm pretty sure I have a good use-case.

Snippet demonstrating the main difference between this and single_view:

{
    auto obj = T(...);
    auto v = ranges::view::single(obj);
    assert(&obj != &*v.begin());
}

{
    auto obj = T(...);
    auto v = ranges::view::single_ref(obj);
    assert(&obj == &*v.begin());
}

daltonmwoodard avatar Jan 26 '19 22:01 daltonmwoodard