[libc++] Split up __memory/base.h into meaningful headers

This commit is contained in:
Louis Dionne 2021-04-14 13:59:03 -04:00
parent 1c5717225e
commit f992cfba71
10 changed files with 72 additions and 42 deletions

View File

@ -13,11 +13,12 @@ set(files
__hash_table
__libcpp_version
__locale
__memory/addressof.h
__memory/allocator.h
__memory/allocator_traits.h
__memory/auto_ptr.h
__memory/base.h
__memory/compressed_pair.h
__memory/construct_at.h
__memory/pointer_safety.h
__memory/pointer_traits.h
__memory/raw_storage_iterator.h

View File

@ -7,12 +7,10 @@
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___MEMORY_BASE_H
#define _LIBCPP___MEMORY_BASE_H
#ifndef _LIBCPP___MEMORY_ADDRESSOF_H
#define _LIBCPP___MEMORY_ADDRESSOF_H
#include <__config>
#include <__debug>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@ -23,7 +21,6 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
// addressof
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
template <class _Tp>
@ -92,36 +89,8 @@ addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
#endif
// construct_at
#if _LIBCPP_STD_VER > 17
template<class _Tp, class ..._Args, class = decltype(
::new (_VSTD::declval<void*>()) _Tp(_VSTD::declval<_Args>()...)
)>
_LIBCPP_INLINE_VISIBILITY
constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
_LIBCPP_ASSERT(__location, "null pointer given to construct_at");
return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...);
}
#endif
// destroy_at
#if _LIBCPP_STD_VER > 14
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void destroy_at(_Tp* __loc) {
_LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
__loc->~_Tp();
}
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___MEMORY_BASE_H
#endif // _LIBCPP___MEMORY_ADDRESSOF_H

View File

@ -11,7 +11,7 @@
#define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H
#include <__config>
#include <__memory/base.h>
#include <__memory/construct_at.h>
#include <__memory/pointer_traits.h>
#include <limits>
#include <type_traits>

View File

@ -0,0 +1,58 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___MEMORY_CONSTRUCT_AT_H
#define _LIBCPP___MEMORY_CONSTRUCT_AT_H
#include <__config>
#include <__debug>
#include <utility>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
// construct_at
#if _LIBCPP_STD_VER > 17
template<class _Tp, class ..._Args, class = decltype(
::new (_VSTD::declval<void*>()) _Tp(_VSTD::declval<_Args>()...)
)>
_LIBCPP_INLINE_VISIBILITY
constexpr _Tp* construct_at(_Tp* __location, _Args&& ...__args) {
_LIBCPP_ASSERT(__location, "null pointer given to construct_at");
return ::new ((void*)__location) _Tp(_VSTD::forward<_Args>(__args)...);
}
#endif
// destroy_at
#if _LIBCPP_STD_VER > 14
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void destroy_at(_Tp* __loc) {
_LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
__loc->~_Tp();
}
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___MEMORY_CONSTRUCT_AT_H

View File

@ -11,7 +11,7 @@
#define _LIBCPP___MEMORY_RAW_STORAGE_ITERATOR_H
#include <__config>
#include <__memory/base.h> // addressof
#include <__memory/addressof.h>
#include <cstddef>
#include <iterator>
#include <utility>

View File

@ -13,10 +13,10 @@
#include <__config>
#include <__availability>
#include <__functional_base> // std::less, std::binary_function
#include <__memory/addressof.h>
#include <__memory/allocator.h>
#include <__memory/allocator_traits.h>
#include <__memory/auto_ptr.h>
#include <__memory/base.h> // std::addressof
#include <__memory/compressed_pair.h>
#include <__memory/pointer_traits.h>
#include <__memory/unique_ptr.h>

View File

@ -11,7 +11,8 @@
#define _LIBCPP___MEMORY_UNINITIALIZED_ALGORITHMS_H
#include <__config>
#include <__memory/base.h> // addressof, destroy_at
#include <__memory/addressof.h>
#include <__memory/construct_at.h>
#include <iterator>
#include <utility>

View File

@ -78,7 +78,7 @@ template <class E> void rethrow_if_nested(const E& e);
#include <__config>
#include <__availability>
#include <__memory/base.h>
#include <__memory/addressof.h>
#include <cstddef>
#include <cstdlib>
#include <type_traits>

View File

@ -425,7 +425,7 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
#include <concepts>
#include <cstddef>
#include <initializer_list>
#include <__memory/base.h>
#include <__memory/addressof.h>
#include <__memory/pointer_traits.h>
#include <version>
#include <concepts>

View File

@ -678,11 +678,12 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
#include <tuple>
#include <stdexcept>
#include <cstring>
#include <__memory/addressof.h>
#include <__memory/allocator.h>
#include <__memory/allocator_traits.h>
#include <__memory/auto_ptr.h>
#include <__memory/base.h>
#include <__memory/compressed_pair.h>
#include <__memory/construct_at.h>
#include <__memory/pointer_safety.h>
#include <__memory/pointer_traits.h>
#include <__memory/raw_storage_iterator.h>