std::destroy_n
| Defined in header <memory> |  |  | 
|---|---|---|
| template< class ForwardIt, class Size > ForwardIt destroy_n( ForwardIt first, Size n ); | (1) | (since C++17) | 
| template< class ExecutionPolicy, class ForwardIt, class Size > ForwardIt destroy_n( ExecutionPolicy&& policy, ForwardIt first, Size n ); | (2) | (since C++17) | 
1%29摧毁n对象范围内的对象,从first,好像
二次
for (; n > 0; (void) ++first, --n)
  std::destroy_at(std::addressof(*first));二次
2%29与%281%29相同,但根据policy此重载不参与过载解决,除非std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>是真的
参数
| first | - | the beginning of the range of elements to destroy | 
|---|---|---|
| n | - | the number of elements to destroy | 
| policy | - | the execution policy to use. See execution policy for details. | 
类型要求
---。
-不通过有效的Forward实例进行增量、赋值、比较或间接转换,否则会引发异常。
返回值
已销毁的对象范围的结束%28i。e.std::next(first, n)29%。
复杂性
线性在n...
例外
带有名为ExecutionPolicy报告错误如下:
- 如果执行作为算法一部分调用的函数,则引发异常ExecutionPolicy是其中之一标准政策,,,std::terminate叫做。对于任何其他人ExecutionPolicy,行为是由实现定义的。
- 如果算法不能分配内存,std::bad_alloc被扔了。
可能的实施
模板<类向前,类大小>向前销毁[医]n%28前进第一,大小n%29{表示%28;n>0;%28void%29++first,--n%29 std:销毁[医]地址::地址%28%2A第一%29%29;先返回;}
*。
例
另见
| destroy (C++17) | destroys a range of objects (function template) | 
|---|---|
| destroy_at (C++17) | destroys an object at a given address (function template) | 
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

