[libcxx] r262931 - Implement P0272R1: Give 'std::string' a non-const '.data()' member function
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 8 07:44:30 PST 2016
Author: marshall
Date: Tue Mar 8 09:44:30 2016
New Revision: 262931
URL: http://llvm.org/viewvc/llvm-project?rev=262931&view=rev
Log:
Implement P0272R1: Give 'std::string' a non-const '.data()' member function
Modified:
libcxx/trunk/include/string
libcxx/trunk/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp
libcxx/trunk/www/cxx1z_status.html
Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=262931&r1=262930&r2=262931&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Tue Mar 8 09:44:30 2016
@@ -225,6 +225,7 @@ public:
const value_type* c_str() const noexcept;
const value_type* data() const noexcept;
+ value_type* data() noexcept; // C++17
allocator_type get_allocator() const noexcept;
@@ -1659,6 +1660,10 @@ public:
const value_type* c_str() const _NOEXCEPT {return data();}
_LIBCPP_INLINE_VISIBILITY
const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
+#if _LIBCPP_STD_VER > 14
+ _LIBCPP_INLINE_VISIBILITY
+ value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
+#endif
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Modified: libcxx/trunk/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp?rev=262931&r1=262930&r2=262931&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp Tue Mar 8 09:44:30 2016
@@ -10,15 +10,17 @@
// <string>
// const charT* data() const;
+// charT* data(); // C++17
#include <string>
#include <cassert>
+#include "test_macros.h"
#include "min_allocator.h"
template <class S>
void
-test(const S& s)
+test_const(const S& s)
{
typedef typename S::traits_type T;
const typename S::value_type* str = s.data();
@@ -31,22 +33,46 @@ test(const S& s)
assert(T::eq(str[0], typename S::value_type()));
}
+template <class S>
+void
+test_nonconst(S& s)
+{
+ typedef typename S::traits_type T;
+ typename S::value_type* str = s.data();
+ if (s.size() > 0)
+ {
+ assert(T::compare(str, &s[0], s.size()) == 0);
+ assert(T::eq(str[s.size()], typename S::value_type()));
+ }
+ else
+ assert(T::eq(str[0], typename S::value_type()));
+}
+
int main()
{
{
typedef std::string S;
- test(S(""));
- test(S("abcde"));
- test(S("abcdefghij"));
- test(S("abcdefghijklmnopqrst"));
+ test_const(S(""));
+ test_const(S("abcde"));
+ test_const(S("abcdefghij"));
+ test_const(S("abcdefghijklmnopqrst"));
}
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
- test(S(""));
- test(S("abcde"));
- test(S("abcdefghij"));
- test(S("abcdefghijklmnopqrst"));
+ test_const(S(""));
+ test_const(S("abcde"));
+ test_const(S("abcdefghij"));
+ test_const(S("abcdefghijklmnopqrst"));
}
#endif
+#if TEST_STD_VER > 14
+ {
+ typedef std::string S;
+ S s1(""); test_nonconst(s1);
+ S s2("abcde"); test_nonconst(s2);
+ S s3("abcdefghij"); test_nonconst(s3);
+ S s4("abcdefghijklmnopqrst"); test_nonconst(s4);
+ }
+#endif
}
Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=262931&r1=262930&r2=262931&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Tue Mar 8 09:44:30 2016
@@ -91,7 +91,7 @@
<tr><td><a href="http://wg21.link/P0154R1">P0154R1</a></td><td>LWG</td><td>constexpr std::hardware_{constructive,destructive}_interference_size</td><td>Jacksonville</td><td></td><td></td></tr>
<tr><td><a href="http://wg21.link/P0030R1">P0030R1</a></td><td>LWG</td><td>Proposal to Introduce a 3-Argument Overload to std::hypot</td><td>Jacksonville</td><td></td><td></td></tr>
<tr><td><a href="http://wg21.link/P0031R0">P0031R0</a></td><td>LWG</td><td>A Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range Access</td><td>Jacksonville</td><td></td><td></td></tr>
- <tr><td><a href="http://wg21.link/P0272R1">P0272R1</a></td><td>LWG</td><td>Give <tt>std::string</tt> a non-const <tt>.data()</tt> member function</td><td>Jacksonville</td><td></td><td></td></tr>
+ <tr><td><a href="http://wg21.link/P0272R1">P0272R1</a></td><td>LWG</td><td>Give <tt>std::string</tt> a non-const <tt>.data()</tt> member function</td><td>Jacksonville</td><td>Complete</td><td>3.9</td></tr>
<tr><td><a href="http://wg21.link/P0077R2">P0077R2</a></td><td>LWG</td><td><tt>is_callable</tt>, the missing INVOKE related trait</td><td>Jacksonville</td><td></td><td></td></tr>
<!-- <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->
</table>
More information about the cfe-commits
mailing list