forked from OSchip/llvm-project
Implement P0272R1: Give 'std::string' a non-const '.data()' member function
llvm-svn: 262931
This commit is contained in:
parent
1a1d78b86f
commit
dd1729fe8a
|
@ -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();}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue