C++20 STL Cookbook by Bill Weinman

C++20 STL Cookbook by Bill Weinman

Author:Bill Weinman
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2022-05-16T00:00:00+00:00


There's more…

Both find() functions search sequentially and return when they find the first match. If you want to find more matching elements, you can use the filter() function from the ranges library:

template<ranges::viewable_range R, class Pred>

constexpr ranges::view auto ranges::views::filter(R&&, Pred&&);

The filter() function returns a view, a non-destructive window into the container with only the filtered elements. We can then use the view as we would any other container:

auto vw1 = std::ranges::views::filter(c,

[](const City& c){ return c.pop > 20000000; });

for(const City& e : vw1) cout << format("{}
", e.str());

Output:

[Tokyo, 37435191]

[Cairo, 20485965]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.