Files
cppdraft_translate/cppdraft/range/elementsof.md
2025-10-25 03:02:53 +03:00

17 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[range.elementsof]
# 25 Ranges library [[ranges]](./#ranges)
## 25.5 Range utilities [[range.utility]](range.utility#range.elementsof)
### 25.5.6 Class template elements_of [range.elementsof]
Specializations of elements_of encapsulate a range and
act as a tag in overload sets to disambiguate
when a range should be treated as a sequence
rather than a single value[.](#sentence-1)
[*Example [1](#example-1)*: template<bool YieldElements> generator<any> f(ranges::[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") auto&& r) {if constexpr (YieldElements)co_yield ranges::elements_of(r); // yield each element of relseco_yield r; // yield r as a single value} — *end example*]
namespace std::ranges {template<[range](range.range#concept:range "25.4.2Ranges[range.range]") R, class Allocator = allocator<byte>>struct elements_of {[[no_unique_address]] R range; [[no_unique_address]] Allocator allocator = Allocator(); }; template<class R, class Allocator = allocator<byte>> elements_of(R&&, Allocator = Allocator()) -> elements_of<R&&, Allocator>;}