for(;first!=last;++first)std::destroy_at(std::addressof(*first)); 2)同(1),但按照policy执行。此重载仅若std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>(C++20 前)std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>(C++20 起)为 true 才参与重载决议。
voiddestroy(ExecutionPolicy&&policy, ForwardIt first, ForwardIt last); (2)(C++17 起) 1)销毁范围[first, last)中的对象,如同用 for(;first!=last;++first)std::destroy_at(std::addressof(*first)); 2)同(1),但按照policy执行。此重载不参与重载决议,除非std::is_execution_policy_v<std::decay_t...
= last; ++first) std::destroy_at(std::addressof(*first));2) 同(1),但按照 policy 执行。此重载只有在满足以下所有条件时才会参与重载决议: std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> 是true。 (C++20 前) std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>> ...
template<class ForwardIt, class Size> constexpr // C++20 起 ForwardIt destroy_n( ForwardIt first, Size n ) { for (; n > 0; (void) ++first, --n) std::destroy_at(std::addressof(*first)); return first; } 示例 下列示例演示如何用 destroy_n 销毁元素的相接序列。运行...
{std::cout<<value<<" destructed\n";}};intmain(){alignas(Tracer)unsignedcharbuffer[sizeof(Tracer)*8];for(inti=0;i<8;++i)new(buffer+sizeof(Tracer)*i)Tracer{i};//manually construct objectsautoptr=std::launder(reinterpret_cast<Tracer*>(buffer));for(inti=0;i<8;++i)std::destroy_at(...
在某常量表达式 e 的求值中调用 destroy_at 时,参数 p 必须指向生存期始于 e 的求值内的对象。 (C++20 起)示例下列示例演示如何用 destroy_at 销毁元素的相接序列。 运行此代码 #include <iostream> #include <memory> #include <new> struct Tracer { int value; ~Tracer() { std::cout << value <...
题外话,我个人觉得有type traits之后pseudo destructor call就是历史遗留问题了。但有人提议让pseudo ...
traits_st::destroy(allocator_int,p);// 对 int 类型而言,上面这一行可以忽略// 然而对于像std:...
std::allocator_traits<OUTERMOST>::destroy(OUTERMOST(*this), p) 其中OUTERMOST 是调用 this->outer_allocator() ,之后在此调用的结果上递归调用 outer_allocator() 成员函数直至抵达无该成员函数的类型的返回类型。 参数p - 指向将被销毁的对象的指针 返回值(...
constexpr void destroy_at( T* p ) noexcept; (since C++20) If T is not an array type, calls the destructor of the object pointed to by p, as if by p->~T(). Otherwise, recursively destroys elements of *p in order, as if by calling std::destroy(std::begin(*p), std::end(*p...