From f0324bcaa1ff97aabb6ba57d58d603af294d6476 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 2 Jun 2015 16:34:03 +0000 Subject: [PATCH] Implement the first part of N4258 - allocator_traits::is_always_equal. Also fixes PR#23723 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@238848 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/memory | 28 +++++++++++ include/scoped_allocator | 14 ++++++ .../is_always_equal.pass.cpp | 48 +++++++++++++++++++ www/cxx1z_status.html | 2 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp diff --git a/include/memory b/include/memory index 4e3a6f81..dc5902da 100644 --- a/include/memory +++ b/include/memory @@ -75,6 +75,8 @@ struct allocator_traits | false_type propagate_on_container_move_assignment; typedef Alloc::propagate_on_container_swap | false_type propagate_on_container_swap; + typedef Alloc::is_always_equal + | is_empty is_always_equal; template using rebind_alloc = Alloc::rebind::other | Alloc; template using rebind_traits = allocator_traits>; @@ -1144,6 +1146,29 @@ struct __propagate_on_container_swap<_Alloc, true> typedef typename _Alloc::propagate_on_container_swap type; }; +template +struct __has_is_always_equal +{ +private: + struct __two {char __lx; char __lxx;}; + template static __two __test(...); + template static char __test(typename _Up::is_always_equal* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template ::value> +struct __is_always_equal +{ + typedef typename _VSTD::is_empty<_Alloc>::type type; +}; + +template +struct __is_always_equal<_Alloc, true> +{ + typedef typename _Alloc::is_always_equal type; +}; + template ::value> struct __has_rebind_other { @@ -1423,6 +1448,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits propagate_on_container_move_assignment; typedef typename __propagate_on_container_swap::type propagate_on_container_swap; + typedef typename __is_always_equal::type + is_always_equal; #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES template using rebind_alloc = @@ -1667,6 +1694,7 @@ public: typedef _Tp value_type; typedef true_type propagate_on_container_move_assignment; + typedef true_type is_always_equal; template struct rebind {typedef allocator<_Up> other;}; diff --git a/include/scoped_allocator b/include/scoped_allocator index aa8bece6..5864689d 100644 --- a/include/scoped_allocator +++ b/include/scoped_allocator @@ -38,6 +38,7 @@ public: typedef see below propagate_on_container_copy_assignment; typedef see below propagate_on_container_move_assignment; typedef see below propagate_on_container_swap; + typedef see below is_always_equal; template struct rebind @@ -170,6 +171,14 @@ struct __get_poc_swap<_A0, _Allocs...> __get_poc_swap<_Allocs...>::value; }; +template +struct __get_poc_always_equal<_A0, _Allocs...> +{ + static const bool value = + allocator_traits<_A0>::is_always_equal::value || + __get_poc_always_equal<_Allocs...>::value; +}; + template class __scoped_allocator_storage; @@ -397,6 +406,11 @@ public: bool, __get_poc_swap::value > propagate_on_container_swap; + typedef integral_constant + < + bool, + __get_poc_always_equal::value + > is_always_equal; template struct rebind diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp new file mode 100644 index 00000000..927736cf --- /dev/null +++ b/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// struct allocator_traits +// { +// typedef Alloc::is_always_equal +// | is_empty is_always_equal; +// ... +// }; + +#include +#include + +template +struct A +{ + typedef T value_type; + typedef std::true_type is_always_equal; +}; + +template +struct B +{ + typedef T value_type; +}; + +template +struct C +{ + typedef T value_type; + int not_empty_; // some random member variable +}; + +int main() +{ + static_assert((std::is_same >::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same >::is_always_equal, std::true_type>::value), ""); + static_assert((std::is_same >::is_always_equal, std::false_type>::value), ""); +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 92268925..b94fe600 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -56,7 +56,7 @@ N4089LWGSafe conversions in unique_ptr<T[]>.Urbana N4169LWGA proposal to add invoke function templateUrbana N4190LWGRemoving auto_ptr, random_shuffle(), And Old Stuff.Urbana - N4258LWGCleaning-up noexcept in the Library.Urbana + N4258LWGCleaning-up noexcept in the Library.UrbanaIn progress3.7 N4259CWGWording for std::uncaught_exceptionsUrbanaComplete3.7 N4277LWGTriviallyCopyable reference_wrapper.UrbanaComplete3.2 N4279LWGImproved insertion interface for unique-key maps.Urbana