std::basic_ispanstream<CharT,Traits>:: span
From cppreference.net
<
cpp
|
io
|
basic ispanstream
|
std::
span
<
const
CharT
>
span
(
)
const
noexcept
;
|
(1) | (depuis C++23) |
|
void
span
(
std::
span
<
CharT
>
s
)
noexcept
;
|
(2) | (depuis C++23) |
|
template
<
class
SpanLike
>
void span ( SpanLike && r ) noexcept ; |
(3) | (depuis C++23) |
1)
Obtient un
span
référençant la zone d'écriture si
std::ios_base::out
est défini dans le mode d'ouverture du
std::basic_spanbuf
encapsulé, ou un
span
référençant le tampon sous-jacent sinon.
2)
Fait en sorte que le
std::basic_spanbuf
encapsulé effectue les entrées/sorties sur le tampon référencé par
s
.
3)
Identique à
(2)
, sauf que
s
est obtenu comme si par
std:: span < const CharT > cs { std:: forward < SpanLike > ( r ) } ;
std:: span < CharT > s { const_cast < CharT * > ( cs. data ( ) ) , cs. size ( ) } ;
. Cette surcharge participe à la résolution de surcharge seulement si
std:: span < const CharT > cs { std:: forward < SpanLike > ( r ) } ;
std:: span < CharT > s { const_cast < CharT * > ( cs. data ( ) ) , cs. size ( ) } ;
. Cette surcharge participe à la résolution de surcharge seulement si
SpanLike
modélise
borrowed_range
,
std::
convertible_to
<
SpanLike,
std::
span
<
CharT
>>
est
false
, et
std::
convertible_to
<
SpanLike,
std::
span
<
const
CharT
>>
est
true
.
Table des matières |
Paramètres
| s | - | std::span référençant le stockage à utiliser comme nouveau tampon sous-jacent du flux |
| r | - |
borrowed_range
à utiliser comme nouveau tampon sous-jacent du flux
|
Valeur de retour
1)
Un
std::span
référençant le tampon sous-jacent ou la zone écrite, selon le mode d'ouverture du
std::basic_spanbuf
encapsulé.
2,3)
(aucun)
Exemple
Exécuter ce code
#include <cassert> #include <iostream> #include <span> #include <spanstream> int main() { char out_buf[16]; std::ospanstream ost{std::span<char>{out_buf}}; ost << "C++" << ' ' << 23 << '\0'; // note: termination explicite par null auto sp = ost.span(); assert( sp[0] == 'C' && sp[1] == '+' && sp[2] == '+' && sp[3] == ' ' && sp[4] == '2' && sp[5] == '3' && sp[6] == '\0' ); std::cout << "sp.data(): [" << sp.data() << "]\n"; std::cout << "out_buf: [" << out_buf << "]\n"; // spanstream utilise out_buf comme stockage interne, pas d'allocations assert(static_cast<char*>(out_buf) == sp.data()); const char in_buf[] = "X Y 42"; std::ispanstream ist{std::span<const char>{in_buf}}; assert(static_cast<const char*>(in_buf) == ist.span().data()); char c; ist >> c; assert(c == 'X'); ist >> c; assert(c == 'Y'); int i; ist >> i; assert(i == 42); ist >> i; // le tampon est épuisé assert(!ist); }
Sortie :
sp.data(): [C++ 23] out_buf: [C++ 23]
Voir aussi
|
obtient ou initialise un tampon sous-jacent selon le mode
(fonction membre publique de
std::basic_spanbuf<CharT,Traits>
)
|