pointer_string.pass.cpp revision 73d21a4f0774d3fadab98e690619a359cfb160a3
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// template<class charT, class traits, class Allocator>
13//   basic_string<charT,traits,Allocator>
14//   operator+(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
15
16// template<class charT, class traits, class Allocator>
17//   basic_string<charT,traits,Allocator>&&
18//   operator+(const charT* lhs, basic_string<charT,traits,Allocator>&& rhs);
19
20#include <string>
21#include <cassert>
22
23template <class S>
24void
25test0(const typename S::value_type* lhs, const S& rhs, const S& x)
26{
27    assert(lhs + rhs == x);
28}
29
30#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
31
32template <class S>
33void
34test1(const typename S::value_type* lhs, S&& rhs, const S& x)
35{
36    assert(lhs + move(rhs) == x);
37}
38
39#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
40
41typedef std::string S;
42
43int main()
44{
45    test0("", S(""), S(""));
46    test0("", S("12345"), S("12345"));
47    test0("", S("1234567890"), S("1234567890"));
48    test0("", S("12345678901234567890"), S("12345678901234567890"));
49    test0("abcde", S(""), S("abcde"));
50    test0("abcde", S("12345"), S("abcde12345"));
51    test0("abcde", S("1234567890"), S("abcde1234567890"));
52    test0("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
53    test0("abcdefghij", S(""), S("abcdefghij"));
54    test0("abcdefghij", S("12345"), S("abcdefghij12345"));
55    test0("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
56    test0("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
57    test0("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
58    test0("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
59    test0("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
60    test0("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
61
62#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
63
64    test1("", S(""), S(""));
65    test1("", S("12345"), S("12345"));
66    test1("", S("1234567890"), S("1234567890"));
67    test1("", S("12345678901234567890"), S("12345678901234567890"));
68    test1("abcde", S(""), S("abcde"));
69    test1("abcde", S("12345"), S("abcde12345"));
70    test1("abcde", S("1234567890"), S("abcde1234567890"));
71    test1("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
72    test1("abcdefghij", S(""), S("abcdefghij"));
73    test1("abcdefghij", S("12345"), S("abcdefghij12345"));
74    test1("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
75    test1("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
76    test1("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
77    test1("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
78    test1("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
79    test1("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
80
81#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
82}
83