[ispanstream]

# 31 Input/output library [[input.output]](./#input.output)

## 31.9 Span-based streams [[span.streams]](span.streams#ispanstream)

### 31.9.4 Class template basic_ispanstream [ispanstream]

#### [31.9.4.1](#general) General [[ispanstream.general]](ispanstream.general)

[ð](#lib:basic_ispanstream)

namespace std {template<class charT, class traits = char_traits<charT>>class basic_ispanstream : public basic_istream<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; // [[ispanstream.cons]](#cons "31.9.4.2 Constructors"), constructorsexplicit basic_ispanstream(std::span<charT> s,
 ios_base::openmode which = ios_base::in);
 basic_ispanstream(const basic_ispanstream&) = delete;
 basic_ispanstream(basic_ispanstream&& rhs); template<class ROS> explicit basic_ispanstream(ROS&& s);

 basic_ispanstream& operator=(const basic_ispanstream&) = delete;
 basic_ispanstream& operator=(basic_ispanstream&& rhs); // [[ispanstream.swap]](#swap "31.9.4.3 Swap"), swapvoid swap(basic_ispanstream& rhs); // [[ispanstream.members]](#members "31.9.4.4 Member functions"), member functions basic_spanbuf<charT, traits>* rdbuf() const noexcept;

 std::span<const charT> span() const noexcept; void span(std::span<charT> s) noexcept; template<class ROS> void span(ROS&& s) noexcept; private: basic_spanbuf<charT, traits> *sb*; // *exposition only*};}

[1](#general-1)

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

[*Note [1](#general-note-1)*:

Constructing an ispanstream from a [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]") includes the termination character '\0' in the underlying spanbuf[.](#general-1.sentence-1)

â *end note*]

#### [31.9.4.2](#cons) Constructors [[ispanstream.cons]](ispanstream.cons)

[ð](#lib:basic_ispanstream,constructor)

`explicit basic_ispanstream(std::span<charT> s, ios_base::openmode which = ios_base::in);
`

[1](#cons-1)

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

*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) and *sb* withbasic_spanbuf<charT, traits>(s, which | ios_base​::​in) ([[spanbuf.cons]](spanbuf.cons "31.9.3.2 Constructors"))[.](#cons-1.sentence-1)

[ð](#lib:basic_ispanstream,constructor_)

`basic_ispanstream(basic_ispanstream&& rhs);
`

[2](#cons-2)

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

*Effects*: Initializes the base class with std​::​move(rhs) and *sb* with std​::​move(rhs.*sb*)[.](#cons-2.sentence-1)

Next, basic_istream<charT, traits>​::​set_rdbuf(addressof(*sb*)) is called
to install the contained basic_spanbuf[.](#cons-2.sentence-2)

[ð](#lib:basic_ispanstream,constructor__)

`template<class ROS> explicit basic_ispanstream(ROS&& s)
`

[3](#cons-3)

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

*Constraints*: ROS models ranges​::​[borrowed_range](range.range#concept:borrowed_range "25.4.2 Ranges [range.range]")[.](#cons-3.sentence-1)

![convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<ROS, std​::​span<charT>> && [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<ROS, std​::​span<charT const>> is true[.](#cons-3.sentence-2)

[4](#cons-4)

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

*Effects*: Let sp be std​::​span<const charT>(std​::​forward<ROS>(s))[.](#cons-4.sentence-1)

Equivalent to:basic_ispanstream(std::span<charT>(const_cast<charT*>(sp.data()), sp.size()))

#### [31.9.4.3](#swap) Swap [[ispanstream.swap]](ispanstream.swap)

[ð](#lib:swap,basic_ispanstream)

`void swap(basic_ispanstream& rhs);
`

[1](#swap-1)

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

*Effects*: Equivalent to:basic_istream<charT, traits>::swap(rhs);*sb*.swap(rhs.*sb*);

[ð](#lib:swap,basic_ispanstream_)

`template<class charT, class traits>
  void swap(basic_ispanstream<charT, traits>& x, basic_ispanstream<charT, traits>& y);
`

[2](#swap-2)

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

*Effects*: Equivalent to x.swap(y)[.](#swap-2.sentence-1)

#### [31.9.4.4](#members) Member functions [[ispanstream.members]](ispanstream.members)

[ð](#lib:rdbuf,basic_ispanstream)

`basic_spanbuf<charT, traits>* rdbuf() const noexcept;
`

[1](#members-1)

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

*Effects*: Equivalent to:return const_cast<basic_spanbuf<charT, traits>*>(addressof(*sb*));

[ð](#lib:span,basic_ispanstream)

`std::span<const charT> span() const noexcept;
`

[2](#members-2)

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

*Effects*: Equivalent to: return rdbuf()->span();

[ð](#lib:span,basic_ispanstream_)

`void span(std::span<charT> s) noexcept;
`

[3](#members-3)

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

*Effects*: Equivalent to rdbuf()->span(s)[.](#members-3.sentence-1)

[ð](#members-itemdecl:4)

`template<class ROS> void span(ROS&& s) noexcept;
`

[4](#members-4)

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

*Constraints*: ROS models ranges​::​[borrowed_range](range.range#concept:borrowed_range "25.4.2 Ranges [range.range]")[.](#members-4.sentence-1)

(![convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<ROS, std​::​span<charT>>) && [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<ROS, std​::​span<const charT>> is true[.](#members-4.sentence-2)

[5](#members-5)

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

*Effects*: Let sp be std​::​span<const charT>(std​::​forward<ROS>(s))[.](#members-5.sentence-1)

Equivalent to:this->span(std::span<charT>(const_cast<charT*>(sp.data()), sp.size()));
