xref: /llvm-project/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_char.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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, charT rhs);
14 
15 // template<class charT, class traits, class Allocator>
16 //   basic_string<charT,traits,Allocator>&&
17 //   operator+(basic_string<charT,traits,Allocator>&& lhs, charT rhs);
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>
27 void test0(const S& lhs, typename S::value_type rhs, const S& x) {
28   assert(lhs + rhs == x);
29 }
30 
31 #if TEST_STD_VER >= 11
32 template <class S>
33 void test1(S&& lhs, typename S::value_type rhs, const S& x) {
34   assert(move(lhs) + rhs == x);
35 }
36 #endif
37 
38 int main() {
39   {
40     typedef std::string S;
41     test0(S(""), '1', S("1"));
42     test0(S("abcde"), '1', S("abcde1"));
43     test0(S("abcdefghij"), '1', S("abcdefghij1"));
44     test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
45   }
46 #if TEST_STD_VER >= 11
47   {
48     typedef std::string S;
49     test1(S(""), '1', S("1"));
50     test1(S("abcde"), '1', S("abcde1"));
51     test1(S("abcdefghij"), '1', S("abcdefghij1"));
52     test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
53   }
54   {
55     typedef std::basic_string<char, std::char_traits<char>,
56                               min_allocator<char> >
57         S;
58     test0(S(""), '1', S("1"));
59     test0(S("abcde"), '1', S("abcde1"));
60     test0(S("abcdefghij"), '1', S("abcdefghij1"));
61     test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
62 
63     test1(S(""), '1', S("1"));
64     test1(S("abcde"), '1', S("abcde1"));
65     test1(S("abcdefghij"), '1', S("abcdefghij1"));
66     test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
67   }
68 #endif
69 }
70