File indexing completed on 2026-05-03 08:14:06
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___UTILITY_NO_DESTROY_H
0010 #define _LIBCPP___UTILITY_NO_DESTROY_H
0011
0012 #include <__config>
0013 #include <__new/placement_new_delete.h>
0014 #include <__type_traits/is_constant_evaluated.h>
0015 #include <__utility/forward.h>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 _LIBCPP_BEGIN_NAMESPACE_STD
0022
0023 struct __uninitialized_tag {};
0024
0025
0026
0027
0028
0029
0030
0031 template <class _Tp>
0032 struct __no_destroy {
0033 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __no_destroy(__uninitialized_tag) : __obj_() {}
0034
0035 template <class... _Args>
0036 _LIBCPP_HIDE_FROM_ABI explicit __no_destroy(_Args&&... __args) {
0037 ::new ((void*)__obj_) _Tp(std::forward<_Args>(__args)...);
0038 }
0039
0040 template <class... _Args>
0041 _LIBCPP_HIDE_FROM_ABI _Tp& __emplace(_Args&&... __args) {
0042 return *(::new ((void*)__obj_) _Tp(std::forward<_Args>(__args)...));
0043 }
0044
0045 _LIBCPP_HIDE_FROM_ABI _Tp& __get() { return *reinterpret_cast<_Tp*>(__obj_); }
0046 _LIBCPP_HIDE_FROM_ABI _Tp const& __get() const { return *reinterpret_cast<const _Tp*>(__obj_); }
0047
0048 private:
0049 _ALIGNAS_TYPE(_Tp) char __obj_[sizeof(_Tp)];
0050 };
0051
0052 _LIBCPP_END_NAMESPACE_STD
0053
0054 #endif