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

6.6 KiB
Raw Permalink Blame History

[ispanstream]

31 Input/output library [input.output]

31.9 Span-based streams [span.streams]

31.9.4 Class template basic_ispanstream [ispanstream]

31.9.4.1 General [ispanstream.general]

🔗

namespace std {template<class charT, class traits = char_traits>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], constructorsexplicit basic_ispanstream(std::span s, ios_base::openmode which = ios_base::in); basic_ispanstream(const basic_ispanstream&) = delete; basic_ispanstream(basic_ispanstream&& rhs); template explicit basic_ispanstream(ROS&& s);

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

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

1

#

[Note 1:

Constructing an ispanstream from a string-literal includes the termination character '\0' in the underlying spanbuf.

— end note]

31.9.4.2 Constructors [ispanstream.cons]

🔗

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

1

#

Effects: Initializes the base class withbasic_istream<charT, traits>(addressof(sb)) and sb withbasic_spanbuf<charT, traits>(s, which | ios_base::in) ([spanbuf.cons]).

🔗

basic_ispanstream(basic_ispanstream&& rhs);

2

#

Effects: Initializes the base class with std::move(rhs) and sb with std::move(rhs.sb).

Next, basic_istream<charT, traits>::set_rdbuf(addressof(sb)) is called to install the contained basic_spanbuf.

🔗

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

3

#

Constraints: ROS models ranges::borrowed_range.

convertible_to<ROS, std::span> && convertible_to<ROS, std::span> is true.

4

#

Effects: Let sp be std::span(std::forward(s)).

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

31.9.4.3 Swap [ispanstream.swap]

🔗

void swap(basic_ispanstream& rhs);

1

#

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

🔗

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

2

#

Effects: Equivalent to x.swap(y).

31.9.4.4 Member functions [ispanstream.members]

🔗

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

1

#

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

🔗

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

2

#

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

🔗

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

3

#

Effects: Equivalent to rdbuf()->span(s).

🔗

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

4

#

Constraints: ROS models ranges::borrowed_range.

(convertible_to<ROS, std::span>) && convertible_to<ROS, std::span> is true.

5

#

Effects: Let sp be std::span(std::forward(s)).

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