| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#ifndef _LIBCPP___CXX03___MEMORY_TEMP_VALUE_H |
| 10 |
#define _LIBCPP___CXX03___MEMORY_TEMP_VALUE_H |
| 11 |
|
| 12 |
#include <__cxx03/__config> |
| 13 |
#include <__cxx03/__memory/addressof.h> |
| 14 |
#include <__cxx03/__memory/allocator_traits.h> |
| 15 |
#include <__cxx03/__type_traits/aligned_storage.h> |
| 16 |
#include <__cxx03/__utility/forward.h> |
| 17 |
|
| 18 |
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 19 |
# pragma GCC system_header |
| 20 |
#endif |
| 21 |
|
| 22 |
_LIBCPP_BEGIN_NAMESPACE_STD |
| 23 |
|
| 24 |
template <class _Tp, class _Alloc> |
| 25 |
struct __temp_value { |
| 26 |
typedef allocator_traits<_Alloc> _Traits; |
| 27 |
|
| 28 |
typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; |
| 29 |
_Alloc& __a; |
| 30 |
|
| 31 |
_LIBCPP_HIDE_FROM_ABI _Tp* __addr() { return reinterpret_cast<_Tp*>(std::addressof(__v)); } |
| 32 |
|
| 33 |
_LIBCPP_HIDE_FROM_ABI _Tp& get() { return *__addr(); } |
| 34 |
|
| 35 |
template <class... _Args> |
| 36 |
_LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI __temp_value(_Alloc& __alloc, _Args&&... __args) : __a(__alloc) { |
| 37 |
_Traits::construct(__a, __addr(), std::forward<_Args>(__args)...); |
| 38 |
} |
| 39 |
|
| 40 |
_LIBCPP_HIDE_FROM_ABI ~__temp_value() { _Traits::destroy(__a, __addr()); } |
| 41 |
}; |
| 42 |
|
| 43 |
_LIBCPP_END_NAMESPACE_STD |
| 44 |
|
| 45 |
#endif // _LIBCPP___CXX03___MEMORY_TEMP_VALUE_H |