Add non-const std::basic_string::data() for C++17
* include/bits/basic_string.h (data() const): Update comment. (data()): Add non-const overload for C++17. * testsuite/21_strings/basic_string/operations/data/char/2.cc: New. * testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc: New. From-SVN: r238963
This commit is contained in:
parent
3ce9aa832b
commit
92d58deefa
@ -1,5 +1,10 @@
|
||||
2016-08-01 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* include/bits/basic_string.h (data() const): Update comment.
|
||||
(data()): Add non-const overload for C++17.
|
||||
* testsuite/21_strings/basic_string/operations/data/char/2.cc: New.
|
||||
* testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc: New.
|
||||
|
||||
* include/bits/basic_string.tcc: Disable explicit instantiation
|
||||
declarations for C++17.
|
||||
|
||||
|
@ -2159,13 +2159,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
|
||||
/**
|
||||
* @brief Return const pointer to contents.
|
||||
*
|
||||
* This is a handle to internal data. Do not modify or dire things may
|
||||
* happen.
|
||||
* This is a pointer to internal data. It is undefined to modify
|
||||
* the contents through the returned pointer. To get a pointer that
|
||||
* allows modifying the contents use @c &str[0] instead,
|
||||
* (or in C++17 the non-const @c str.data() overload).
|
||||
*/
|
||||
const _CharT*
|
||||
data() const _GLIBCXX_NOEXCEPT
|
||||
{ return _M_data(); }
|
||||
|
||||
#if __cplusplus > 201402L
|
||||
/**
|
||||
* @brief Return non-const pointer to contents.
|
||||
*
|
||||
* This is a pointer to the character sequence held by the string.
|
||||
* Modifying the characters in the sequence is allowed.
|
||||
*/
|
||||
_CharT*
|
||||
data() noexcept
|
||||
{ return _M_data(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Return copy of allocator used to construct this string.
|
||||
*/
|
||||
@ -4658,13 +4672,27 @@ _GLIBCXX_END_NAMESPACE_CXX11
|
||||
/**
|
||||
* @brief Return const pointer to contents.
|
||||
*
|
||||
* This is a handle to internal data. Do not modify or dire things may
|
||||
* happen.
|
||||
* This is a pointer to internal data. It is undefined to modify
|
||||
* the contents through the returned pointer. To get a pointer that
|
||||
* allows modifying the contents use @c &str[0] instead,
|
||||
* (or in C++17 the non-const @c str.data() overload).
|
||||
*/
|
||||
const _CharT*
|
||||
data() const _GLIBCXX_NOEXCEPT
|
||||
{ return _M_data(); }
|
||||
|
||||
#if __cplusplus > 201402L
|
||||
/**
|
||||
* @brief Return non-const pointer to contents.
|
||||
*
|
||||
* This is a pointer to the character sequence held by the string.
|
||||
* Modifying the characters in the sequence is allowed.
|
||||
*/
|
||||
_CharT*
|
||||
data() noexcept
|
||||
{ return _M_data(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Return copy of allocator used to construct this string.
|
||||
*/
|
||||
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
|
||||
// C++17 21.3.1.7 [string.ops] string operations
|
||||
|
||||
#include <string>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::string s;
|
||||
char* p = s.data();
|
||||
VERIFY( *p == '\0' );
|
||||
s = "a string that is longer than a short string";
|
||||
p = s.data();
|
||||
VERIFY( p == &s.front() );
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-options "-std=gnu++17" }
|
||||
|
||||
// C++17 21.3.1.7 [string.ops] string operations
|
||||
|
||||
#include <string>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::wstring s;
|
||||
wchar_t* p = s.data();
|
||||
VERIFY( *p == L'\0' );
|
||||
s = L"a string that is longer than a short string";
|
||||
p = s.data();
|
||||
VERIFY( p == &s.front() );
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
}
|
Loading…
Reference in New Issue
Block a user