C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Add Projection Support for std::ranges::views

From: Hewill Kang <hewillk_at_[hidden]>
Date: Wed, 13 Sep 2023 23:30:29 +0800
You can just simply do:

auto active_buttons = buttons | std::views::filter(&Button::enabled);

Grzegorz Sikorski via Std-Proposals <std-proposals_at_[hidden]> 於
2023年9月13日 週三 下午11:20寫道:

> Hello,
>
> I am new to the std-proposals and I assume something like this has already
> been considered in the past, but I wonder if it was rejected for any reason
> or is it planned to address at some point?
>
> I started to notice a pattern that appears in many places. Consider a code
> like this:
>
> struct Button {
> std::string name;
> bool enabled;
> };
>
> auto get_enabled(const auto& buttons) {
> return std::ranges::views::filter([](const auto& button) { return
> button.enabled; });
> }
>
> What I find useful is to add something like
> https://godbolt.org/z/7Y5bdeddd. Projection support could also be useful
> in some other std::ranges::views namespace members.
>
> Greg
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-09-13 15:30:41