那么std::launder(p)返回T*类型的值,它指向对象x。否则行为未定义。 如果T是函数类型或(可有 cv 限定的)void,那么程序非良构。 std::launder可用于核心常量表达式,当且仅当它的(在转换后的)实参的值在函数调用的位置可使用。换言之,std::launder不放松常量求值中的限制。 注解 std::launder在它的实参上
cout << value << " 已析构\n"; } }; int main() { alignas(Tracer) unsigned char buffer[sizeof(Tracer) * 8]; for (int i = 0; i < 8; ++i) new(buffer + sizeof(Tracer) * i) Tracer{i}; // 手工构造对象 auto ptr = std::launder(reinterpret_cast<Tracer*>(buffer)); std::...
(this)A;return2;}};inlineintA::transmogrify(){::new(this)B;return1;}voidtest(){A i;intn=i.transmogrify();// int m = i.transmogrify(); // undefined behavior:// the new A object is a base subobject, while the old one is a complete objectintm=std::launder(&i)->trans...
launder (C++17) bad_alloc bad_array_new_length nothrow_t align_val_t destroying_delete_t new_handler nothrow Miscellaneous pointer_traits (C++11) to_address (C++20) addressof (C++11) align (C++11) assume_aligned (C++20) C Library malloc calloc realloc aligned_alloc (C++17) free std::...
__cpp_lib_launder CWG issue 1776: Replacement of class objects containing reference members (std::launder) 201606L (C++17) P0137R1 __cpp_lib_linalg A free function linear algebra interface based on the BLAS 202311L (C++26) P1673R13 __cpp_lib_list_remove_return_type Change the return...
(std::size_tpos=0;pos<m_size;++pos){// 注意:在 P0137R1 中的对象模型更改后需要 std::launderstd::destroy_at(std::launder(reinterpret_cast<T*>(&data[pos])));}}};intmain(){static_vector<std::string,10>v1;v1.emplace_back(5,'*');v1.emplace_back(10,'*');std::cout<<v1[0...
launder (C++17) bad_alloc bad_array_new_length nothrow_t align_val_t destroying_delete_t new_handler nothrow Miscellaneous pointer_traits (C++11) to_address (C++20) addressof (C++11) align (C++11) assume_aligned (C++20) C Library malloc calloc realloc aligned_alloc (C++17) free Defined...
launder (C++17) bad_alloc bad_array_new_length nothrow_t align_val_t destroying_delete_t new_handler nothrow Miscellaneous pointer_traits (C++11) to_address (C++20) addressof (C++11) align (C++11) assume_aligned (C++20) C Library malloc calloc realloc aligned_alloc (C++17) free std::...
{ alignas(Tracer) unsigned char buffer[sizeof(Tracer) * 8]; for (int i = 0; i < 8; ++i) new(buffer + sizeof(Tracer) * i) Tracer{i}; // 手工构造对象 auto ptr = std::launder(reinterpret_cast<Tracer*>(buffer)); for (int i = 0; i < 8; ++i) std::destroy_at(ptr + ...
(public member function of std::pmr::polymorphic_allocator<T>) allocate allocates uninitialized storage using the outer allocator (public member function of std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>) Indirect access launder (C++17) pointer optimization barrier (function templat...