brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 5285bca Raw
58 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___MEMORY_TEMP_VALUE_H10#define _LIBCPP___MEMORY_TEMP_VALUE_H11 12#include <__config>13#include <__memory/addressof.h>14#include <__memory/allocator_traits.h>15#include <__utility/forward.h>16 17#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18#  pragma GCC system_header19#endif20 21_LIBCPP_BEGIN_NAMESPACE_STD22 23template <class _Tp, class _Alloc>24struct __temp_value {25  typedef allocator_traits<_Alloc> _Traits;26 27#ifdef _LIBCPP_CXX03_LANG28  _ALIGNAS_TYPE(_Tp) char __v[sizeof(_Tp)];29#else30  union {31    _Tp __v;32  };33#endif34  _Alloc& __a;35 36  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __addr() {37#ifdef _LIBCPP_CXX03_LANG38    return reinterpret_cast<_Tp*>(std::addressof(__v));39#else40    return std::addressof(__v);41#endif42  }43 44  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& get() { return *__addr(); }45 46  template <class... _Args>47  _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_CONSTEXPR_SINCE_CXX20 __temp_value(_Alloc& __alloc, _Args&&... __args)48      : __a(__alloc) {49    _Traits::construct(__a, __addr(), std::forward<_Args>(__args)...);50  }51 52  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__temp_value() { _Traits::destroy(__a, __addr()); }53};54 55_LIBCPP_END_NAMESPACE_STD56 57#endif // _LIBCPP___MEMORY_TEMP_VALUE_H58