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

109 lines
4.0 KiB
Markdown
Raw 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.

[spanstream]
# 31 Input/output library [[input.output]](./#input.output)
## 31.9 Span-based streams [[span.streams]](span.streams#spanstream)
### 31.9.6 Class template basic_spanstream [spanstream]
#### [31.9.6.1](#general) General [[spanstream.general]](spanstream.general)
[🔗](#lib:basic_spanstream)
namespace std {template<class charT, class traits = char_traits<charT>>class basic_spanstream : public basic_iostream<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; // [[spanstream.cons]](#cons "31.9.6.2Constructors"), constructorsexplicit basic_spanstream(std::span<charT> s,
ios_base::openmode which = ios_base::out | ios_base::in);
basic_spanstream(const basic_spanstream&) = delete;
basic_spanstream(basic_spanstream&& rhs);
basic_spanstream& operator=(const basic_spanstream&) = delete;
basic_spanstream& operator=(basic_spanstream&& rhs); // [[spanstream.swap]](#swap "31.9.6.3Swap"), swapvoid swap(basic_spanstream& rhs); // [[spanstream.members]](#members "31.9.6.4Member functions"), members basic_spanbuf<charT, traits>* rdbuf() const noexcept;
std::span<charT> span() const noexcept; void span(std::span<charT> s) noexcept; private: basic_spanbuf<charT, traits> *sb*; // *exposition only*};}
#### [31.9.6.2](#cons) Constructors [[spanstream.cons]](spanstream.cons)
[🔗](#lib:basic_spanstream,constructor)
`explicit basic_spanstream(std::span<charT> s,
ios_base::openmode which = ios_base::out | ios_bas::in);
`
[1](#cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10774)
*Effects*: Initializes the base class withbasic_iostream<charT, traits>(addressof(*sb*)) and *sb* withbasic_spanbuf<charT, traits>(s, which) ([[spanbuf.cons]](spanbuf.cons "31.9.3.2Constructors"))[.](#cons-1.sentence-1)
[🔗](#lib:basic_spanstream,constructor_)
`basic_spanstream(basic_spanstream&& rhs);
`
[2](#cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10788)
*Effects*: Initializes the base class with std::move(rhs) and *sb* with std::move(rhs.*sb*)[.](#cons-2.sentence-1)
Next, basic_iostream<charT, traits>::set_rdbuf(addressof(*sb*)) is called to install the contained basic_spanbuf[.](#cons-2.sentence-2)
#### [31.9.6.3](#swap) Swap [[spanstream.swap]](spanstream.swap)
[🔗](#lib:swap,basic_spanstream)
`void swap(basic_spanstream& rhs);
`
[1](#swap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10804)
*Effects*: Equivalent to:basic_iostream<charT, traits>::swap(rhs);*sb*.swap(rhs.*sb*);
[🔗](#lib:swap,basic_spanstream_)
`template<class charT, class traits>
void swap(basic_spanstream<charT, traits>& x, basic_spanstream<charT, traits>& y);
`
[2](#swap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10820)
*Effects*: Equivalent to x.swap(y)[.](#swap-2.sentence-1)
#### [31.9.6.4](#members) Member functions [[spanstream.members]](spanstream.members)
[🔗](#lib:rdbuf,basic_spanstream)
`basic_spanbuf<charT, traits>* rdbuf() const noexcept;
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10833)
*Effects*: Equivalent to:return const_cast<basic_spanbuf<charT, traits>*>(addressof(*sb*));
[🔗](#lib:span,basic_spanstream)
`std::span<charT> span() const noexcept;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10847)
*Effects*: Equivalent to: return rdbuf()->span();
[🔗](#lib:span,basic_spanstream_)
`void span(std::span<charT> s) noexcept;
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L10858)
*Effects*: Equivalent to rdbuf()->span(s)[.](#members-3.sentence-1)