brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 8d10893 Raw
78 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___CXX03___MEMORY_CONSTRUCT_AT_H11#define _LIBCPP___CXX03___MEMORY_CONSTRUCT_AT_H12 13#include <__cxx03/__assert>14#include <__cxx03/__config>15#include <__cxx03/__iterator/access.h>16#include <__cxx03/__memory/addressof.h>17#include <__cxx03/__memory/voidify.h>18#include <__cxx03/__type_traits/enable_if.h>19#include <__cxx03/__type_traits/is_array.h>20#include <__cxx03/__utility/declval.h>21#include <__cxx03/__utility/forward.h>22#include <__cxx03/__utility/move.h>23#include <__cxx03/new>24 25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)26#  pragma GCC system_header27#endif28 29_LIBCPP_PUSH_MACROS30#include <__cxx03/__undef_macros>31 32_LIBCPP_BEGIN_NAMESPACE_STD33 34// construct_at35 36template <class _Tp, class... _Args, class = decltype(::new(std::declval<void*>()) _Tp(std::declval<_Args>()...))>37_LIBCPP_HIDE_FROM_ABI _Tp* __construct_at(_Tp* __location, _Args&&... __args) {38  return _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"),39         ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);40}41 42// destroy_at43 44// The internal functions are available regardless of the language version (with the exception of the `__destroy_at`45// taking an array).46 47template <class _ForwardIterator>48_LIBCPP_HIDE_FROM_ABI _ForwardIterator __destroy(_ForwardIterator, _ForwardIterator);49 50template <class _Tp, __enable_if_t<!is_array<_Tp>::value, int> = 0>51_LIBCPP_HIDE_FROM_ABI void __destroy_at(_Tp* __loc) {52  _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at");53  __loc->~_Tp();54}55 56template <class _ForwardIterator>57_LIBCPP_HIDE_FROM_ABI _ForwardIterator __destroy(_ForwardIterator __first, _ForwardIterator __last) {58  for (; __first != __last; ++__first)59    std::__destroy_at(std::addressof(*__first));60  return __first;61}62 63template <class _BidirectionalIterator>64_LIBCPP_HIDE_FROM_ABI _BidirectionalIterator65__reverse_destroy(_BidirectionalIterator __first, _BidirectionalIterator __last) {66  while (__last != __first) {67    --__last;68    std::__destroy_at(std::addressof(*__last));69  }70  return __last;71}72 73_LIBCPP_END_NAMESPACE_STD74 75_LIBCPP_POP_MACROS76 77#endif // _LIBCPP___CXX03___MEMORY_CONSTRUCT_AT_H78