namespace std {
template <class CharT,
class Traits = char_traits<CharT> >
class basic_spanbuf : public basic_streambuf<CharT, Traits>;
using spanbuf = basic_spanbuf<char>;
using wspanbuf = basic_spanbuf<wchar_t>;
}
概要
std::basic_spanbufクラスは、std::span を使用した固定長ストリームバッファである。
メンバ関数
| 名前 | 説明 | 対応バージョン |
|---|---|---|
(constructor) |
コンストラクタ | C++23 |
operator= |
ムーブ代入 | C++23 |
swap |
値の交換 | C++23 |
span |
std::spanオブジェクトの設定・取得 |
C++23 |
非メンバ関数
| 名前 | 説明 | 対応バージョン |
|---|---|---|
swap |
2つのオブジェクトを入れ替える | C++23 |
メンバ型
| 名前 | 説明 | 対応バージョン |
|---|---|---|
char_type |
テンプレート仮引数CharT |
C++23 |
int_type |
Traits::int_type |
C++23 |
pos_type |
Traits::pos_type |
C++23 |
off_type |
Traits::off_type |
C++23 |
traits_type |
テンプレート仮引数Traits |
C++23 |
例
#include <iostream>
#include <span>
#include <spanstream>
int main()
{
// basic_spanbufはストリームの内部バッファとして動作する
char buf[256] = {};
std::span<char> span{buf};
std::spanbuf sb(span);
// 書き込み: sputc()で1文字ずつ書き込む
sb.sputc('H');
sb.sputc('e');
sb.sputc('l');
sb.sputc('l');
sb.sputc('o');
// 文字列として取得
std::cout << "Written: " << sb.span().data() << std::endl;
char buf2[256] = "World";
std::span<char> span2{buf2};
// 新しい文字列を設定
sb.span(span2);
// 読み取り: sbumpc()で1文字ずつ読み取る
std::cout << "Read: ";
while (sb.in_avail() > 0) {
char c = sb.sbumpc();
std::cout << c;
}
std::cout << std::endl;
}
出力
Written: Hello
Read: World
バージョン
言語
- C++23
処理系
- Clang: ??
- GCC: ??
- Visual C++: ??