Warning: This file is not a C or C++ file. It does not have highlighting.
| 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___CXX03___MEMORY_CONSTRUCT_AT_H |
| 11 | #define _LIBCPP___CXX03___MEMORY_CONSTRUCT_AT_H |
| 12 | |
| 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_header |
| 27 | #endif |
| 28 | |
| 29 | _LIBCPP_PUSH_MACROS |
| 30 | #include <__cxx03/__undef_macros> |
| 31 | |
| 32 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 33 | |
| 34 | // construct_at |
| 35 | |
| 36 | template <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_at |
| 43 | |
| 44 | // The internal functions are available regardless of the language version (with the exception of the `__destroy_at` |
| 45 | // taking an array). |
| 46 | |
| 47 | template <class _ForwardIterator> |
| 48 | _LIBCPP_HIDE_FROM_ABI _ForwardIterator __destroy(_ForwardIterator, _ForwardIterator); |
| 49 | |
| 50 | template <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 | |
| 56 | template <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 | |
| 63 | template <class _BidirectionalIterator> |
| 64 | _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator |
| 65 | __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_STD |
| 74 | |
| 75 | _LIBCPP_POP_MACROS |
| 76 | |
| 77 | #endif // _LIBCPP___CXX03___MEMORY_CONSTRUCT_AT_H |
| 78 |
Warning: This file is not a C or C++ file. It does not have highlighting.
