[libcxx] r321188 - Fix the definitions of 'reference' and 'pointer' in string_view that no one uses :-). Thanks to K-ballo for the catch.

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 20 08:31:40 PST 2017


Author: marshall
Date: Wed Dec 20 08:31:40 2017
New Revision: 321188

URL: http://llvm.org/viewvc/llvm-project?rev=321188&view=rev
Log:
Fix the definitions of 'reference' and 'pointer' in string_view that no one uses :-). Thanks to K-ballo for the catch.

Added:
    libcxx/trunk/test/std/strings/string.view/types.pass.cpp
Modified:
    libcxx/trunk/include/string_view

Modified: libcxx/trunk/include/string_view
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string_view?rev=321188&r1=321187&r2=321188&view=diff
==============================================================================
--- libcxx/trunk/include/string_view (original)
+++ libcxx/trunk/include/string_view Wed Dec 20 08:31:40 2017
@@ -196,9 +196,9 @@ public:
     // types
     typedef _Traits                                    traits_type;
     typedef _CharT                                     value_type;
-    typedef const _CharT*                              pointer;
+    typedef _CharT*                                    pointer;
     typedef const _CharT*                              const_pointer;
-    typedef const _CharT&                              reference;
+    typedef _CharT&                                    reference;
     typedef const _CharT&                              const_reference;
     typedef const_pointer                              const_iterator; // See [string.view.iterators]
     typedef const_iterator                             iterator;

Added: libcxx/trunk/test/std/strings/string.view/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/types.pass.cpp?rev=321188&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/types.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/string.view/types.pass.cpp Wed Dec 20 08:31:40 2017
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <string_view>
+
+// Test nested types and default template args:
+
+// template<class charT, class traits = char_traits<charT>>
+// {
+// public:
+//     // types:
+// 	using traits_type               = traits;
+// 	using value_type                = charT;
+// 	using pointer                   = value_type*;
+// 	using const_pointer             = const value_type*;
+// 	using reference                 = value_type&;
+// 	using const_reference           = const value_type&;
+// 	using const_iterator            = implementation-defined ; // see 24.4.2.2
+// 	using iterator                  = const_iterator;
+// 	using const_reverse_iterator    = reverse_iterator<const_iterator>;
+// 	using iterator                  = const_reverse_iterator;
+// 	using size_type                 = size_t;
+// 	using difference_type           = ptrdiff_t;
+// 	static constexpr size_type npos = size_type(-1);
+// 
+// };
+
+#include <string_view>
+#include <iterator>
+#include <type_traits>
+
+#include "test_macros.h"
+
+template <class Traits>
+void
+test()
+{
+    typedef std::basic_string_view<typename Traits::char_type, Traits> S;
+
+    static_assert((std::is_same<typename S::traits_type,     Traits>::value), "");
+    static_assert((std::is_same<typename S::value_type,      typename Traits::char_type>::value), "");
+    static_assert((std::is_same<typename S::size_type,       std::size_t>::value), "");
+    static_assert((std::is_same<typename S::difference_type, ptrdiff_t>::value), "");
+    static_assert((std::is_same<typename S::reference,             typename S::value_type&>::value), "");
+    static_assert((std::is_same<typename S::const_reference, const typename S::value_type&>::value), "");
+    static_assert((std::is_same<typename S::pointer,               typename S::value_type*>::value), "");
+    static_assert((std::is_same<typename S::const_pointer,   const typename S::value_type*>::value), "");
+    static_assert((std::is_same<
+        typename std::iterator_traits<typename S::iterator>::iterator_category,
+        std::random_access_iterator_tag>::value), "");
+    static_assert((std::is_same<
+        typename std::iterator_traits<typename S::const_iterator>::iterator_category,
+        std::random_access_iterator_tag>::value), "");
+    static_assert((std::is_same<
+        typename S::reverse_iterator,
+        std::reverse_iterator<typename S::iterator> >::value), "");
+    static_assert((std::is_same<
+        typename S::const_reverse_iterator,
+        std::reverse_iterator<typename S::const_iterator> >::value), "");
+    static_assert(S::npos == -1, "");
+    static_assert((std::is_same<typename S::iterator,         typename S::const_iterator>::value), "");
+    static_assert((std::is_same<typename S::reverse_iterator, typename S::const_reverse_iterator>::value), "");
+}
+
+int main()
+{
+    test<std::char_traits<char> >();
+    test<std::char_traits<wchar_t> >();
+    static_assert((std::is_same<std::basic_string_view<char>::traits_type,
+                                std::char_traits<char> >::value), "");
+}




More information about the cfe-commits mailing list