1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // const charT* data() const; // constexpr since C++20
12 // charT* data(); // C++17, constexpr since C++20
17 #include "test_macros.h"
18 #include "min_allocator.h"
21 TEST_CONSTEXPR_CXX20
void test_const(const S
& s
) {
22 typedef typename
S::traits_type T
;
23 const typename
S::value_type
* str
= s
.data();
25 assert(T::compare(str
, &s
[0], s
.size()) == 0);
26 assert(T::eq(str
[s
.size()], typename
S::value_type()));
28 assert(T::eq(str
[0], typename
S::value_type()));
32 TEST_CONSTEXPR_CXX20
void test_nonconst(S
& s
) {
33 typedef typename
S::traits_type T
;
34 typename
S::value_type
* str
= s
.data();
36 assert(T::compare(str
, &s
[0], s
.size()) == 0);
37 assert(T::eq(str
[s
.size()], typename
S::value_type()));
39 assert(T::eq(str
[0], typename
S::value_type()));
43 TEST_CONSTEXPR_CXX20
void test_string() {
45 test_const(S("abcde"));
46 test_const(S("abcdefghij"));
47 test_const(S("abcdefghijklmnopqrst"));
56 S
s4("abcdefghijklmnopqrst");
62 TEST_CONSTEXPR_CXX20
bool test() {
63 test_string
<std::string
>();
64 #if TEST_STD_VER >= 11
65 test_string
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char> > >();
71 int main(int, char**) {
74 static_assert(test());