1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H 11 #define _LIBCPP___MEMORY_CONSTRUCT_AT_H 12 13 #include <__config> 14 #include <__debug> 15 #include <__utility/forward.h> 16 #include <utility> 17 18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19 #pragma GCC system_header 20 #endif 21 22 _LIBCPP_PUSH_MACROS 23 #include <__undef_macros> 24 25 _LIBCPP_BEGIN_NAMESPACE_STD 26 27 // construct_at 28 29 #if _LIBCPP_STD_VER > 17 30 31 template<class _Tp, class ..._Args, class = decltype( 32 ::new (declval<void*>()) _Tp(declval<_Args>()...) 33 )> 34 _LIBCPP_INLINE_VISIBILITY 35 constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) { 36 _LIBCPP_ASSERT(__location, "null pointer given to construct_at"); 37 return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...); 38 } 39 40 #endif 41 42 // destroy_at 43 44 #if _LIBCPP_STD_VER > 14 45 46 template <class _Tp> 47 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 48 void destroy_at(_Tp* __loc) { 49 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at"); 50 __loc->~_Tp(); 51 } 52 53 #endif 54 55 _LIBCPP_END_NAMESPACE_STD 56 57 _LIBCPP_POP_MACROS 58 59 #endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H 60