[string.view.cons]

# 27 Strings library [[strings]](./#strings)

## 27.3 String view classes [[string.view]](string.view#cons)

### 27.3.3 Class template basic_string_view [[string.view.template]](string.view.template#string.view.cons)

#### 27.3.3.2 Construction and assignment [string.view.cons]

[ð](#lib:basic_string_view,constructor)

`constexpr basic_string_view() noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L781)

*Postconditions*: *size_* == 0 and *data_* == nullptr[.](#1.sentence-1)

[ð](#lib:basic_string_view,constructor_)

`constexpr basic_string_view(const charT* str);
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L792)

*Preconditions*: [str, str + traits​::​length(str)) is a valid range[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L796)

*Effects*: Constructs a basic_string_view, initializing *data_* with str and initializing *size_* with traits​::​length(str)[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L801)

*Complexity*: O(traits::length(str))[.](#4.sentence-1)

[ð](#lib:basic_string_view,constructor__)

`constexpr basic_string_view(const charT* str, size_type len);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L812)

*Preconditions*: [str, str + len) is a valid range[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L816)

*Effects*: Constructs a basic_string_view, initializing *data_* with str and initializing *size_* with len[.](#6.sentence-1)

[ð](#lib:basic_string_view,constructor___)

`template<class It, class End>
  constexpr basic_string_view(It begin, End end);
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L829)

*Constraints*: 

- [(7.1)](#7.1)

  It satisfies [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")[.](#7.1.sentence-1)

- [(7.2)](#7.2)

  End satisfies [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<It>[.](#7.2.sentence-1)

- [(7.3)](#7.3)

  is_same_v<iter_value_t<It>, charT> is true[.](#7.3.sentence-1)

- [(7.4)](#7.4)

  is_convertible_v<End, size_type> is false[.](#7.4.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L838)

*Preconditions*: 

- [(8.1)](#8.1)

  [begin, end) is a valid range[.](#8.1.sentence-1)

- [(8.2)](#8.2)

  It models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")[.](#8.2.sentence-1)

- [(8.3)](#8.3)

  End models [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<It>[.](#8.3.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L846)

*Effects*: Initializes *data_* with to_address(begin) and
initializes *size_* with end - begin[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L851)

*Throws*: When and what end - begin throws[.](#10.sentence-1)

[ð](#lib:basic_string_view,constructor____)

`template<class R>
  constexpr explicit basic_string_view(R&& r);
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L863)

Let d be an lvalue of type remove_cvref_t<R>[.](#11.sentence-1)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L866)

*Constraints*: 

- [(12.1)](#12.1)

remove_cvref_t<R> is not the same type as basic_string_view,

- [(12.2)](#12.2)

R modelsranges​::​[contiguous_range](range.refinements#concept:contiguous_range "25.4.6 Other range refinements [range.refinements]") and ranges​::​[sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"),

- [(12.3)](#12.3)

is_same_v<ranges​::​range_value_t<R>, charT> is true,

- [(12.4)](#12.4)

is_convertible_v<R, const charT*> is false, and

- [(12.5)](#12.5)

d.operator ​::​std​::​basic_string_view<charT, traits>() is not a valid expression[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L883)

*Effects*: Initializes *data_* with ranges​::​data(r) and*size_* with ranges​::​size(r)[.](#13.sentence-1)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L888)

*Throws*: Any exception thrown by ranges​::​data(r) and ranges​::​size(r)[.](#14.sentence-1)
