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+(const basic_string<charT,traits,Allocator>& lhs, 14 // const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20 15 16 // template<class charT, class traits, class Allocator> 17 // basic_string<charT,traits,Allocator>&& 18 // operator+(const basic_string<charT,traits,Allocator>&& lhs, 19 // const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20 20 21 // template<class charT, class traits, class Allocator> 22 // basic_string<charT,traits,Allocator>&& 23 // operator+(const basic_string<charT,traits,Allocator>& lhs, 24 // const basic_string<charT,traits,Allocator>&& rhs); // constexpr since C++20 25 26 // template<class charT, class traits, class Allocator> 27 // basic_string<charT,traits,Allocator>&& 28 // operator+(const basic_string<charT,traits,Allocator>&& lhs, 29 // const basic_string<charT,traits,Allocator>&& rhs); // constexpr since C++20 30 31 #include <string> 32 #include <utility> 33 #include <cassert> 34 35 #include "test_macros.h" 36 #include "min_allocator.h" 37 38 template <class S> 39 TEST_CONSTEXPR_CXX20 void test0(const S& lhs, const S& rhs, const S& x) { 40 assert(lhs + rhs == x); 41 } 42 43 #if TEST_STD_VER >= 11 44 template <class S> 45 TEST_CONSTEXPR_CXX20 void test1(S&& lhs, const S& rhs, const S& x) { 46 assert(std::move(lhs) + rhs == x); 47 } 48 49 template <class S> 50 TEST_CONSTEXPR_CXX20 void test2(const S& lhs, S&& rhs, const S& x) { 51 assert(lhs + std::move(rhs) == x); 52 } 53 54 template <class S> 55 TEST_CONSTEXPR_CXX20 void test3(S&& lhs, S&& rhs, const S& x) { 56 assert(std::move(lhs) + std::move(rhs) == x); 57 } 58 #endif 59 60 template <class S> 61 TEST_CONSTEXPR_CXX20 void test_string() { 62 test0(S(""), S(""), S("")); 63 test0(S(""), S("12345"), S("12345")); 64 test0(S(""), S("1234567890"), S("1234567890")); 65 test0(S(""), S("12345678901234567890"), S("12345678901234567890")); 66 test0(S("abcde"), S(""), S("abcde")); 67 test0(S("abcde"), S("12345"), S("abcde12345")); 68 test0(S("abcde"), S("1234567890"), S("abcde1234567890")); 69 test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); 70 test0(S("abcdefghij"), S(""), S("abcdefghij")); 71 test0(S("abcdefghij"), S("12345"), S("abcdefghij12345")); 72 test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); 73 test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); 74 test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); 75 test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); 76 test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); 77 test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); 78 #if TEST_STD_VER >= 11 79 test1(S(""), S(""), S("")); 80 test1(S(""), S("12345"), S("12345")); 81 test1(S(""), S("1234567890"), S("1234567890")); 82 test1(S(""), S("12345678901234567890"), S("12345678901234567890")); 83 test1(S("abcde"), S(""), S("abcde")); 84 test1(S("abcde"), S("12345"), S("abcde12345")); 85 test1(S("abcde"), S("1234567890"), S("abcde1234567890")); 86 test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); 87 test1(S("abcdefghij"), S(""), S("abcdefghij")); 88 test1(S("abcdefghij"), S("12345"), S("abcdefghij12345")); 89 test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); 90 test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); 91 test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); 92 test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); 93 test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); 94 test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); 95 96 test2(S(""), S(""), S("")); 97 test2(S(""), S("12345"), S("12345")); 98 test2(S(""), S("1234567890"), S("1234567890")); 99 test2(S(""), S("12345678901234567890"), S("12345678901234567890")); 100 test2(S("abcde"), S(""), S("abcde")); 101 test2(S("abcde"), S("12345"), S("abcde12345")); 102 test2(S("abcde"), S("1234567890"), S("abcde1234567890")); 103 test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); 104 test2(S("abcdefghij"), S(""), S("abcdefghij")); 105 test2(S("abcdefghij"), S("12345"), S("abcdefghij12345")); 106 test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); 107 test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); 108 test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); 109 test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); 110 test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); 111 test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); 112 113 test3(S(""), S(""), S("")); 114 test3(S(""), S("12345"), S("12345")); 115 test3(S(""), S("1234567890"), S("1234567890")); 116 test3(S(""), S("12345678901234567890"), S("12345678901234567890")); 117 test3(S("abcde"), S(""), S("abcde")); 118 test3(S("abcde"), S("12345"), S("abcde12345")); 119 test3(S("abcde"), S("1234567890"), S("abcde1234567890")); 120 test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890")); 121 test3(S("abcdefghij"), S(""), S("abcdefghij")); 122 test3(S("abcdefghij"), S("12345"), S("abcdefghij12345")); 123 test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890")); 124 test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890")); 125 test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst")); 126 test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345")); 127 test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890")); 128 test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); 129 #endif 130 } 131 132 TEST_CONSTEXPR_CXX20 bool test() { 133 test_string<std::string>(); 134 #if TEST_STD_VER >= 11 135 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); 136 #endif 137 138 return true; 139 } 140 141 int main(int, char**) { 142 test(); 143 #if TEST_STD_VER > 17 144 static_assert(test()); 145 #endif 146 147 return 0; 148 } 149