diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-01-29 14:57:35 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-01-29 14:57:35 +0000 |
commit | 7deb91c75a1c9de5bf46a5c959e5e709173ee639 (patch) | |
tree | 9e1fd6bd9e76ef396f73230c2bc16361ea341289 /libstdc++-v3/include | |
parent | b904104cb8c81fcd196aa64cde69663157de4be0 (diff) | |
download | ppe42-gcc-7deb91c75a1c9de5bf46a5c959e5e709173ee639.tar.gz ppe42-gcc-7deb91c75a1c9de5bf46a5c959e5e709173ee639.zip |
* include/bits/alloc_traits.h (allocator_traits::_S_allocate): Do
not use varargs when argument could be non-POD.
(__alloctr_rebind_helper): Eliminate static const bool member by
using true_type and false_type.
(allocator_traits::__allocate_helper): Likewise.
(allocator_traits::__construct_helper): Likewise.
(allocator_traits::__destroy_helper): Likewise.
(allocator_traits::__maxsize_helper): Likewise.
(allocator_traits::__select_helper): Likewise.
* include/bits/ptr_traits.h (__ptrtr_rebind_helper): Likewise.
* include/bits/stl_tree.h (_Rb_tree::operator=(const _Rb_tree&)):
Remove redundant condition.
* include/bits/stl_vector.h (vector::operator=(const vector&)):
Likewise.
(_Vector_impl::_M_allocate, _Vector_impl::_M_deallocate): Use
indirection through __alloc_traits.
* include/ext/alloc_traits.h (__allocator_always_compares_equal):
Eliminate static const bool members by using true_type and false_type.
(__gnu_cxx::__alloc_traits::__is_custom_pointer): Optimize.
* testsuite/util/testsuite_allocator.h (PointerBase): Define.
* testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
New.
* testsuite/20_util/allocator_traits/requirements/typedefs2.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207240 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/alloc_traits.h | 157 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ptr_traits.h | 17 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_tree.h | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 12 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/alloc_traits.h | 51 |
5 files changed, 98 insertions, 144 deletions
diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index 86ed222ccec..23fe8de0947 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -44,24 +44,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class __alloctr_rebind_helper { template<typename _Alloc2, typename _Tp2> - static constexpr bool - _S_chk(typename _Alloc2::template rebind<_Tp2>::other*) - { return true; } + static constexpr true_type + _S_chk(typename _Alloc2::template rebind<_Tp2>::other*); template<typename, typename> - static constexpr bool - _S_chk(...) - { return false; } + static constexpr false_type + _S_chk(...); public: - static const bool __value = _S_chk<_Alloc, _Tp>(nullptr); + using __type = decltype(_S_chk<_Alloc, _Tp>(nullptr)); }; - template<typename _Alloc, typename _Tp> - const bool __alloctr_rebind_helper<_Alloc, _Tp>::__value; - template<typename _Alloc, typename _Tp, - bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value> + bool = __alloctr_rebind_helper<_Alloc, _Tp>::__type::value> struct __alloctr_rebind; template<typename _Alloc, typename _Tp> @@ -71,7 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template<template<typename, typename...> class _Alloc, typename _Tp, - typename _Up, typename... _Args> + typename _Up, typename... _Args> struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false> { typedef _Alloc<_Tp, _Args...> __type; @@ -140,7 +135,7 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(const_void_pointer, typedef __const_void_pointer const_void_pointer; _GLIBCXX_ALLOC_TR_NESTED_TYPE(difference_type, - typename pointer_traits<pointer>::difference_type) + typename pointer_traits<pointer>::difference_type) /** * @brief The allocator's difference type @@ -151,7 +146,7 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(difference_type, typedef __difference_type difference_type; _GLIBCXX_ALLOC_TR_NESTED_TYPE(size_type, - typename make_unsigned<difference_type>::type) + typename make_unsigned<difference_type>::type) /** * @brief The allocator's size type @@ -162,7 +157,7 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(size_type, typedef __size_type size_type; _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_copy_assignment, - false_type) + false_type) /** * @brief How the allocator is propagated on copy assignment @@ -171,10 +166,10 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_copy_assignment, * otherwise @c false_type */ typedef __propagate_on_container_copy_assignment - propagate_on_container_copy_assignment; + propagate_on_container_copy_assignment; _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_move_assignment, - false_type) + false_type) /** * @brief How the allocator is propagated on move assignment @@ -183,10 +178,10 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_move_assignment, * otherwise @c false_type */ typedef __propagate_on_container_move_assignment - propagate_on_container_move_assignment; + propagate_on_container_move_assignment; _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, - false_type) + false_type) /** * @brief How the allocator is propagated on swap @@ -199,9 +194,9 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, #undef _GLIBCXX_ALLOC_TR_NESTED_TYPE template<typename _Tp> - using rebind_alloc = typename __alloctr_rebind<_Alloc, _Tp>::__type; + using rebind_alloc = typename __alloctr_rebind<_Alloc, _Tp>::__type; template<typename _Tp> - using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; + using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; private: template<typename _Alloc2> @@ -216,20 +211,22 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, template<typename> static false_type __test(...); - typedef decltype(__test<_Alloc>(0)) type; - static const bool value = type::value; + using type = decltype(__test<_Alloc>(0)); }; template<typename _Alloc2> - static typename - enable_if<__allocate_helper<_Alloc2>::value, pointer>::type - _S_allocate(_Alloc2& __a, size_type __n, const_void_pointer __hint) + using __has_allocate = typename __allocate_helper<_Alloc2>::type; + + template<typename _Alloc2, + typename = _Require<__has_allocate<_Alloc2>>> + static pointer + _S_allocate(_Alloc2& __a, size_type __n, const_void_pointer __hint) { return __a.allocate(__n, __hint); } - template<typename _Alloc2> - static typename - enable_if<!__allocate_helper<_Alloc2>::value, pointer>::type - _S_allocate(_Alloc2& __a, size_type __n, ...) + template<typename _Alloc2, typename _UnusedHint, + typename = _Require<__not_<__has_allocate<_Alloc2>>>> + static pointer + _S_allocate(_Alloc2& __a, size_type __n, _UnusedHint) { return __a.allocate(__n); } template<typename _Tp, typename... _Args> @@ -243,21 +240,23 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, template<typename> static false_type __test(...); - typedef decltype(__test<_Alloc>(0)) type; - static const bool value = type::value; + using type = decltype(__test<_Alloc>(0)); }; template<typename _Tp, typename... _Args> - static typename - enable_if<__construct_helper<_Tp, _Args...>::value, void>::type - _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args) + using __has_construct + = typename __construct_helper<_Tp, _Args...>::type; + + template<typename _Tp, typename... _Args> + static _Require<__has_construct<_Tp, _Args...>> + _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args) { __a.construct(__p, std::forward<_Args>(__args)...); } template<typename _Tp, typename... _Args> - static typename - enable_if<__and_<__not_<__construct_helper<_Tp, _Args...>>, - is_constructible<_Tp, _Args...>>::value, void>::type - _S_construct(_Alloc&, _Tp* __p, _Args&&... __args) + static + _Require<__and_<__not_<__has_construct<_Tp, _Args...>>, + is_constructible<_Tp, _Args...>>> + _S_construct(_Alloc&, _Tp* __p, _Args&&... __args) { ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); } template<typename _Tp> @@ -271,18 +270,20 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, template<typename> static false_type __test(...); - typedef decltype(__test<_Alloc>(0)) type; - static const bool value = type::value; + using type = decltype(__test<_Alloc>(0)); }; template<typename _Tp> - static typename enable_if<__destroy_helper<_Tp>::value, void>::type - _S_destroy(_Alloc& __a, _Tp* __p) + using __has_destroy = typename __destroy_helper<_Tp>::type; + + template<typename _Tp> + static _Require<__has_destroy<_Tp>> + _S_destroy(_Alloc& __a, _Tp* __p) { __a.destroy(__p); } template<typename _Tp> - static typename enable_if<!__destroy_helper<_Tp>::value, void>::type - _S_destroy(_Alloc&, _Tp* __p) + static _Require<__not_<__has_destroy<_Tp>>> + _S_destroy(_Alloc&, _Tp* __p) { __p->~_Tp(); } template<typename _Alloc2> @@ -295,20 +296,22 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, template<typename> static false_type __test(...); - typedef decltype(__test<_Alloc2>(0)) type; - static const bool value = type::value; + using type = decltype(__test<_Alloc2>(0)); }; template<typename _Alloc2> - static typename - enable_if<__maxsize_helper<_Alloc2>::value, size_type>::type - _S_max_size(_Alloc2& __a) + using __has_max_size = typename __maxsize_helper<_Alloc2>::type; + + template<typename _Alloc2, + typename = _Require<__has_max_size<_Alloc2>>> + static size_type + _S_max_size(_Alloc2& __a, int) { return __a.max_size(); } - template<typename _Alloc2> - static typename - enable_if<!__maxsize_helper<_Alloc2>::value, size_type>::type - _S_max_size(_Alloc2&) + template<typename _Alloc2, + typename = _Require<__not_<__has_max_size<_Alloc2>>>> + static size_type + _S_max_size(_Alloc2&, ...) { return __gnu_cxx::__numeric_traits<size_type>::__max; } template<typename _Alloc2> @@ -322,19 +325,22 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, template<typename> static false_type __test(...); - typedef decltype(__test<_Alloc2>(0)) type; - static const bool value = type::value; + using type = decltype(__test<_Alloc2>(0)); }; + template<typename _Alloc2> - static typename - enable_if<__select_helper<_Alloc2>::value, _Alloc2>::type - _S_select(_Alloc2& __a) + using __has_soccc = typename __select_helper<_Alloc2>::type; + + template<typename _Alloc2, + typename = _Require<__has_soccc<_Alloc2>>> + static _Alloc2 + _S_select(_Alloc2& __a, int) { return __a.select_on_container_copy_construction(); } - template<typename _Alloc2> - static typename - enable_if<!__select_helper<_Alloc2>::value, _Alloc2>::type - _S_select(_Alloc2& __a) + template<typename _Alloc2, + typename = _Require<__not_<__has_soccc<_Alloc2>>>> + static _Alloc2 + _S_select(_Alloc2& __a, ...) { return __a; } public: @@ -413,7 +419,7 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, * otherwise returns @c numeric_limits<size_type>::max() */ static size_type max_size(const _Alloc& __a) noexcept - { return _S_max_size(__a); } + { return _S_max_size(__a, 0); } /** * @brief Obtain an allocator to use when copying a container. @@ -425,31 +431,10 @@ _GLIBCXX_ALLOC_TR_NESTED_TYPE(propagate_on_container_swap, */ static _Alloc select_on_container_copy_construction(const _Alloc& __rhs) - { return _S_select(__rhs); } + { return _S_select(__rhs, 0); } }; template<typename _Alloc> - template<typename _Alloc2> - const bool allocator_traits<_Alloc>::__allocate_helper<_Alloc2>::value; - - template<typename _Alloc> - template<typename _Tp, typename... _Args> - const bool - allocator_traits<_Alloc>::__construct_helper<_Tp, _Args...>::value; - - template<typename _Alloc> - template<typename _Tp> - const bool allocator_traits<_Alloc>::__destroy_helper<_Tp>::value; - - template<typename _Alloc> - template<typename _Alloc2> - const bool allocator_traits<_Alloc>::__maxsize_helper<_Alloc2>::value; - - template<typename _Alloc> - template<typename _Alloc2> - const bool allocator_traits<_Alloc>::__select_helper<_Alloc2>::value; - - template<typename _Alloc> inline void __do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type) { __one = __two; } diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h index 714db790320..94995c8fb2e 100644 --- a/libstdc++-v3/include/bits/ptr_traits.h +++ b/libstdc++-v3/include/bits/ptr_traits.h @@ -73,24 +73,19 @@ _GLIBCXX_HAS_NESTED_TYPE(difference_type) class __ptrtr_rebind_helper { template<typename _Ptr2, typename _Up2> - static constexpr bool - _S_chk(typename _Ptr2::template rebind<_Up2>*) - { return true; } + static constexpr true_type + _S_chk(typename _Ptr2::template rebind<_Up2>*); template<typename, typename> - static constexpr bool - _S_chk(...) - { return false; } + static constexpr false_type + _S_chk(...); public: - static const bool __value = _S_chk<_Ptr, _Up>(nullptr); + using __type = decltype(_S_chk<_Ptr, _Up>(nullptr)); }; - template<typename _Ptr, typename _Up> - const bool __ptrtr_rebind_helper<_Ptr, _Up>::__value; - template<typename _Tp, typename _Up, - bool = __ptrtr_rebind_helper<_Tp, _Up>::__value> + bool = __ptrtr_rebind_helper<_Tp, _Up>::__type::value> struct __ptrtr_rebind; template<typename _Tp, typename _Up> diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index d24b1f750bc..4bc3c602c20 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -1080,9 +1080,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION clear(); if (__x._M_root() != 0) _M_move_data(__x, std::true_type()); - if (_Alloc_traits::_S_propagate_on_move_assign()) - std::__alloc_on_move(_M_get_Node_allocator(), - __x._M_get_Node_allocator()); + std::__alloc_on_move(_M_get_Node_allocator(), + __x._M_get_Node_allocator()); return true; } return false; diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index f4829575e73..98ac708e8f1 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -165,13 +165,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER pointer _M_allocate(size_t __n) - { return __n != 0 ? _M_impl.allocate(__n) : 0; } + { + typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; + return __n != 0 ? _Tr::allocate(_M_impl, __n) : 0; + } void _M_deallocate(pointer __p, size_t __n) { + typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; if (__p) - _M_impl.deallocate(__p, __n); + _Tr::deallocate(_M_impl, __p, __n); } private: @@ -1446,9 +1450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER vector __tmp(get_allocator()); this->_M_impl._M_swap_data(__tmp._M_impl); this->_M_impl._M_swap_data(__x._M_impl); - if (_Alloc_traits::_S_propagate_on_move_assign()) - std::__alloc_on_move(_M_get_Tp_allocator(), - __x._M_get_Tp_allocator()); + std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator()); } // Do move assignment when it might not be possible to move source diff --git a/libstdc++-v3/include/ext/alloc_traits.h b/libstdc++-v3/include/ext/alloc_traits.h index 26e457ff253..14fbc4359ec 100644 --- a/libstdc++-v3/include/ext/alloc_traits.h +++ b/libstdc++-v3/include/ext/alloc_traits.h @@ -44,73 +44,47 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L template<typename _Alloc> - struct __allocator_always_compares_equal - { static const bool value = false; }; - - template<typename _Alloc> - const bool __allocator_always_compares_equal<_Alloc>::value; + struct __allocator_always_compares_equal : std::false_type { }; template<typename _Tp> struct __allocator_always_compares_equal<std::allocator<_Tp>> - { static const bool value = true; }; - - template<typename _Tp> - const bool __allocator_always_compares_equal<std::allocator<_Tp>>::value; + : std::true_type { }; template<typename, typename> struct array_allocator; template<typename _Tp, typename _Array> struct __allocator_always_compares_equal<array_allocator<_Tp, _Array>> - { static const bool value = true; }; - - template<typename _Tp, typename _Array> - const bool - __allocator_always_compares_equal<array_allocator<_Tp, _Array>>::value; + : std::true_type { }; template<typename> struct bitmap_allocator; template<typename _Tp> struct __allocator_always_compares_equal<bitmap_allocator<_Tp>> - { static const bool value = true; }; - - template<typename _Tp> - const bool __allocator_always_compares_equal<bitmap_allocator<_Tp>>::value; + : std::true_type { }; template<typename> struct malloc_allocator; template<typename _Tp> struct __allocator_always_compares_equal<malloc_allocator<_Tp>> - { static const bool value = true; }; - - template<typename _Tp> - const bool __allocator_always_compares_equal<malloc_allocator<_Tp>>::value; + : std::true_type { }; template<typename> struct mt_allocator; template<typename _Tp> struct __allocator_always_compares_equal<mt_allocator<_Tp>> - { static const bool value = true; }; - - template<typename _Tp> - const bool __allocator_always_compares_equal<mt_allocator<_Tp>>::value; + : std::true_type { }; template<typename> struct new_allocator; template<typename _Tp> struct __allocator_always_compares_equal<new_allocator<_Tp>> - { static const bool value = true; }; - - template<typename _Tp> - const bool __allocator_always_compares_equal<new_allocator<_Tp>>::value; + : std::true_type { }; template<typename> struct pool_allocator; template<typename _Tp> struct __allocator_always_compares_equal<pool_allocator<_Tp>> - { static const bool value = true; }; - - template<typename _Tp> - const bool __allocator_always_compares_equal<pool_allocator<_Tp>>::value; + : std::true_type { }; #endif /** @@ -131,7 +105,7 @@ template<typename _Alloc> typedef typename _Base_type::const_pointer const_pointer; typedef typename _Base_type::size_type size_type; typedef typename _Base_type::difference_type difference_type; - // C++0x allocators do not define reference or const_reference + // C++11 allocators do not define reference or const_reference typedef value_type& reference; typedef const value_type& const_reference; using _Base_type::allocate; @@ -142,10 +116,9 @@ template<typename _Alloc> private: template<typename _Ptr> - struct __is_custom_pointer - : std::integral_constant<bool, std::is_same<pointer, _Ptr>::value - && !std::is_pointer<_Ptr>::value> - { }; + using __is_custom_pointer + = std::__and_<std::is_same<pointer, _Ptr>, + std::__not_<std::is_pointer<_Ptr>>>; public: // overload construct for non-standard pointer types |