Home | History | Annotate | Line # | Download | only in __memory
      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>
     16 
     17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
     18 #pragma GCC system_header
     19 #endif
     20 
     21 _LIBCPP_PUSH_MACROS
     22 #include <__undef_macros>
     23 
     24 _LIBCPP_BEGIN_NAMESPACE_STD
     25 
     26 // construct_at
     27 
     28 #if _LIBCPP_STD_VER > 17
     29 
     30 template<class _Tp, class ..._Args, class = decltype(
     31     ::new (declval<void*>()) _Tp(declval<_Args>()...)
     32 )>
     33 _LIBCPP_INLINE_VISIBILITY
     34 constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
     35     _LIBCPP_ASSERT(__location, "null pointer given to construct_at");
     36     return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...);
     37 }
     38 
     39 #endif
     40 
     41 // destroy_at
     42 
     43 #if _LIBCPP_STD_VER > 14
     44 
     45 template <class _Tp>
     46 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     47 void destroy_at(_Tp* __loc) {
     48     _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
     49     __loc->~_Tp();
     50 }
     51 
     52 #endif
     53 
     54 _LIBCPP_END_NAMESPACE_STD
     55 
     56 _LIBCPP_POP_MACROS
     57 
     58 #endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H
     59