From dd1729fe8a854b79e8d699da61eb749195c1fac5 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 8 Mar 2016 15:44:30 +0000 Subject: [PATCH] Implement P0272R1: Give 'std::string' a non-const '.data()' member function llvm-svn: 262931 --- libcxx/include/string | 5 +++ .../string.ops/string.accessors/data.pass.cpp | 46 +++++++++++++++++----- libcxx/www/cxx1z_status.html | 2 +- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/libcxx/include/string b/libcxx/include/string index 004dc3d..a453779 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -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();} diff --git a/libcxx/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp index 917248f..9b9523e 100644 --- a/libcxx/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string.accessors/data.pass.cpp @@ -10,15 +10,17 @@ // // const charT* data() const; +// charT* data(); // C++17 #include #include +#include "test_macros.h" #include "min_allocator.h" template 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 +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, min_allocator> 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 } diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index 80097fe..c30166e 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -91,7 +91,7 @@ P0154R1LWGconstexpr std::hardware_{constructive,destructive}_interference_sizeJacksonville P0030R1LWGProposal to Introduce a 3-Argument Overload to std::hypotJacksonville P0031R0LWGA Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range AccessJacksonville - P0272R1LWGGive std::string a non-const .data() member functionJacksonville + P0272R1LWGGive std::string a non-const .data() member functionJacksonvilleComplete3.9 P0077R2LWGis_callable, the missing INVOKE related traitJacksonville -- 2.7.4