名前空間
変種
操作

std::get_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)
 
動的メモリ管理
未初期化記憶域
get_temporary_buffer
(C++20未満)
ガベージコレクションサポート
その他
(C++20)
(C++11)
(C++11)
C のライブラリ
低水準のメモリ管理
 
ヘッダ <memory> で定義
template<class T >
std::pair< T*, std::ptrdiff_t> get_temporary_buffer(std::ptrdiff_t count );
(C++17で非推奨)
(C++20で削除)

T 型の隣接したオブジェクトを最大 count 個格納するのに十分であるべき未初期化の連続記憶域を確保します。 この要求には拘束力がなく、処理系は count 個の隣接したオブジェクトを格納するのに必要なよりも多く、あるいは少なく、確保することがあります。

目次

[編集]引数

count - 所望のオブジェクト数

[編集]戻り値

確保した記憶域の先頭を指すポインタと、実際に確保された記憶域に収められるオブジェクトの数を保持する、 std::pair

メモリを確保できなかった場合、または確保された記憶域が T 型のオブジェクトを1個格納するにも十分でない場合、結果の first 要素はヌルポインタに、 second 要素はゼロになります。

[編集]例外

(なし)(C++11未満)
noexcept 指定:  
noexcept
  
(C++11以上)

[編集]

#include <algorithm>#include <iostream>#include <memory>#include <string>#include <iterator>   int main(){conststd::string s[]={"string", "1", "test", "..."};constauto 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]
close