Path: blob/main/contrib/llvm-project/libcxx/include/__memory/temp_value.h
35233 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___MEMORY_TEMP_VALUE_H9#define _LIBCPP___MEMORY_TEMP_VALUE_H1011#include <__config>12#include <__memory/addressof.h>13#include <__memory/allocator_traits.h>14#include <__type_traits/aligned_storage.h>15#include <__utility/forward.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_BEGIN_NAMESPACE_STD2223template <class _Tp, class _Alloc>24struct __temp_value {25typedef allocator_traits<_Alloc> _Traits;2627#ifdef _LIBCPP_CXX03_LANG28typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;29#else30union {31_Tp __v;32};33#endif34_Alloc& __a;3536_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __addr() {37#ifdef _LIBCPP_CXX03_LANG38return reinterpret_cast<_Tp*>(std::addressof(__v));39#else40return std::addressof(__v);41#endif42}4344_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& get() { return *__addr(); }4546template <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}5152_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__temp_value() { _Traits::destroy(__a, __addr()); }53};5455_LIBCPP_END_NAMESPACE_STD5657#endif // _LIBCPP___MEMORY_TEMP_VALUE_H585960