[libcxx] r238848 - Implement the first part of N4258 - allocator_traits<X>::is_always_equal. Also fixes PR#23723
Marshall Clow
mclow.lists at gmail.com
Tue Jun 2 09:34:04 PDT 2015
Author: marshall
Date: Tue Jun 2 11:34:03 2015
New Revision: 238848
URL: http://llvm.org/viewvc/llvm-project?rev=238848&view=rev
Log:
Implement the first part of N4258 - allocator_traits<X>::is_always_equal. Also fixes PR#23723
Added:
libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp
Modified:
libcxx/trunk/include/memory
libcxx/trunk/include/scoped_allocator
libcxx/trunk/www/cxx1z_status.html
Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=238848&r1=238847&r2=238848&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Tue Jun 2 11:34:03 2015
@@ -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 <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
@@ -1144,6 +1146,29 @@ struct __propagate_on_container_swap<_Al
typedef typename _Alloc::propagate_on_container_swap type;
};
+template <class _Tp>
+struct __has_is_always_equal
+{
+private:
+ struct __two {char __lx; char __lxx;};
+ template <class _Up> static __two __test(...);
+ template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
+public:
+ static const bool value = sizeof(__test<_Tp>(0)) == 1;
+};
+
+template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
+struct __is_always_equal
+{
+ typedef typename _VSTD::is_empty<_Alloc>::type type;
+};
+
+template <class _Alloc>
+struct __is_always_equal<_Alloc, true>
+{
+ typedef typename _Alloc::is_always_equal type;
+};
+
template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
struct __has_rebind_other
{
@@ -1423,6 +1448,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_t
propagate_on_container_move_assignment;
typedef typename __propagate_on_container_swap<allocator_type>::type
propagate_on_container_swap;
+ typedef typename __is_always_equal<allocator_type>::type
+ is_always_equal;
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class _Tp> 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 <class _Up> struct rebind {typedef allocator<_Up> other;};
Modified: libcxx/trunk/include/scoped_allocator
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/scoped_allocator?rev=238848&r1=238847&r2=238848&view=diff
==============================================================================
--- libcxx/trunk/include/scoped_allocator (original)
+++ libcxx/trunk/include/scoped_allocator Tue Jun 2 11:34:03 2015
@@ -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 <class Tp>
struct rebind
@@ -170,6 +171,14 @@ struct __get_poc_swap<_A0, _Allocs...>
__get_poc_swap<_Allocs...>::value;
};
+template <class _A0, class ..._Allocs>
+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 ..._Allocs>
class __scoped_allocator_storage;
@@ -397,6 +406,11 @@ public:
bool,
__get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
> propagate_on_container_swap;
+ typedef integral_constant
+ <
+ bool,
+ __get_poc_always_equal<outer_allocator_type, _InnerAllocs...>::value
+ > is_always_equal;
template <class _Tp>
struct rebind
Added: libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp?rev=238848&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.types/is_always_equal.pass.cpp Tue Jun 2 11:34:03 2015
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <class Alloc>
+// struct allocator_traits
+// {
+// typedef Alloc::is_always_equal
+// | is_empty is_always_equal;
+// ...
+// };
+
+#include <memory>
+#include <type_traits>
+
+template <class T>
+struct A
+{
+ typedef T value_type;
+ typedef std::true_type is_always_equal;
+};
+
+template <class T>
+struct B
+{
+ typedef T value_type;
+};
+
+template <class T>
+struct C
+{
+ typedef T value_type;
+ int not_empty_; // some random member variable
+};
+
+int main()
+{
+ static_assert((std::is_same<std::allocator_traits<A<char> >::is_always_equal, std::true_type>::value), "");
+ static_assert((std::is_same<std::allocator_traits<B<char> >::is_always_equal, std::true_type>::value), "");
+ static_assert((std::is_same<std::allocator_traits<C<char> >::is_always_equal, std::false_type>::value), "");
+}
Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=238848&r1=238847&r2=238848&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue Jun 2 11:34:03 2015
@@ -56,7 +56,7 @@
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4089">N4089</a></td><td>LWG</td></td><td>Safe conversions in <code>unique_ptr<T[]></code>.</td><td>Urbana</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4169">N4169</a></td><td>LWG</td></td><td>A proposal to add invoke function template</td><td>Urbana</td><td></td><td></td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4190">N4190</a></td></td><td>LWG</td><td>Removing auto_ptr, random_shuffle(), And Old <functional> Stuff.</td><td>Urbana</td><td></td><td></td></tr>
- <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4258">N4258</a></td><td>LWG</td></td><td>Cleaning-up noexcept in the Library.</td><td>Urbana</td><td></td><td></td></tr>
+ <tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4258">N4258</a></td><td>LWG</td></td><td>Cleaning-up noexcept in the Library.</td><td>Urbana</td><td>In progress</td><td>3.7</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4259">N4259</a></td><td>CWG</td></td><td>Wording for std::uncaught_exceptions</td><td>Urbana</td><td>Complete</td><td>3.7</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4277">N4277</a></td><td>LWG</td></td><td>TriviallyCopyable <code>reference_wrapper</code>.</td><td>Urbana</td><td>Complete</td><td>3.2</td></tr>
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4279">N4279</a></td><td>LWG</td></td><td>Improved insertion interface for unique-key maps.</td><td>Urbana</td><td></td><td></td></tr>
More information about the cfe-commits
mailing list