From 47761071be811e5815311294b71ad6ac9414963e Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 18 Nov 2010 01:40:00 +0000 Subject: [PATCH] LWG 1404 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@119609 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/memory | 33 ++++++++++++++----- .../difference_type.pass.cpp | 24 +++++++++++++- .../allocator.traits.types/size_type.pass.cpp | 26 ++++++++++++++- 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/include/memory b/include/memory index 2eb87c3b..130613e2 100644 --- a/include/memory +++ b/include/memory @@ -52,8 +52,11 @@ struct allocator_traits | pointer_traits::rebind const_void_pointer; typedef Alloc::difference_type - | ptrdiff_t difference_type; - typedef Alloc::size_type | size_t size_type; + | pointer_traits::difference_type + difference_type; + typedef Alloc::size_type + | make_unsigned::type + size_type; typedef Alloc::propagate_on_container_copy_assignment | false_type propagate_on_container_copy_assignment; typedef Alloc::propagate_on_container_move_assignment @@ -856,7 +859,7 @@ struct __pointer_type<_Tp, _Dp, false> typedef _Tp* type; }; -} +} // __pointer_type_imp template struct __pointer_type @@ -972,14 +975,14 @@ public: static const bool value = sizeof(__test<_Tp>(0)) == 1; }; -template ::value> +template ::value> struct __size_type { - typedef size_t type; + typedef typename make_unsigned<_DiffType>::type type; }; -template -struct __size_type<_Alloc, true> +template +struct __size_type<_Alloc, _DiffType, true> { typedef typename _Alloc::size_type type; }; @@ -1292,6 +1295,18 @@ struct __has_select_on_container_copy_construction #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +template ::value> +struct __alloc_traits_difference_type +{ + typedef typename pointer_traits<_Ptr>::difference_type type; +}; + +template +struct __alloc_traits_difference_type<_Alloc, _Ptr, true> +{ + typedef typename _Alloc::difference_type type; +}; + template struct _LIBCPP_VISIBLE allocator_traits { @@ -1303,8 +1318,8 @@ struct _LIBCPP_VISIBLE allocator_traits typedef typename __void_pointer::type void_pointer; typedef typename __const_void_pointer::type const_void_pointer; - typedef typename __pointer_traits_difference_type::type difference_type; - typedef typename __size_type::type size_type; + typedef typename __alloc_traits_difference_type::type difference_type; + typedef typename __size_type::type size_type; typedef typename __propagate_on_container_copy_assignment::type propagate_on_container_copy_assignment; diff --git a/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp b/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp index 62fd23f5..085c911b 100644 --- a/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp +++ b/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp @@ -13,7 +13,7 @@ // struct allocator_traits // { // typedef Alloc::difference_type -// | ptrdiff_t difference_type; +// | pointer_traits::difference_type difference_type; // ... // }; @@ -33,8 +33,30 @@ struct B typedef T value_type; }; +template +struct C +{ + typedef T value_type; + struct pointer {}; + struct const_pointer {}; + struct void_pointer {}; + struct const_void_pointer {}; +}; + +namespace std +{ + +template <> +struct pointer_traits::pointer> +{ + typedef signed char difference_type; +}; + +} + int main() { static_assert((std::is_same >::difference_type, short>::value), ""); static_assert((std::is_same >::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same >::difference_type, signed char>::value), ""); } diff --git a/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp b/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp index 7a6d7891..e9c175fe 100644 --- a/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp +++ b/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp @@ -32,8 +32,32 @@ struct B typedef T value_type; }; +template +struct C +{ + typedef T value_type; + struct pointer {}; + struct const_pointer {}; + struct void_pointer {}; + struct const_void_pointer {}; +}; + +namespace std +{ + +template <> +struct pointer_traits::pointer> +{ + typedef signed char difference_type; +}; + +} + int main() { static_assert((std::is_same >::size_type, unsigned short>::value), ""); - static_assert((std::is_same >::size_type, std::size_t>::value), ""); + static_assert((std::is_same >::size_type, + std::make_unsigned::type>::value), ""); + static_assert((std::is_same >::size_type, + unsigned char>::value), ""); }