Init
This commit is contained in:
120
cppdraft/range/view.md
Normal file
120
cppdraft/range/view.md
Normal file
@@ -0,0 +1,120 @@
|
||||
[range.view]
|
||||
|
||||
# 25 Ranges library [[ranges]](./#ranges)
|
||||
|
||||
## 25.4 Range requirements [[range.req]](range.req#range.view)
|
||||
|
||||
### 25.4.5 Views [range.view]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1526)
|
||||
|
||||
The [view](#concept:view "25.4.5 Views [range.view]") concept specifies the requirements of a [range](range.range#concept:range "25.4.2 Ranges [range.range]") type
|
||||
that has the semantic properties below,
|
||||
which make it suitable for use in
|
||||
constructing range adaptor pipelines ([[range.adaptors]](range.adaptors "25.7 Range adaptors"))[.](#1.sentence-1)
|
||||
|
||||
[ð](#concept:view)
|
||||
|
||||
`template<class T>
|
||||
concept [view](#concept:view "25.4.5 Views [range.view]") =
|
||||
[range](range.range#concept:range "25.4.2 Ranges [range.range]")<T> && [movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]")<T> && enable_view<T>;
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1539)
|
||||
|
||||
T models [view](#concept:view "25.4.5 Views [range.view]") only if
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
T has O(1) move construction; and
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
move assignment of an object of type T is no more complex than destruction followed by move construction; and
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
if N copies and/or moves are made from an object of type T that contained M elements,
|
||||
then those N objects have O(N+M) destruction; and
|
||||
|
||||
- [(2.4)](#2.4)
|
||||
|
||||
[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]")<T> is false, orT has O(1) copy construction; and
|
||||
|
||||
- [(2.5)](#2.5)
|
||||
|
||||
[copyable](concepts.object#concept:copyable "18.6 Object concepts [concepts.object]")<T> is false, or
|
||||
copy assignment of an object of type T is no more complex than destruction followed by copy construction[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1564)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The constraints on copying and moving imply that
|
||||
a moved-from object of type T has O(1) destruction[.](#3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1570)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
Examples of views are:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
A [range](range.range#concept:range "25.4.2 Ranges [range.range]") type that wraps a pair of iterators[.](#4.1.sentence-1)
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
A [range](range.range#concept:range "25.4.2 Ranges [range.range]") type that holds its elements by shared_ptr and shares ownership with all its copies[.](#4.2.sentence-1)
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
A [range](range.range#concept:range "25.4.2 Ranges [range.range]") type that generates its elements on demand[.](#4.3.sentence-1)
|
||||
|
||||
A container such as vector<string> does not meet the semantic requirements of [view](#concept:view "25.4.5 Views [range.view]") since copying the container copies all of the elements,
|
||||
which cannot be done in constant time[.](#4.sentence-2)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1589)
|
||||
|
||||
Since the difference between [range](range.range#concept:range "25.4.2 Ranges [range.range]") and [view](#concept:view "25.4.5 Views [range.view]") is largely
|
||||
semantic, the two are differentiated with the help of enable_view[.](#5.sentence-1)
|
||||
|
||||
[ð](#lib:enable_view)
|
||||
|
||||
`template<class T>
|
||||
constexpr bool is-derived-from-view-interface = see below; // exposition only
|
||||
template<class T>
|
||||
constexpr bool enable_view =
|
||||
[derived_from](concept.derived#concept:derived_from "18.4.3 Concept derived_from [concept.derived]")<T, view_base> || is-derived-from-view-interface<T>;
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1603)
|
||||
|
||||
For a type T,*is-derived-from-view-interface*<T> is true if and only ifT has exactly one public base class view_interface<U> for some type U andT has no base classes of type view_interface<V> for any other type V[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1612)
|
||||
|
||||
*Remarks*: Pursuant to [[namespace.std]](namespace.std "16.4.5.2.1 Namespace std"), users may specialize enable_view to true for cv-unqualified program-defined types that model [view](#concept:view "25.4.5 Views [range.view]"),
|
||||
and false for types that do not[.](#7.sentence-1)
|
||||
|
||||
Such specializations shall
|
||||
be usable in constant expressions ([[expr.const]](expr.const "7.7 Constant expressions")) and
|
||||
have type const bool[.](#7.sentence-2)
|
||||
Reference in New Issue
Block a user