std::return_temporary_buffer
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <memory> で定義
|
||
template< class T > void return_temporary_buffer( T* p ); |
(C++17で非推奨) (C++20で削除) |
|
以前に std::get_temporary_buffer で確保した記憶域を解放します。
引数
| p | - | 以前に std::get_temporary_buffer で返され、まだ return_temporary_buffer の呼び出しによって無効化されていないポインタ
|
戻り値
(なし)
例外(なし) |
(C++17以上) |
例
Run this code
#include <algorithm>
#include <iostream>
#include <memory>
#include <string>
#include <iterator>
int main()
{
const std::string s[] = {"string", "1", "test", "..."};
const auto p = std::get_temporary_buffer<std::string>(4);
// requires that p.first is passed to return_temporary_buffer
// (beware of early exit points and exceptions)
std::copy(s, s + p.second,
std::raw_storage_iterator<std::string*, std::string>(p.first));
// requires that each string in p is individually destroyed
// (beware of early exit points and exceptions)
std::copy(p.first, p.first + p.second,
std::ostream_iterator<std::string>{std::cout, "\n"});
std::for_each(p.first, p.first + p.second, [](std::string& e) {
e.~basic_string<char>();
});
std::return_temporary_buffer(p.first);
}
出力:
string
1
test
...
関連項目
(C++17で非推奨)(C++20で削除) |
未初期化記憶域を取得します (関数テンプレート) |