[libcxx] r203539 - Final bit for LWG #2263; test different allocator pointer types. Note that libc++ already does the right thing here; I've just added tests to ensure that it stays this way.

Marshall Clow mclow.lists at gmail.com
Mon Mar 10 21:32:13 PDT 2014


Author: marshall
Date: Mon Mar 10 23:32:12 2014
New Revision: 203539

URL: http://llvm.org/viewvc/llvm-project?rev=203539&view=rev
Log:
Final bit for LWG #2263; test different allocator pointer types. Note that libc++ already does the right thing here; I've just added tests to ensure that it stays this way.

Added:
    libcxx/trunk/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp
    libcxx/trunk/test/utilities/memory/default.allocator/allocator_pointers.pass.cpp
Modified:
    libcxx/trunk/www/cxx1y_status.html

Added: libcxx/trunk/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp?rev=203539&view=auto
==============================================================================
--- libcxx/trunk/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp (added)
+++ libcxx/trunk/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp Mon Mar 10 23:32:12 2014
@@ -0,0 +1,116 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+#include <scoped_allocator>
+#include <cassert>
+
+#if __cplusplus >= 201103L
+// #include <memory>
+//
+// template <class Alloc>
+// struct allocator_traits
+// {
+//     typedef Alloc                        allocator_type;
+//     typedef typename allocator_type::value_type
+//                                          value_type;
+// 
+//     typedef Alloc::pointer | value_type* pointer;
+//     typedef Alloc::const_pointer
+//           | pointer_traits<pointer>::rebind<const value_type>
+//                                          const_pointer;
+//     typedef Alloc::void_pointer
+//           | pointer_traits<pointer>::rebind<void>
+//                                          void_pointer;
+//     typedef Alloc::const_void_pointer
+//           | pointer_traits<pointer>::rebind<const void>
+//                                          const_void_pointer;
+
+template <typename Alloc>
+void test_pointer()
+{
+     typename std::allocator_traits<Alloc>::pointer        vp;
+     typename std::allocator_traits<Alloc>::const_pointer cvp;
+     
+     static_assert(std::is_same<bool, decltype( vp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
+}
+
+template <typename Alloc>
+void test_void_pointer()
+{
+     typename std::allocator_traits<Alloc>::void_pointer        vp;
+     typename std::allocator_traits<Alloc>::const_void_pointer cvp;
+     
+     static_assert(std::is_same<bool, decltype( vp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
+}
+
+struct Foo { int x; };
+
+int main()
+{
+	test_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> ();
+	test_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> ();
+	test_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> ();
+
+	test_void_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> ();
+	test_void_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> ();
+	test_void_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> ();	
+}
+#else
+int main() {}
+#endif

Added: libcxx/trunk/test/utilities/memory/default.allocator/allocator_pointers.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/default.allocator/allocator_pointers.pass.cpp?rev=203539&view=auto
==============================================================================
--- libcxx/trunk/test/utilities/memory/default.allocator/allocator_pointers.pass.cpp (added)
+++ libcxx/trunk/test/utilities/memory/default.allocator/allocator_pointers.pass.cpp Mon Mar 10 23:32:12 2014
@@ -0,0 +1,116 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <cassert>
+
+#if __cplusplus >= 201103L
+// #include <memory>
+//
+// template <class Alloc>
+// struct allocator_traits
+// {
+//     typedef Alloc                        allocator_type;
+//     typedef typename allocator_type::value_type
+//                                          value_type;
+// 
+//     typedef Alloc::pointer | value_type* pointer;
+//     typedef Alloc::const_pointer
+//           | pointer_traits<pointer>::rebind<const value_type>
+//                                          const_pointer;
+//     typedef Alloc::void_pointer
+//           | pointer_traits<pointer>::rebind<void>
+//                                          void_pointer;
+//     typedef Alloc::const_void_pointer
+//           | pointer_traits<pointer>::rebind<const void>
+//                                          const_void_pointer;
+
+template <typename Alloc>
+void test_pointer()
+{
+     typename std::allocator_traits<Alloc>::pointer        vp;
+     typename std::allocator_traits<Alloc>::const_pointer cvp;
+     
+     static_assert(std::is_same<bool, decltype( vp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
+}
+
+template <typename Alloc>
+void test_void_pointer()
+{
+     typename std::allocator_traits<Alloc>::void_pointer        vp;
+     typename std::allocator_traits<Alloc>::const_void_pointer cvp;
+     
+     static_assert(std::is_same<bool, decltype( vp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp ==  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp !=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >=  vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <   vp)>::value, "");
+     static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <=  vp)>::value, "");
+
+     static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <  cvp)>::value, "");
+     static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
+}
+
+struct Foo { int x; };
+
+int main()
+{
+	test_pointer<std::allocator<char>> ();
+	test_pointer<std::allocator<int>> ();
+	test_pointer<std::allocator<Foo>> ();	
+
+	test_void_pointer<std::allocator<char>> ();
+	test_void_pointer<std::allocator<int>> ();
+	test_void_pointer<std::allocator<Foo>> ();	
+}
+#else
+int main() {}
+#endif

Modified: libcxx/trunk/www/cxx1y_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1y_status.html?rev=203539&r1=203538&r2=203539&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1y_status.html (original)
+++ libcxx/trunk/www/cxx1y_status.html Mon Mar 10 23:32:12 2014
@@ -239,7 +239,7 @@
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2213">2213</a></td><td>Return value of std::regex_replace</td><td>Issaquah</td><td>Complete</td></tr>
 
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2258">2258</a></td><td>a.erase(q1, q2) unable to directly return q2</td><td>Issaquah</td><td>Complete</td></tr>
-	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2263">2263</a></td><td>Comparing iterators and allocator pointers with different const-character</td><td>Issaquah</td><td></td></tr>
+	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2263">2263</a></td><td>Comparing iterators and allocator pointers with different const-character</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2293">2293</a></td><td>Wrong facet used by num_put::do_put</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2301">2301</a></td><td>Why is std::tie not constexpr?</td><td>Issaquah</td><td>Complete</td></tr>
 	<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2304">2304</a></td><td>Complexity of count in unordered associative containers</td><td>Issaquah</td><td>Complete</td></tr>





More information about the cfe-commits mailing list