1e87479b0SArthur O'Dwyer //===----------------------------------------------------------------------===//
2e87479b0SArthur O'Dwyer //
3e87479b0SArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e87479b0SArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
5e87479b0SArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e87479b0SArthur O'Dwyer //
7e87479b0SArthur O'Dwyer //===----------------------------------------------------------------------===//
8e87479b0SArthur O'Dwyer
9e87479b0SArthur O'Dwyer // <string>
10e87479b0SArthur O'Dwyer
11e87479b0SArthur O'Dwyer #include <cassert>
12e87479b0SArthur O'Dwyer #include <string>
13e87479b0SArthur O'Dwyer
14dcffa7d3SNikolas Klauser #include "test_macros.h"
15dcffa7d3SNikolas Klauser
16e87479b0SArthur O'Dwyer struct Incomplete;
17a40bada9SBrendan Emery template <class T>
18a40bada9SBrendan Emery struct Holder {
19a40bada9SBrendan Emery T t;
20a40bada9SBrendan Emery };
21e87479b0SArthur O'Dwyer
22e87479b0SArthur O'Dwyer template <class T>
23e87479b0SArthur O'Dwyer struct Charlike {
24e87479b0SArthur O'Dwyer char ch_;
CharlikeCharlike2585e9b268SNikolas Klauser TEST_CONSTEXPR Charlike(char ch) : ch_(ch) {}
operator charCharlike2685e9b268SNikolas Klauser TEST_CONSTEXPR operator char() const { return ch_; }
27e87479b0SArthur O'Dwyer };
28e87479b0SArthur O'Dwyer
29*6e1dcc93SLouis Dionne template <class S>
test_string()30*6e1dcc93SLouis Dionne TEST_CONSTEXPR_CXX20 void test_string() {
31*6e1dcc93SLouis Dionne S s;
32e87479b0SArthur O'Dwyer Charlike<Holder<Incomplete> > a[] = {'m', 'a', 'h', 'i'};
33e87479b0SArthur O'Dwyer s.append(a, a + 4);
34e87479b0SArthur O'Dwyer s.assign(a, a + 4);
35e87479b0SArthur O'Dwyer s.insert(s.begin(), a, a + 4);
36e87479b0SArthur O'Dwyer s.replace(s.begin(), s.begin() + 4, a, a + 4);
37e87479b0SArthur O'Dwyer assert(s == "mahimahi");
38*6e1dcc93SLouis Dionne }
39*6e1dcc93SLouis Dionne
test()40*6e1dcc93SLouis Dionne TEST_CONSTEXPR_CXX20 bool test() {
41*6e1dcc93SLouis Dionne test_string<std::string>();
42e87479b0SArthur O'Dwyer
43dcffa7d3SNikolas Klauser return true;
44dcffa7d3SNikolas Klauser }
45dcffa7d3SNikolas Klauser
main(int,char **)46a40bada9SBrendan Emery int main(int, char**) {
47dcffa7d3SNikolas Klauser test();
48dcffa7d3SNikolas Klauser #if TEST_STD_VER > 17
49425620ccSNikolas Klauser static_assert(test());
50dcffa7d3SNikolas Klauser #endif
51dcffa7d3SNikolas Klauser
52e87479b0SArthur O'Dwyer return 0;
53e87479b0SArthur O'Dwyer }
54