2010-08-20 02:39:17 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===-------------------------- scoped_allocator --------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// 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
|
2010-08-20 02:39:17 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_SCOPED_ALLOCATOR
|
|
|
|
#define _LIBCPP_SCOPED_ALLOCATOR
|
|
|
|
|
|
|
|
/*
|
|
|
|
scoped_allocator synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class OuterAlloc, class... InnerAllocs>
|
|
|
|
class scoped_allocator_adaptor : public OuterAlloc
|
|
|
|
{
|
|
|
|
typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only
|
2010-08-22 08:02:43 +08:00
|
|
|
scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only
|
2010-08-20 02:39:17 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
typedef OuterAlloc outer_allocator_type;
|
|
|
|
typedef see below inner_allocator_type;
|
|
|
|
|
|
|
|
typedef typename OuterTraits::value_type value_type;
|
|
|
|
typedef typename OuterTraits::size_type size_type;
|
|
|
|
typedef typename OuterTraits::difference_type difference_type;
|
|
|
|
typedef typename OuterTraits::pointer pointer;
|
|
|
|
typedef typename OuterTraits::const_pointer const_pointer;
|
|
|
|
typedef typename OuterTraits::void_pointer void_pointer;
|
|
|
|
typedef typename OuterTraits::const_void_pointer const_void_pointer;
|
|
|
|
|
|
|
|
typedef see below propagate_on_container_copy_assignment;
|
|
|
|
typedef see below propagate_on_container_move_assignment;
|
|
|
|
typedef see below propagate_on_container_swap;
|
2015-06-03 00:34:03 +08:00
|
|
|
typedef see below is_always_equal;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class Tp>
|
|
|
|
struct rebind
|
|
|
|
{
|
|
|
|
typedef scoped_allocator_adaptor<
|
|
|
|
OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other;
|
|
|
|
};
|
|
|
|
|
|
|
|
scoped_allocator_adaptor();
|
|
|
|
template <class OuterA2>
|
|
|
|
scoped_allocator_adaptor(OuterA2&& outerAlloc,
|
2011-05-29 02:51:12 +08:00
|
|
|
const InnerAllocs&... innerAllocs) noexcept;
|
|
|
|
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
|
|
|
|
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class OuterA2>
|
2011-05-29 02:51:12 +08:00
|
|
|
scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class OuterA2>
|
2011-05-29 02:51:12 +08:00
|
|
|
scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2015-10-26 03:52:47 +08:00
|
|
|
scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
|
|
|
|
scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
|
2010-08-20 02:39:17 +08:00
|
|
|
~scoped_allocator_adaptor();
|
|
|
|
|
2011-05-29 02:51:12 +08:00
|
|
|
inner_allocator_type& inner_allocator() noexcept;
|
|
|
|
const inner_allocator_type& inner_allocator() const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2011-05-29 02:51:12 +08:00
|
|
|
outer_allocator_type& outer_allocator() noexcept;
|
|
|
|
const outer_allocator_type& outer_allocator() const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2017-11-26 10:55:38 +08:00
|
|
|
pointer allocate(size_type n); // [[nodiscard]] in C++20
|
|
|
|
pointer allocate(size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
|
2011-05-29 02:51:12 +08:00
|
|
|
void deallocate(pointer p, size_type n) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
size_type max_size() const;
|
|
|
|
template <class T, class... Args> void construct(T* p, Args&& args);
|
|
|
|
template <class T1, class T2, class... Args1, class... Args2>
|
|
|
|
void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x,
|
|
|
|
tuple<Args2...> y);
|
|
|
|
template <class T1, class T2>
|
|
|
|
void construct(pair<T1, T2>* p);
|
|
|
|
template <class T1, class T2, class U, class V>
|
|
|
|
void construct(pair<T1, T2>* p, U&& x, V&& y);
|
|
|
|
template <class T1, class T2, class U, class V>
|
|
|
|
void construct(pair<T1, T2>* p, const pair<U, V>& x);
|
|
|
|
template <class T1, class T2, class U, class V>
|
|
|
|
void construct(pair<T1, T2>* p, pair<U, V>&& x);
|
|
|
|
template <class T> void destroy(T* p);
|
|
|
|
|
2011-05-29 02:51:12 +08:00
|
|
|
template <class T> void destroy(T* p) noexcept;
|
|
|
|
|
|
|
|
scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
2021-10-28 15:36:19 +08:00
|
|
|
template<class OuterAlloc, class... InnerAllocs>
|
|
|
|
scoped_allocator_adaptor(OuterAlloc, InnerAllocs...)
|
|
|
|
-> scoped_allocator_adaptor<OuterAlloc, InnerAllocs...>;
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
|
|
|
bool
|
|
|
|
operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
2011-05-29 02:51:12 +08:00
|
|
|
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class OuterA1, class OuterA2, class... InnerAllocs>
|
|
|
|
bool
|
|
|
|
operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
|
2011-05-29 02:51:12 +08:00
|
|
|
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
2021-06-05 10:47:47 +08:00
|
|
|
#include <__utility/forward.h>
|
2010-08-20 02:39:17 +08:00
|
|
|
#include <memory>
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-08-20 02:39:17 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2016-09-25 11:34:28 +08:00
|
|
|
#if !defined(_LIBCPP_CXX03_LANG)
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
// scoped_allocator_adaptor
|
|
|
|
|
|
|
|
template <class ..._Allocs>
|
|
|
|
class scoped_allocator_adaptor;
|
|
|
|
|
|
|
|
template <class ..._Allocs> struct __get_poc_copy_assignment;
|
|
|
|
|
|
|
|
template <class _A0>
|
|
|
|
struct __get_poc_copy_assignment<_A0>
|
|
|
|
{
|
|
|
|
static const bool value = allocator_traits<_A0>::
|
|
|
|
propagate_on_container_copy_assignment::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _A0, class ..._Allocs>
|
|
|
|
struct __get_poc_copy_assignment<_A0, _Allocs...>
|
|
|
|
{
|
|
|
|
static const bool value =
|
|
|
|
allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
|
|
|
|
__get_poc_copy_assignment<_Allocs...>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Allocs> struct __get_poc_move_assignment;
|
|
|
|
|
|
|
|
template <class _A0>
|
|
|
|
struct __get_poc_move_assignment<_A0>
|
|
|
|
{
|
|
|
|
static const bool value = allocator_traits<_A0>::
|
|
|
|
propagate_on_container_move_assignment::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _A0, class ..._Allocs>
|
|
|
|
struct __get_poc_move_assignment<_A0, _Allocs...>
|
|
|
|
{
|
|
|
|
static const bool value =
|
|
|
|
allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
|
|
|
|
__get_poc_move_assignment<_Allocs...>::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class ..._Allocs> struct __get_poc_swap;
|
|
|
|
|
|
|
|
template <class _A0>
|
|
|
|
struct __get_poc_swap<_A0>
|
|
|
|
{
|
|
|
|
static const bool value = allocator_traits<_A0>::
|
|
|
|
propagate_on_container_swap::value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _A0, class ..._Allocs>
|
|
|
|
struct __get_poc_swap<_A0, _Allocs...>
|
|
|
|
{
|
|
|
|
static const bool value =
|
|
|
|
allocator_traits<_A0>::propagate_on_container_swap::value ||
|
|
|
|
__get_poc_swap<_Allocs...>::value;
|
|
|
|
};
|
|
|
|
|
2015-06-03 05:40:58 +08:00
|
|
|
template <class ..._Allocs> struct __get_is_always_equal;
|
|
|
|
|
|
|
|
template <class _A0>
|
|
|
|
struct __get_is_always_equal<_A0>
|
|
|
|
{
|
|
|
|
static const bool value = allocator_traits<_A0>::is_always_equal::value;
|
|
|
|
};
|
|
|
|
|
2015-06-03 00:34:03 +08:00
|
|
|
template <class _A0, class ..._Allocs>
|
2015-06-03 05:40:58 +08:00
|
|
|
struct __get_is_always_equal<_A0, _Allocs...>
|
2015-06-03 00:34:03 +08:00
|
|
|
{
|
|
|
|
static const bool value =
|
2015-06-04 00:15:55 +08:00
|
|
|
allocator_traits<_A0>::is_always_equal::value &&
|
2015-06-03 05:40:58 +08:00
|
|
|
__get_is_always_equal<_Allocs...>::value;
|
2015-06-03 00:34:03 +08:00
|
|
|
};
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class ..._Allocs>
|
|
|
|
class __scoped_allocator_storage;
|
|
|
|
|
|
|
|
template <class _OuterAlloc, class... _InnerAllocs>
|
|
|
|
class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
|
|
|
|
: public _OuterAlloc
|
|
|
|
{
|
|
|
|
typedef _OuterAlloc outer_allocator_type;
|
|
|
|
protected:
|
|
|
|
typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
|
|
|
|
|
|
|
|
private:
|
|
|
|
inner_allocator_type __inner_;
|
|
|
|
|
|
|
|
protected:
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
__scoped_allocator_storage() _NOEXCEPT {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
__scoped_allocator_storage(_OuterA2&& __outerAlloc,
|
2011-05-29 02:51:12 +08:00
|
|
|
const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)),
|
2010-08-20 02:39:17 +08:00
|
|
|
__inner_(__innerAllocs...) {}
|
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, const _OuterA2&>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
__scoped_allocator_storage(
|
2011-05-29 02:51:12 +08:00
|
|
|
const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
: outer_allocator_type(__other.outer_allocator()),
|
|
|
|
__inner_(__other.inner_allocator()) {}
|
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
__scoped_allocator_storage(
|
2011-05-29 02:51:12 +08:00
|
|
|
__scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: outer_allocator_type(_VSTD::move(__other.outer_allocator())),
|
|
|
|
__inner_(_VSTD::move(__other.inner_allocator())) {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__scoped_allocator_storage(_OuterA2&& __o,
|
2011-05-29 02:51:12 +08:00
|
|
|
const inner_allocator_type& __i) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: outer_allocator_type(_VSTD::forward<_OuterA2>(__o)),
|
2010-09-24 00:27:36 +08:00
|
|
|
__inner_(__i)
|
|
|
|
{
|
|
|
|
}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
inner_allocator_type& inner_allocator() _NOEXCEPT {return __inner_;}
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
outer_allocator_type& outer_allocator() _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return static_cast<outer_allocator_type&>(*this);}
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
const outer_allocator_type& outer_allocator() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return static_cast<const outer_allocator_type&>(*this);}
|
|
|
|
|
|
|
|
scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
select_on_container_copy_construction() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{
|
|
|
|
return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
|
|
|
|
(
|
|
|
|
allocator_traits<outer_allocator_type>::
|
|
|
|
select_on_container_copy_construction(outer_allocator()),
|
|
|
|
allocator_traits<inner_allocator_type>::
|
|
|
|
select_on_container_copy_construction(inner_allocator())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class...> friend class __scoped_allocator_storage;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _OuterAlloc>
|
|
|
|
class __scoped_allocator_storage<_OuterAlloc>
|
|
|
|
: public _OuterAlloc
|
|
|
|
{
|
|
|
|
typedef _OuterAlloc outer_allocator_type;
|
|
|
|
protected:
|
|
|
|
typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
__scoped_allocator_storage() _NOEXCEPT {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
__scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, const _OuterA2&>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
__scoped_allocator_storage(
|
2011-05-29 02:51:12 +08:00
|
|
|
const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
: outer_allocator_type(__other.outer_allocator()) {}
|
|
|
|
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
__scoped_allocator_storage(
|
2011-05-29 02:51:12 +08:00
|
|
|
__scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: outer_allocator_type(_VSTD::move(__other.outer_allocator())) {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
inner_allocator_type& inner_allocator() _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return static_cast<inner_allocator_type&>(*this);}
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
const inner_allocator_type& inner_allocator() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return static_cast<const inner_allocator_type&>(*this);}
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
outer_allocator_type& outer_allocator() _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return static_cast<outer_allocator_type&>(*this);}
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
const outer_allocator_type& outer_allocator() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return static_cast<const outer_allocator_type&>(*this);}
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
scoped_allocator_adaptor<outer_allocator_type>
|
2011-05-29 02:51:12 +08:00
|
|
|
select_on_container_copy_construction() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return scoped_allocator_adaptor<outer_allocator_type>(
|
|
|
|
allocator_traits<outer_allocator_type>::
|
|
|
|
select_on_container_copy_construction(outer_allocator())
|
|
|
|
);}
|
|
|
|
|
|
|
|
__scoped_allocator_storage(const outer_allocator_type& __o,
|
2011-05-29 02:51:12 +08:00
|
|
|
const inner_allocator_type& __i) _NOEXCEPT;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class...> friend class __scoped_allocator_storage;
|
|
|
|
};
|
|
|
|
|
|
|
|
// __outermost
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
decltype(declval<_Alloc>().outer_allocator(), true_type())
|
|
|
|
__has_outer_allocator_test(_Alloc&& __a);
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
false_type
|
|
|
|
__has_outer_allocator_test(const volatile _Alloc& __a);
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __has_outer_allocator
|
|
|
|
: public common_type
|
|
|
|
<
|
|
|
|
decltype(__has_outer_allocator_test(declval<_Alloc&>()))
|
|
|
|
>::type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
|
|
|
|
struct __outermost
|
|
|
|
{
|
|
|
|
typedef _Alloc type;
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
type& operator()(type& __a) const _NOEXCEPT {return __a;}
|
2010-08-20 02:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Alloc>
|
|
|
|
struct __outermost<_Alloc, true>
|
|
|
|
{
|
|
|
|
typedef typename remove_reference
|
|
|
|
<
|
2021-05-11 01:04:16 +08:00
|
|
|
decltype(declval<_Alloc>().outer_allocator())
|
2010-08-20 02:39:17 +08:00
|
|
|
>::type _OuterAlloc;
|
|
|
|
typedef typename __outermost<_OuterAlloc>::type type;
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
type& operator()(_Alloc& __a) const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return __outermost<_OuterAlloc>()(__a.outer_allocator());}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _OuterAlloc, class... _InnerAllocs>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
|
2010-08-20 02:39:17 +08:00
|
|
|
: public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
|
|
|
|
{
|
|
|
|
typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
|
|
|
|
typedef allocator_traits<_OuterAlloc> _OuterTraits;
|
|
|
|
public:
|
|
|
|
typedef _OuterAlloc outer_allocator_type;
|
|
|
|
typedef typename base::inner_allocator_type inner_allocator_type;
|
|
|
|
typedef typename _OuterTraits::size_type size_type;
|
|
|
|
typedef typename _OuterTraits::difference_type difference_type;
|
|
|
|
typedef typename _OuterTraits::pointer pointer;
|
|
|
|
typedef typename _OuterTraits::const_pointer const_pointer;
|
|
|
|
typedef typename _OuterTraits::void_pointer void_pointer;
|
|
|
|
typedef typename _OuterTraits::const_void_pointer const_void_pointer;
|
|
|
|
|
|
|
|
typedef integral_constant
|
|
|
|
<
|
|
|
|
bool,
|
|
|
|
__get_poc_copy_assignment<outer_allocator_type,
|
|
|
|
_InnerAllocs...>::value
|
|
|
|
> propagate_on_container_copy_assignment;
|
|
|
|
typedef integral_constant
|
|
|
|
<
|
|
|
|
bool,
|
|
|
|
__get_poc_move_assignment<outer_allocator_type,
|
|
|
|
_InnerAllocs...>::value
|
|
|
|
> propagate_on_container_move_assignment;
|
|
|
|
typedef integral_constant
|
|
|
|
<
|
|
|
|
bool,
|
|
|
|
__get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
|
|
|
|
> propagate_on_container_swap;
|
2015-06-03 00:34:03 +08:00
|
|
|
typedef integral_constant
|
|
|
|
<
|
|
|
|
bool,
|
2015-06-03 05:40:58 +08:00
|
|
|
__get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value
|
2015-06-03 00:34:03 +08:00
|
|
|
> is_always_equal;
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
struct rebind
|
|
|
|
{
|
|
|
|
typedef scoped_allocator_adaptor
|
|
|
|
<
|
|
|
|
typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
|
|
|
|
> other;
|
|
|
|
};
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
scoped_allocator_adaptor() _NOEXCEPT {}
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
|
2011-05-29 02:51:12 +08:00
|
|
|
const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
|
2010-08-20 02:39:17 +08:00
|
|
|
// scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, const _OuterA2&>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
scoped_allocator_adaptor(
|
2011-05-29 02:51:12 +08:00
|
|
|
const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
: base(__other) {}
|
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
scoped_allocator_adaptor(
|
2011-05-29 02:51:12 +08:00
|
|
|
scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: base(_VSTD::move(__other)) {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
2015-10-26 03:52:47 +08:00
|
|
|
// scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
|
|
|
|
// scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
|
2010-08-20 02:39:17 +08:00
|
|
|
// ~scoped_allocator_adaptor() = default;
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
inner_allocator_type& inner_allocator() _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return base::inner_allocator();}
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
const inner_allocator_type& inner_allocator() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return base::inner_allocator();}
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
outer_allocator_type& outer_allocator() _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return base::outer_allocator();}
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
const outer_allocator_type& outer_allocator() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return base::outer_allocator();}
|
|
|
|
|
2017-11-26 10:55:38 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
pointer allocate(size_type __n)
|
|
|
|
{return allocator_traits<outer_allocator_type>::
|
|
|
|
allocate(outer_allocator(), __n);}
|
2017-11-26 10:55:38 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
pointer allocate(size_type __n, const_void_pointer __hint)
|
|
|
|
{return allocator_traits<outer_allocator_type>::
|
|
|
|
allocate(outer_allocator(), __n, __hint);}
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
void deallocate(pointer __p, size_type __n) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{allocator_traits<outer_allocator_type>::
|
|
|
|
deallocate(outer_allocator(), __p, __n);}
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
size_type max_size() const
|
2010-09-24 00:27:36 +08:00
|
|
|
{return allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _Tp, class... _Args>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
void construct(_Tp* __p, _Args&& ...__args)
|
2016-12-15 05:29:29 +08:00
|
|
|
{__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(),
|
2011-07-01 05:18:19 +08:00
|
|
|
__p, _VSTD::forward<_Args>(__args)...);}
|
2016-12-15 05:29:29 +08:00
|
|
|
|
|
|
|
template <class _T1, class _T2, class... _Args1, class... _Args2>
|
|
|
|
void construct(pair<_T1, _T2>* __p, piecewise_construct_t,
|
|
|
|
tuple<_Args1...> __x, tuple<_Args2...> __y)
|
|
|
|
{
|
|
|
|
typedef __outermost<outer_allocator_type> _OM;
|
|
|
|
allocator_traits<typename _OM::type>::construct(
|
|
|
|
_OM()(outer_allocator()), __p, piecewise_construct
|
|
|
|
, __transform_tuple(
|
|
|
|
typename __uses_alloc_ctor<
|
|
|
|
_T1, inner_allocator_type&, _Args1...
|
|
|
|
>::type()
|
|
|
|
, _VSTD::move(__x)
|
|
|
|
, typename __make_tuple_indices<sizeof...(_Args1)>::type{}
|
|
|
|
)
|
|
|
|
, __transform_tuple(
|
|
|
|
typename __uses_alloc_ctor<
|
|
|
|
_T2, inner_allocator_type&, _Args2...
|
|
|
|
>::type()
|
|
|
|
, _VSTD::move(__y)
|
|
|
|
, typename __make_tuple_indices<sizeof...(_Args2)>::type{}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _T2>
|
|
|
|
void construct(pair<_T1, _T2>* __p)
|
|
|
|
{ construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); }
|
|
|
|
|
|
|
|
template <class _T1, class _T2, class _Up, class _Vp>
|
|
|
|
void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) {
|
|
|
|
construct(__p, piecewise_construct,
|
|
|
|
_VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x)),
|
|
|
|
_VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__y)));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _T2, class _Up, class _Vp>
|
|
|
|
void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) {
|
|
|
|
construct(__p, piecewise_construct,
|
|
|
|
_VSTD::forward_as_tuple(__x.first),
|
|
|
|
_VSTD::forward_as_tuple(__x.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _T1, class _T2, class _Up, class _Vp>
|
|
|
|
void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) {
|
|
|
|
construct(__p, piecewise_construct,
|
|
|
|
_VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)),
|
|
|
|
_VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second)));
|
|
|
|
}
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class _Tp>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
void destroy(_Tp* __p)
|
|
|
|
{
|
|
|
|
typedef __outermost<outer_allocator_type> _OM;
|
|
|
|
allocator_traits<typename _OM::type>::
|
|
|
|
destroy(_OM()(outer_allocator()), __p);
|
|
|
|
}
|
|
|
|
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-29 02:51:12 +08:00
|
|
|
scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{return base::select_on_container_copy_construction();}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-12-15 05:29:29 +08:00
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class _OuterA2,
|
|
|
|
class = typename enable_if<
|
|
|
|
is_constructible<outer_allocator_type, _OuterA2>::value
|
|
|
|
>::type>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
scoped_allocator_adaptor(_OuterA2&& __o,
|
2011-05-29 02:51:12 +08:00
|
|
|
const inner_allocator_type& __i) _NOEXCEPT
|
2011-07-01 05:18:19 +08:00
|
|
|
: base(_VSTD::forward<_OuterA2>(__o), __i) {}
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
template <class _Tp, class... _Args>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
|
|
|
|
{
|
|
|
|
typedef __outermost<outer_allocator_type> _OM;
|
|
|
|
allocator_traits<typename _OM::type>::construct
|
|
|
|
(
|
|
|
|
_OM()(outer_allocator()),
|
|
|
|
__p,
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Args>(__args)...
|
2010-08-20 02:39:17 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class... _Args>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
|
|
|
|
{
|
|
|
|
typedef __outermost<outer_allocator_type> _OM;
|
|
|
|
allocator_traits<typename _OM::type>::construct
|
|
|
|
(
|
|
|
|
_OM()(outer_allocator()),
|
2016-12-15 05:29:29 +08:00
|
|
|
__p, allocator_arg, inner_allocator(),
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Args>(__args)...
|
2010-08-20 02:39:17 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class... _Args>
|
2010-09-24 00:27:36 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-08-20 02:39:17 +08:00
|
|
|
void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
|
|
|
|
{
|
|
|
|
typedef __outermost<outer_allocator_type> _OM;
|
|
|
|
allocator_traits<typename _OM::type>::construct
|
|
|
|
(
|
|
|
|
_OM()(outer_allocator()),
|
|
|
|
__p,
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::forward<_Args>(__args)...,
|
2010-08-20 02:39:17 +08:00
|
|
|
inner_allocator()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-15 05:29:29 +08:00
|
|
|
template <class ..._Args, size_t ..._Idx>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
tuple<_Args&&...>
|
|
|
|
__transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t,
|
|
|
|
__tuple_indices<_Idx...>)
|
|
|
|
{
|
|
|
|
return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Args, size_t ..._Idx>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>
|
|
|
|
__transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t,
|
|
|
|
__tuple_indices<_Idx...>)
|
|
|
|
{
|
|
|
|
using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>;
|
|
|
|
return _Tup(allocator_arg, inner_allocator(),
|
|
|
|
_VSTD::get<_Idx>(_VSTD::move(__t))...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ..._Args, size_t ..._Idx>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
tuple<_Args&&..., inner_allocator_type&>
|
|
|
|
__transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t,
|
|
|
|
__tuple_indices<_Idx...>)
|
|
|
|
{
|
|
|
|
using _Tup = tuple<_Args&&..., inner_allocator_type&>;
|
|
|
|
return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., inner_allocator());
|
|
|
|
}
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class...> friend class __scoped_allocator_storage;
|
|
|
|
};
|
|
|
|
|
2021-10-28 15:36:19 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
|
|
|
template<class _OuterAlloc, class... _InnerAllocs>
|
|
|
|
scoped_allocator_adaptor(_OuterAlloc, _InnerAllocs...)
|
|
|
|
-> scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>;
|
|
|
|
#endif
|
|
|
|
|
2010-08-20 02:39:17 +08:00
|
|
|
template <class _OuterA1, class _OuterA2>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
|
2011-05-29 02:51:12 +08:00
|
|
|
const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{
|
|
|
|
return __a.outer_allocator() == __b.outer_allocator();
|
|
|
|
}
|
|
|
|
|
2011-05-18 04:41:18 +08:00
|
|
|
template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs>
|
2010-08-20 02:39:17 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
2011-05-18 04:41:18 +08:00
|
|
|
operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a,
|
2011-05-29 02:51:12 +08:00
|
|
|
const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{
|
|
|
|
return __a.outer_allocator() == __b.outer_allocator() &&
|
|
|
|
__a.inner_allocator() == __b.inner_allocator();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool
|
|
|
|
operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
|
2011-05-29 02:51:12 +08:00
|
|
|
const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT
|
2010-08-20 02:39:17 +08:00
|
|
|
{
|
|
|
|
return !(__a == __b);
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // !defined(_LIBCPP_CXX03_LANG)
|
2010-08-20 02:39:17 +08:00
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_SCOPED_ALLOCATOR
|