名前空間
変種
操作

std::return_temporary_buffer

提供: cppreference.com
< cpp‎ | memory
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
動的メモリ管理
スマートポインタ
(C++11)
(C++11)
(C++11)
(C++17未満)
(C++11)
アロケータ
メモリリソース
未初期化記憶域
return_temporary_buffer
(C++20未満)
ガベージコレクションサポート
その他
(C++20)
(C++11)
(C++11)
C のライブラリ
低水準のメモリ管理
 
ヘッダ <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以上)

[編集]

#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で削除)
未初期化記憶域を取得します
(関数テンプレート) [edit]