cmcstl2
cmcstl2 copied to clipboard
Add single_ref_view to ext
@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());
}