1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <string>
10 
11 // template<class charT, class traits, class Allocator>
12 //   basic_string<charT,traits,Allocator>
13 //   operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
14 
15 // template<class charT, class traits, class Allocator>
16 //   basic_string<charT,traits,Allocator>&&
17 //   operator+(charT lhs, basic_string<charT,traits,Allocator>&& rhs); // constexpr since C++20
18 
19 #include <string>
20 #include <utility>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 #include "min_allocator.h"
25 
26 template <class S>
test0(typename S::value_type lhs,const S & rhs,const S & x)27 TEST_CONSTEXPR_CXX20 void test0(typename S::value_type lhs, const S& rhs, const S& x) {
28   assert(lhs + rhs == x);
29 }
30 
31 #if TEST_STD_VER >= 11
32 template <class S>
test1(typename S::value_type lhs,S && rhs,const S & x)33 TEST_CONSTEXPR_CXX20 void test1(typename S::value_type lhs, S&& rhs, const S& x) {
34   assert(lhs + std::move(rhs) == x);
35 }
36 #endif
37 
test()38 TEST_CONSTEXPR_CXX20 bool test() {
39   {
40     typedef std::string S;
41     test0('a', S(""), S("a"));
42     test0('a', S("12345"), S("a12345"));
43     test0('a', S("1234567890"), S("a1234567890"));
44     test0('a', S("12345678901234567890"), S("a12345678901234567890"));
45   }
46 #if TEST_STD_VER >= 11
47   {
48     typedef std::string S;
49     test1('a', S(""), S("a"));
50     test1('a', S("12345"), S("a12345"));
51     test1('a', S("1234567890"), S("a1234567890"));
52     test1('a', S("12345678901234567890"), S("a12345678901234567890"));
53   }
54   {
55     typedef std::basic_string<char, std::char_traits<char>,
56                               min_allocator<char> >
57         S;
58     test0('a', S(""), S("a"));
59     test0('a', S("12345"), S("a12345"));
60     test0('a', S("1234567890"), S("a1234567890"));
61     test0('a', S("12345678901234567890"), S("a12345678901234567890"));
62 
63     test1('a', S(""), S("a"));
64     test1('a', S("12345"), S("a12345"));
65     test1('a', S("1234567890"), S("a1234567890"));
66     test1('a', S("12345678901234567890"), S("a12345678901234567890"));
67   }
68 #endif
69 
70   return true;
71 }
72 
main(int,char **)73 int main(int, char**) {
74   test();
75 #if TEST_STD_VER > 17
76   static_assert(test());
77 #endif
78 
79   return 0;
80 }
81