std::get_temporary_buffer
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <memory>
|
||
| template< class T > std::pair< T*, std::ptrdiff_t > get_temporary_buffer( std::ptrdiff_t count ) |
||
分配存储空间,足够存储多达
count相邻对象的类型T。如果没有足够的内存为所有count对象,分配不到count,如果可能的话.Original:
Allocates storage sufficient to store up to
count adjacent objects of type T. If there is insufficient memory for all count objects, allocates less than count, if possible.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| count | - | 要分配的对象的数量
Original: the number of objects to allocate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 返回值
一种std::pair保持一个指针到已分配的存储的开始和适合实际分配的存储在存储对象的数目(可能为零).
Original:
An std::pair holding a pointer to the beginning of the allocated storage and the number of objects that fit in the storage that was actually allocated (may be zero).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 例外
[编辑] 为例
#include <algorithm> #include <iostream> #include <memory> #include <string> int main() { const std::string s[] = {"string", "1", "test", "..."}; std::string* p = std::get_temporary_buffer<std::string>(4).first; std::copy(std::begin(s), std::end(s), std::raw_storage_iterator<std::string*, std::string>(p)); for (std::string* i = p; i != p+4; ++i) { std::cout << *i << '\n'; i->~basic_string<char>(); } std::return_temporary_buffer(p); }
Output:
string 1 test ...
[编辑] 另请参阅
| 释放未初始化的存储 Original: frees uninitialized storage The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |