[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 concept [view](#concept:view "25.4.5 Views [range.view]") = [range](range.range#concept:range "25.4.2 Ranges [range.range]") && [movable](concepts.object#concept:movable "18.6 Object concepts [concepts.object]") && enable_view; ` [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]") is false, orT has O(1) copy construction; and - [(2.5)](#2.5) [copyable](concepts.object#concept:copyable "18.6 Object concepts [concepts.object]") 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 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 constexpr bool is-derived-from-view-interface = see below; // exposition only template constexpr bool enable_view = [derived_from](concept.derived#concept:derived_from "18.4.3 Concept derived_­from [concept.derived]") || is-derived-from-view-interface; ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1603) For a type T,*is-derived-from-view-interface* is true if and only ifT has exactly one public base class view_interface for some type U andT has no base classes of type view_interface 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)