2011-06-22 21:57:12 +02:00
|
|
|
// Allocator traits -*- C++ -*-
|
|
|
|
|
2020-01-01 12:51:42 +01:00
|
|
|
// Copyright (C) 2011-2020 Free Software Foundation, Inc.
|
2011-06-22 21:57:12 +02:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/** @file ext/alloc_traits.h
|
|
|
|
* This file is a GNU extension to the Standard C++ Library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _EXT_ALLOC_TRAITS_H
|
|
|
|
#define _EXT_ALLOC_TRAITS_H 1
|
|
|
|
|
|
|
|
#pragma GCC system_header
|
|
|
|
|
|
|
|
# include <bits/alloc_traits.h>
|
PR c++/91369 Implement P0784R7 changes to allocation and construction
This patch is the first part of library support for constexpr
std::vector and std::string. This only includes the changes to
std::allocator, std::allocator_traits, std::construct_at,
std::destroy_at, std::destroy and std::destroy_n.
std::allocator::allocate and std::allocator::deallocate need to be
added so that they can be intercepted by the compiler during constant
evaluation. Outside of constant evaluation those new member functions
just forward to the existing implementation in the base class.
PR c++/91369 Implement P0784R7 changes to allocation and construction
* include/bits/alloc_traits.h: Include <bits/stl_construct.h>.
(allocator_traits::_S_allocate, allocator_traits::_S_construct)
(allocator_traits::_S_destroy, allocator_traits::_S_max_size)
(allocator_traits::_S_select, allocator_traits::allocate)
(allocator_traits::deallocate, allocator_traits::construct)
(allocator_traits::destroy, allocator_traits::max_size)
(allocator_traits::select_on_container_copy_construction)
(allocator_traits<allocator<T>>): Add constexpr specifier for C++20.
(allocator_traits<allocator<T>>::construct): Use construct_at.
(allocator_traits<allocator<T>>::destroy): Use destroy_at.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Add constexpr
specifier.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move here
from <bits/stl_construct.h>.
* include/bits/allocator.h (allocator::~allocator): Remove for C++20.
(allocator::allocate, allocate::deallocate): Define for C++20 and up.
(operator==, operator!=): Add constexpr specifier for C++20.
* include/bits/stl_construct.h: Don't include <ext/alloc_traits.h>.
(destroy_at): For C++20 add constexpr specifier and support for
destroying arrays.
(construct_at): Define new function for C++20.
(_Construct): Return result of placement new-expression. For C++11 and
up add constexpr. For C++20 dispatch to std::construct_at during
constant evaluation.
(_Destroy(pointer)): Add constexpr specifier. For C++20 dispatch to
std::destroy_at during constant evaluation.
(_Destroy_aux::__destroy, _Destroy_n_aux::__destroy_n): Add constexpr
specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator))
(_Destroy(ForwardIterator, Size)): Likewise. Do not elide trivial
destructors during constant evaluation.
(destroy, destroy_n): Add constexpr specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move to
<bits/alloc_traits.h>, to remove dependency on allocators.
* include/bits/stl_uninitialized.h: Include <ext/alloc_traits.h>.
Include <bits/stl_pair.h> instead of <utility>.
* include/ext/alloc_traits.h: Always include <bits/alloc_traits.h>.
(__alloc_traits::construct, __alloc_traits::destroy)
(__alloc_traits::_S_select_on_copy, __alloc_traits::_S_on_swap): Add
constexpr specifier.
* include/ext/malloc_allocator.h (operator==, operator!=): Add
constexpr specifier for C++20.
* include/ext/new_allocator.h (operator==, operator!=): Likewise.
* testsuite/20_util/headers/memory/synopsis.cc: Add constexpr.
* testsuite/20_util/scoped_allocator/69293_neg.cc: Ignore additional
errors due to constexpr function called after failed static_assert.
* testsuite/20_util/specialized_algorithms/construct_at/1.cc: New test.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Ignore additional errors due to constexpr function called after failed
static_assert.
* testsuite/23_containers/vector/cons/destructible_neg.cc: Likewise.
From-SVN: r277342
2019-10-23 19:42:11 +02:00
|
|
|
#if __cplusplus < 201103L
|
2011-06-22 21:57:12 +02:00
|
|
|
# include <bits/allocator.h> // for __alloc_swap
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
|
|
|
|
{
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
|
2011-07-09 14:48:32 +02:00
|
|
|
/**
|
Implement N4258 (Cleaning-up noexcept in the Library rev 3)
* doc/xml/manual/intro.xml: Document LWG 2108 status.
* include/bits/alloc_traits.h (allocator_traits::is_always_equal):
Define.
* include/bits/allocator.h (allocator::is_always_equal): Likewise.
* include/bits/forward_list.h
(forward_list::operator=(forward_list&&)): Use __bool_constant.
(forward_list::swap(forward_list&)): Add noexcept.
* include/bits/hashtable.h (_Hashtable::operator=(_Hashtable&&)):
Likewise.
(_Hashtable::swap(_Hashtable&)): Likewise.
* include/bits/stl_deque.h (_Deque_base::_Deque_base(_Deque_base&&)):
Use _Alloc_traits::is_always_equal.
(deque::operator=(deque&&)): Likewise.
(deque::_M_move_assign1(deque&&, false_type)): Add comment and use
__bool_constant.
(swap(deque&, deque&)): Add noexcept.
* include/bits/stl_list.h (list::operator=(list&&)): Use
__bool_constant.
(swap(list&, list&)): Add noexcept.
* include/bits/stl_map.h (map::swap(map&)): Include _Compare in
noexcept.
(swap(map&, map&)): Add noexcept.
* include/bits/stl_multimap.h (multimap::swap(multimap&)): Include
_Compare in noexcept.
(swap(multimap&, multimap&)): Add noexcept.
* include/bits/stl_multiset.h (multiset::swap(multiset&)): Include
_Compare in noexcept.
(swap(multiset&, multiset&)): Add noexcept.
* include/bits/stl_set.h (set::swap(set&)): Include _Compare in
noexcept.
(swap(set&, set&)): Add noexcept.
* include/bits/stl_tree.h (_Rb_tree::operator=(_Rb_tree&&)): Include
_Compare in noexcept.
(_Rb_tree::_Rb_tree(_Rb_tree&&, _Node_alloc_type&&)): Use
is_always_equal.
* include/bits/stl_vector.h (vector::operator=(vector&&)): Use
__bool_constant.
(swap(vector&, vector&)): Add noexcept.
* include/bits/unordered_map.h (swap(unordered_map&, unordered_map&),
swap(unordered_multimap& unordered_multimap&)): Add noexcept.
* include/bits/unordered_set.h (swap(unordered_set&, unordered_set&),
swap(unordered_multiset& unordered_multiset&)): Add noexcept.
* include/ext/alloc_traits.h (__allocator_always_compares_equal):
Remove.
(__alloc_traits::_S_always_equal()): Use is_always_equal instead of
__allocator_always_compares_equal.
* include/ext/array_allocator.h (array_allocator::is_always_equal):
Define.
* include/std/scoped_allocator (__any_of, __propagate_on_copy,
__propagate_on_move, __propagate_on_swap): Remove.
(scoped_allocator_adaptor::propagate_on_container_copy_assignment,
scoped_allocator_adaptor::propagate_on_container_move_assignment,
scoped_allocator_adaptor::propagate_on_container_swap): Define with
__and_ instead of __any_of.
(scoped_allocator_adaptor::is_always_equal): Define.
* testsuite/20_util/allocator_traits/members/is_always_equal.cc: New.
* testsuite/20_util/scoped_allocator/propagation.cc: Make traits
derive from true_type or false_type.
* testsuite/23_containers/deque/allocator/move_assign-2.cc: Add
is_always_equal member and remove the trait specialization.
* testsuite/23_containers/vector/52591.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
Adjust dg-error line number.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
Likewise.
From-SVN: r225081
2015-06-26 22:10:24 +02:00
|
|
|
* @brief Uniform interface to C++98 and C++11 allocators.
|
2011-07-09 14:48:32 +02:00
|
|
|
* @ingroup allocators
|
|
|
|
*/
|
2017-06-07 14:35:08 +02:00
|
|
|
template<typename _Alloc, typename = typename _Alloc::value_type>
|
2011-06-22 21:57:12 +02:00
|
|
|
struct __alloc_traits
|
2012-11-10 18:27:22 +01:00
|
|
|
#if __cplusplus >= 201103L
|
2011-06-22 21:57:12 +02:00
|
|
|
: std::allocator_traits<_Alloc>
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
typedef _Alloc allocator_type;
|
2012-11-10 18:27:22 +01:00
|
|
|
#if __cplusplus >= 201103L
|
2011-06-22 21:57:12 +02:00
|
|
|
typedef std::allocator_traits<_Alloc> _Base_type;
|
|
|
|
typedef typename _Base_type::value_type value_type;
|
|
|
|
typedef typename _Base_type::pointer pointer;
|
|
|
|
typedef typename _Base_type::const_pointer const_pointer;
|
|
|
|
typedef typename _Base_type::size_type size_type;
|
2012-04-22 16:38:33 +02:00
|
|
|
typedef typename _Base_type::difference_type difference_type;
|
2014-01-29 15:57:35 +01:00
|
|
|
// C++11 allocators do not define reference or const_reference
|
2011-06-22 21:57:12 +02:00
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
|
|
|
using _Base_type::allocate;
|
|
|
|
using _Base_type::deallocate;
|
|
|
|
using _Base_type::construct;
|
|
|
|
using _Base_type::destroy;
|
2011-10-04 22:34:54 +02:00
|
|
|
using _Base_type::max_size;
|
2011-06-22 21:57:12 +02:00
|
|
|
|
2011-07-09 14:48:32 +02:00
|
|
|
private:
|
|
|
|
template<typename _Ptr>
|
2014-01-29 15:57:35 +01:00
|
|
|
using __is_custom_pointer
|
|
|
|
= std::__and_<std::is_same<pointer, _Ptr>,
|
|
|
|
std::__not_<std::is_pointer<_Ptr>>>;
|
2011-07-09 14:48:32 +02:00
|
|
|
|
|
|
|
public:
|
2011-10-04 22:34:54 +02:00
|
|
|
// overload construct for non-standard pointer types
|
2011-07-09 14:48:32 +02:00
|
|
|
template<typename _Ptr, typename... _Args>
|
2019-10-29 21:16:57 +01:00
|
|
|
static _GLIBCXX14_CONSTEXPR
|
|
|
|
std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
|
2011-07-09 14:48:32 +02:00
|
|
|
construct(_Alloc& __a, _Ptr __p, _Args&&... __args)
|
Relocation (= move+destroy)
2018-10-25 Marc Glisse <marc.glisse@inria.fr>
PR libstdc++/87106
* include/bits/alloc_traits.h (_S_construct, _S_destroy, construct,
destroy): Add noexcept specification.
* include/bits/allocator.h (construct, destroy): Likewise.
* include/ext/alloc_traits.h (construct, destroy): Likewise.
* include/ext/malloc_allocator.h (construct, destroy): Likewise.
* include/ext/new_allocator.h (construct, destroy): Likewise.
* include/bits/stl_uninitialized.h (__relocate_object_a, __relocate_a,
__relocate_a_1): New functions.
(__is_trivially_relocatable): New class.
* include/bits/stl_vector.h (__use_relocate): New static member.
* include/bits/vector.tcc (reserve, _M_realloc_insert,
_M_default_append): Use __relocate_a.
(reserve, _M_assign_aux, _M_realloc_insert, _M_fill_insert,
_M_default_append, _M_range_insert): Move _GLIBCXX_ASAN_ANNOTATE_REINIT
after _Destroy.
* testsuite/23_containers/vector/modifiers/push_back/49836.cc:
Replace CopyConsOnlyType with DelAnyAssign.
From-SVN: r265485
2018-10-25 15:03:13 +02:00
|
|
|
noexcept(noexcept(_Base_type::construct(__a, std::__to_address(__p),
|
|
|
|
std::forward<_Args>(__args)...)))
|
2011-07-09 14:48:32 +02:00
|
|
|
{
|
2017-09-13 09:27:40 +02:00
|
|
|
_Base_type::construct(__a, std::__to_address(__p),
|
2011-07-09 14:48:32 +02:00
|
|
|
std::forward<_Args>(__args)...);
|
|
|
|
}
|
|
|
|
|
2011-10-04 22:34:54 +02:00
|
|
|
// overload destroy for non-standard pointer types
|
2011-07-09 14:48:32 +02:00
|
|
|
template<typename _Ptr>
|
2019-10-29 21:16:57 +01:00
|
|
|
static _GLIBCXX14_CONSTEXPR
|
|
|
|
std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
|
2011-07-09 14:48:32 +02:00
|
|
|
destroy(_Alloc& __a, _Ptr __p)
|
Relocation (= move+destroy)
2018-10-25 Marc Glisse <marc.glisse@inria.fr>
PR libstdc++/87106
* include/bits/alloc_traits.h (_S_construct, _S_destroy, construct,
destroy): Add noexcept specification.
* include/bits/allocator.h (construct, destroy): Likewise.
* include/ext/alloc_traits.h (construct, destroy): Likewise.
* include/ext/malloc_allocator.h (construct, destroy): Likewise.
* include/ext/new_allocator.h (construct, destroy): Likewise.
* include/bits/stl_uninitialized.h (__relocate_object_a, __relocate_a,
__relocate_a_1): New functions.
(__is_trivially_relocatable): New class.
* include/bits/stl_vector.h (__use_relocate): New static member.
* include/bits/vector.tcc (reserve, _M_realloc_insert,
_M_default_append): Use __relocate_a.
(reserve, _M_assign_aux, _M_realloc_insert, _M_fill_insert,
_M_default_append, _M_range_insert): Move _GLIBCXX_ASAN_ANNOTATE_REINIT
after _Destroy.
* testsuite/23_containers/vector/modifiers/push_back/49836.cc:
Replace CopyConsOnlyType with DelAnyAssign.
From-SVN: r265485
2018-10-25 15:03:13 +02:00
|
|
|
noexcept(noexcept(_Base_type::destroy(__a, std::__to_address(__p))))
|
2017-09-13 09:27:40 +02:00
|
|
|
{ _Base_type::destroy(__a, std::__to_address(__p)); }
|
2011-07-09 14:48:32 +02:00
|
|
|
|
PR c++/91369 Implement P0784R7 changes to allocation and construction
This patch is the first part of library support for constexpr
std::vector and std::string. This only includes the changes to
std::allocator, std::allocator_traits, std::construct_at,
std::destroy_at, std::destroy and std::destroy_n.
std::allocator::allocate and std::allocator::deallocate need to be
added so that they can be intercepted by the compiler during constant
evaluation. Outside of constant evaluation those new member functions
just forward to the existing implementation in the base class.
PR c++/91369 Implement P0784R7 changes to allocation and construction
* include/bits/alloc_traits.h: Include <bits/stl_construct.h>.
(allocator_traits::_S_allocate, allocator_traits::_S_construct)
(allocator_traits::_S_destroy, allocator_traits::_S_max_size)
(allocator_traits::_S_select, allocator_traits::allocate)
(allocator_traits::deallocate, allocator_traits::construct)
(allocator_traits::destroy, allocator_traits::max_size)
(allocator_traits::select_on_container_copy_construction)
(allocator_traits<allocator<T>>): Add constexpr specifier for C++20.
(allocator_traits<allocator<T>>::construct): Use construct_at.
(allocator_traits<allocator<T>>::destroy): Use destroy_at.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Add constexpr
specifier.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move here
from <bits/stl_construct.h>.
* include/bits/allocator.h (allocator::~allocator): Remove for C++20.
(allocator::allocate, allocate::deallocate): Define for C++20 and up.
(operator==, operator!=): Add constexpr specifier for C++20.
* include/bits/stl_construct.h: Don't include <ext/alloc_traits.h>.
(destroy_at): For C++20 add constexpr specifier and support for
destroying arrays.
(construct_at): Define new function for C++20.
(_Construct): Return result of placement new-expression. For C++11 and
up add constexpr. For C++20 dispatch to std::construct_at during
constant evaluation.
(_Destroy(pointer)): Add constexpr specifier. For C++20 dispatch to
std::destroy_at during constant evaluation.
(_Destroy_aux::__destroy, _Destroy_n_aux::__destroy_n): Add constexpr
specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator))
(_Destroy(ForwardIterator, Size)): Likewise. Do not elide trivial
destructors during constant evaluation.
(destroy, destroy_n): Add constexpr specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move to
<bits/alloc_traits.h>, to remove dependency on allocators.
* include/bits/stl_uninitialized.h: Include <ext/alloc_traits.h>.
Include <bits/stl_pair.h> instead of <utility>.
* include/ext/alloc_traits.h: Always include <bits/alloc_traits.h>.
(__alloc_traits::construct, __alloc_traits::destroy)
(__alloc_traits::_S_select_on_copy, __alloc_traits::_S_on_swap): Add
constexpr specifier.
* include/ext/malloc_allocator.h (operator==, operator!=): Add
constexpr specifier for C++20.
* include/ext/new_allocator.h (operator==, operator!=): Likewise.
* testsuite/20_util/headers/memory/synopsis.cc: Add constexpr.
* testsuite/20_util/scoped_allocator/69293_neg.cc: Ignore additional
errors due to constexpr function called after failed static_assert.
* testsuite/20_util/specialized_algorithms/construct_at/1.cc: New test.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Ignore additional errors due to constexpr function called after failed
static_assert.
* testsuite/23_containers/vector/cons/destructible_neg.cc: Likewise.
From-SVN: r277342
2019-10-23 19:42:11 +02:00
|
|
|
static constexpr _Alloc _S_select_on_copy(const _Alloc& __a)
|
2011-06-22 21:57:12 +02:00
|
|
|
{ return _Base_type::select_on_container_copy_construction(__a); }
|
|
|
|
|
2019-10-29 21:16:57 +01:00
|
|
|
static _GLIBCXX14_CONSTEXPR void _S_on_swap(_Alloc& __a, _Alloc& __b)
|
2011-06-22 21:57:12 +02:00
|
|
|
{ std::__alloc_on_swap(__a, __b); }
|
|
|
|
|
|
|
|
static constexpr bool _S_propagate_on_copy_assign()
|
|
|
|
{ return _Base_type::propagate_on_container_copy_assignment::value; }
|
|
|
|
|
|
|
|
static constexpr bool _S_propagate_on_move_assign()
|
|
|
|
{ return _Base_type::propagate_on_container_move_assignment::value; }
|
|
|
|
|
|
|
|
static constexpr bool _S_propagate_on_swap()
|
|
|
|
{ return _Base_type::propagate_on_container_swap::value; }
|
|
|
|
|
2011-07-09 14:48:32 +02:00
|
|
|
static constexpr bool _S_always_equal()
|
Implement N4258 (Cleaning-up noexcept in the Library rev 3)
* doc/xml/manual/intro.xml: Document LWG 2108 status.
* include/bits/alloc_traits.h (allocator_traits::is_always_equal):
Define.
* include/bits/allocator.h (allocator::is_always_equal): Likewise.
* include/bits/forward_list.h
(forward_list::operator=(forward_list&&)): Use __bool_constant.
(forward_list::swap(forward_list&)): Add noexcept.
* include/bits/hashtable.h (_Hashtable::operator=(_Hashtable&&)):
Likewise.
(_Hashtable::swap(_Hashtable&)): Likewise.
* include/bits/stl_deque.h (_Deque_base::_Deque_base(_Deque_base&&)):
Use _Alloc_traits::is_always_equal.
(deque::operator=(deque&&)): Likewise.
(deque::_M_move_assign1(deque&&, false_type)): Add comment and use
__bool_constant.
(swap(deque&, deque&)): Add noexcept.
* include/bits/stl_list.h (list::operator=(list&&)): Use
__bool_constant.
(swap(list&, list&)): Add noexcept.
* include/bits/stl_map.h (map::swap(map&)): Include _Compare in
noexcept.
(swap(map&, map&)): Add noexcept.
* include/bits/stl_multimap.h (multimap::swap(multimap&)): Include
_Compare in noexcept.
(swap(multimap&, multimap&)): Add noexcept.
* include/bits/stl_multiset.h (multiset::swap(multiset&)): Include
_Compare in noexcept.
(swap(multiset&, multiset&)): Add noexcept.
* include/bits/stl_set.h (set::swap(set&)): Include _Compare in
noexcept.
(swap(set&, set&)): Add noexcept.
* include/bits/stl_tree.h (_Rb_tree::operator=(_Rb_tree&&)): Include
_Compare in noexcept.
(_Rb_tree::_Rb_tree(_Rb_tree&&, _Node_alloc_type&&)): Use
is_always_equal.
* include/bits/stl_vector.h (vector::operator=(vector&&)): Use
__bool_constant.
(swap(vector&, vector&)): Add noexcept.
* include/bits/unordered_map.h (swap(unordered_map&, unordered_map&),
swap(unordered_multimap& unordered_multimap&)): Add noexcept.
* include/bits/unordered_set.h (swap(unordered_set&, unordered_set&),
swap(unordered_multiset& unordered_multiset&)): Add noexcept.
* include/ext/alloc_traits.h (__allocator_always_compares_equal):
Remove.
(__alloc_traits::_S_always_equal()): Use is_always_equal instead of
__allocator_always_compares_equal.
* include/ext/array_allocator.h (array_allocator::is_always_equal):
Define.
* include/std/scoped_allocator (__any_of, __propagate_on_copy,
__propagate_on_move, __propagate_on_swap): Remove.
(scoped_allocator_adaptor::propagate_on_container_copy_assignment,
scoped_allocator_adaptor::propagate_on_container_move_assignment,
scoped_allocator_adaptor::propagate_on_container_swap): Define with
__and_ instead of __any_of.
(scoped_allocator_adaptor::is_always_equal): Define.
* testsuite/20_util/allocator_traits/members/is_always_equal.cc: New.
* testsuite/20_util/scoped_allocator/propagation.cc: Make traits
derive from true_type or false_type.
* testsuite/23_containers/deque/allocator/move_assign-2.cc: Add
is_always_equal member and remove the trait specialization.
* testsuite/23_containers/vector/52591.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
Adjust dg-error line number.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
Likewise.
From-SVN: r225081
2015-06-26 22:10:24 +02:00
|
|
|
{ return _Base_type::is_always_equal::value; }
|
2011-07-09 14:48:32 +02:00
|
|
|
|
|
|
|
static constexpr bool _S_nothrow_move()
|
|
|
|
{ return _S_propagate_on_move_assign() || _S_always_equal(); }
|
|
|
|
|
2011-10-04 22:34:54 +02:00
|
|
|
template<typename _Tp>
|
|
|
|
struct rebind
|
2011-11-08 01:33:45 +01:00
|
|
|
{ typedef typename _Base_type::template rebind_alloc<_Tp> other; };
|
PR c++/91369 Implement P0784R7 changes to allocation and construction
This patch is the first part of library support for constexpr
std::vector and std::string. This only includes the changes to
std::allocator, std::allocator_traits, std::construct_at,
std::destroy_at, std::destroy and std::destroy_n.
std::allocator::allocate and std::allocator::deallocate need to be
added so that they can be intercepted by the compiler during constant
evaluation. Outside of constant evaluation those new member functions
just forward to the existing implementation in the base class.
PR c++/91369 Implement P0784R7 changes to allocation and construction
* include/bits/alloc_traits.h: Include <bits/stl_construct.h>.
(allocator_traits::_S_allocate, allocator_traits::_S_construct)
(allocator_traits::_S_destroy, allocator_traits::_S_max_size)
(allocator_traits::_S_select, allocator_traits::allocate)
(allocator_traits::deallocate, allocator_traits::construct)
(allocator_traits::destroy, allocator_traits::max_size)
(allocator_traits::select_on_container_copy_construction)
(allocator_traits<allocator<T>>): Add constexpr specifier for C++20.
(allocator_traits<allocator<T>>::construct): Use construct_at.
(allocator_traits<allocator<T>>::destroy): Use destroy_at.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Add constexpr
specifier.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move here
from <bits/stl_construct.h>.
* include/bits/allocator.h (allocator::~allocator): Remove for C++20.
(allocator::allocate, allocate::deallocate): Define for C++20 and up.
(operator==, operator!=): Add constexpr specifier for C++20.
* include/bits/stl_construct.h: Don't include <ext/alloc_traits.h>.
(destroy_at): For C++20 add constexpr specifier and support for
destroying arrays.
(construct_at): Define new function for C++20.
(_Construct): Return result of placement new-expression. For C++11 and
up add constexpr. For C++20 dispatch to std::construct_at during
constant evaluation.
(_Destroy(pointer)): Add constexpr specifier. For C++20 dispatch to
std::destroy_at during constant evaluation.
(_Destroy_aux::__destroy, _Destroy_n_aux::__destroy_n): Add constexpr
specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator))
(_Destroy(ForwardIterator, Size)): Likewise. Do not elide trivial
destructors during constant evaluation.
(destroy, destroy_n): Add constexpr specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move to
<bits/alloc_traits.h>, to remove dependency on allocators.
* include/bits/stl_uninitialized.h: Include <ext/alloc_traits.h>.
Include <bits/stl_pair.h> instead of <utility>.
* include/ext/alloc_traits.h: Always include <bits/alloc_traits.h>.
(__alloc_traits::construct, __alloc_traits::destroy)
(__alloc_traits::_S_select_on_copy, __alloc_traits::_S_on_swap): Add
constexpr specifier.
* include/ext/malloc_allocator.h (operator==, operator!=): Add
constexpr specifier for C++20.
* include/ext/new_allocator.h (operator==, operator!=): Likewise.
* testsuite/20_util/headers/memory/synopsis.cc: Add constexpr.
* testsuite/20_util/scoped_allocator/69293_neg.cc: Ignore additional
errors due to constexpr function called after failed static_assert.
* testsuite/20_util/specialized_algorithms/construct_at/1.cc: New test.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Ignore additional errors due to constexpr function called after failed
static_assert.
* testsuite/23_containers/vector/cons/destructible_neg.cc: Likewise.
From-SVN: r277342
2019-10-23 19:42:11 +02:00
|
|
|
#else // ! C++11
|
2011-06-22 21:57:12 +02:00
|
|
|
|
|
|
|
typedef typename _Alloc::pointer pointer;
|
|
|
|
typedef typename _Alloc::const_pointer const_pointer;
|
|
|
|
typedef typename _Alloc::value_type value_type;
|
|
|
|
typedef typename _Alloc::reference reference;
|
|
|
|
typedef typename _Alloc::const_reference const_reference;
|
|
|
|
typedef typename _Alloc::size_type size_type;
|
2012-04-22 16:38:33 +02:00
|
|
|
typedef typename _Alloc::difference_type difference_type;
|
2011-06-22 21:57:12 +02:00
|
|
|
|
2019-01-21 12:47:30 +01:00
|
|
|
_GLIBCXX_NODISCARD static pointer
|
2011-06-22 21:57:12 +02:00
|
|
|
allocate(_Alloc& __a, size_type __n)
|
|
|
|
{ return __a.allocate(__n); }
|
|
|
|
|
2019-10-23 18:14:28 +02:00
|
|
|
template<typename _Hint>
|
|
|
|
_GLIBCXX_NODISCARD static pointer
|
|
|
|
allocate(_Alloc& __a, size_type __n, _Hint __hint)
|
|
|
|
{ return __a.allocate(__n, __hint); }
|
|
|
|
|
2011-06-22 21:57:12 +02:00
|
|
|
static void deallocate(_Alloc& __a, pointer __p, size_type __n)
|
|
|
|
{ __a.deallocate(__p, __n); }
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
static void construct(_Alloc& __a, pointer __p, const _Tp& __arg)
|
|
|
|
{ __a.construct(__p, __arg); }
|
|
|
|
|
|
|
|
static void destroy(_Alloc& __a, pointer __p)
|
|
|
|
{ __a.destroy(__p); }
|
|
|
|
|
2011-10-04 22:34:54 +02:00
|
|
|
static size_type max_size(const _Alloc& __a)
|
|
|
|
{ return __a.max_size(); }
|
|
|
|
|
2011-06-22 21:57:12 +02:00
|
|
|
static const _Alloc& _S_select_on_copy(const _Alloc& __a) { return __a; }
|
|
|
|
|
|
|
|
static void _S_on_swap(_Alloc& __a, _Alloc& __b)
|
|
|
|
{
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 431. Swapping containers with unequal allocators.
|
|
|
|
std::__alloc_swap<_Alloc>::_S_do_it(__a, __b);
|
|
|
|
}
|
2011-10-04 22:34:54 +02:00
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
struct rebind
|
|
|
|
{ typedef typename _Alloc::template rebind<_Tp>::other other; };
|
PR c++/91369 Implement P0784R7 changes to allocation and construction
This patch is the first part of library support for constexpr
std::vector and std::string. This only includes the changes to
std::allocator, std::allocator_traits, std::construct_at,
std::destroy_at, std::destroy and std::destroy_n.
std::allocator::allocate and std::allocator::deallocate need to be
added so that they can be intercepted by the compiler during constant
evaluation. Outside of constant evaluation those new member functions
just forward to the existing implementation in the base class.
PR c++/91369 Implement P0784R7 changes to allocation and construction
* include/bits/alloc_traits.h: Include <bits/stl_construct.h>.
(allocator_traits::_S_allocate, allocator_traits::_S_construct)
(allocator_traits::_S_destroy, allocator_traits::_S_max_size)
(allocator_traits::_S_select, allocator_traits::allocate)
(allocator_traits::deallocate, allocator_traits::construct)
(allocator_traits::destroy, allocator_traits::max_size)
(allocator_traits::select_on_container_copy_construction)
(allocator_traits<allocator<T>>): Add constexpr specifier for C++20.
(allocator_traits<allocator<T>>::construct): Use construct_at.
(allocator_traits<allocator<T>>::destroy): Use destroy_at.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Add constexpr
specifier.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move here
from <bits/stl_construct.h>.
* include/bits/allocator.h (allocator::~allocator): Remove for C++20.
(allocator::allocate, allocate::deallocate): Define for C++20 and up.
(operator==, operator!=): Add constexpr specifier for C++20.
* include/bits/stl_construct.h: Don't include <ext/alloc_traits.h>.
(destroy_at): For C++20 add constexpr specifier and support for
destroying arrays.
(construct_at): Define new function for C++20.
(_Construct): Return result of placement new-expression. For C++11 and
up add constexpr. For C++20 dispatch to std::construct_at during
constant evaluation.
(_Destroy(pointer)): Add constexpr specifier. For C++20 dispatch to
std::destroy_at during constant evaluation.
(_Destroy_aux::__destroy, _Destroy_n_aux::__destroy_n): Add constexpr
specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator))
(_Destroy(ForwardIterator, Size)): Likewise. Do not elide trivial
destructors during constant evaluation.
(destroy, destroy_n): Add constexpr specifier for C++20.
(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move to
<bits/alloc_traits.h>, to remove dependency on allocators.
* include/bits/stl_uninitialized.h: Include <ext/alloc_traits.h>.
Include <bits/stl_pair.h> instead of <utility>.
* include/ext/alloc_traits.h: Always include <bits/alloc_traits.h>.
(__alloc_traits::construct, __alloc_traits::destroy)
(__alloc_traits::_S_select_on_copy, __alloc_traits::_S_on_swap): Add
constexpr specifier.
* include/ext/malloc_allocator.h (operator==, operator!=): Add
constexpr specifier for C++20.
* include/ext/new_allocator.h (operator==, operator!=): Likewise.
* testsuite/20_util/headers/memory/synopsis.cc: Add constexpr.
* testsuite/20_util/scoped_allocator/69293_neg.cc: Ignore additional
errors due to constexpr function called after failed static_assert.
* testsuite/20_util/specialized_algorithms/construct_at/1.cc: New test.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Ignore additional errors due to constexpr function called after failed
static_assert.
* testsuite/23_containers/vector/cons/destructible_neg.cc: Likewise.
From-SVN: r277342
2019-10-23 19:42:11 +02:00
|
|
|
#endif // C++11
|
2011-06-22 21:57:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
2014-06-25 22:54:34 +02:00
|
|
|
} // namespace __gnu_cxx
|
2011-06-22 21:57:12 +02:00
|
|
|
|
|
|
|
#endif
|