Home | History | Annotate | Download | only in string_op+
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. 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 basic_string<charT,traits,Allocator>& lhs,
     15 //             const basic_string<charT,traits,Allocator>& rhs);
     16 
     17 // template<class charT, class traits, class Allocator>
     18 //   basic_string<charT,traits,Allocator>&&
     19 //   operator+(const basic_string<charT,traits,Allocator>&& lhs,
     20 //             const basic_string<charT,traits,Allocator>& rhs);
     21 
     22 // template<class charT, class traits, class Allocator>
     23 //   basic_string<charT,traits,Allocator>&&
     24 //   operator+(const basic_string<charT,traits,Allocator>& lhs,
     25 //             const basic_string<charT,traits,Allocator>&& rhs);
     26 
     27 // template<class charT, class traits, class Allocator>
     28 //   basic_string<charT,traits,Allocator>&&
     29 //   operator+(const basic_string<charT,traits,Allocator>&& lhs,
     30 //             const basic_string<charT,traits,Allocator>&& rhs);
     31 
     32 #include <string>
     33 #include <cassert>
     34 
     35 #include "min_allocator.h"
     36 
     37 template <class S>
     38 void
     39 test0(const S& lhs, const S& rhs, const S& x)
     40 {
     41     assert(lhs + rhs == x);
     42 }
     43 
     44 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     45 
     46 template <class S>
     47 void
     48 test1(S&& lhs, const S& rhs, const S& x)
     49 {
     50     assert(move(lhs) + rhs == x);
     51 }
     52 
     53 template <class S>
     54 void
     55 test2(const S& lhs, S&& rhs, const S& x)
     56 {
     57     assert(lhs + move(rhs) == x);
     58 }
     59 
     60 template <class S>
     61 void
     62 test3(S&& lhs, S&& rhs, const S& x)
     63 {
     64     assert(move(lhs) + move(rhs) == x);
     65 }
     66 
     67 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     68 
     69 int main()
     70 {
     71     {
     72     typedef std::string S;
     73     test0(S(""), S(""), S(""));
     74     test0(S(""), S("12345"), S("12345"));
     75     test0(S(""), S("1234567890"), S("1234567890"));
     76     test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
     77     test0(S("abcde"), S(""), S("abcde"));
     78     test0(S("abcde"), S("12345"), S("abcde12345"));
     79     test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
     80     test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
     81     test0(S("abcdefghij"), S(""), S("abcdefghij"));
     82     test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
     83     test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
     84     test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
     85     test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
     86     test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
     87     test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
     88     test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
     89 
     90 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     91 
     92     test1(S(""), S(""), S(""));
     93     test1(S(""), S("12345"), S("12345"));
     94     test1(S(""), S("1234567890"), S("1234567890"));
     95     test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
     96     test1(S("abcde"), S(""), S("abcde"));
     97     test1(S("abcde"), S("12345"), S("abcde12345"));
     98     test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
     99     test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    100     test1(S("abcdefghij"), S(""), S("abcdefghij"));
    101     test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    102     test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    103     test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    104     test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    105     test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    106     test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    107     test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    108 
    109     test2(S(""), S(""), S(""));
    110     test2(S(""), S("12345"), S("12345"));
    111     test2(S(""), S("1234567890"), S("1234567890"));
    112     test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
    113     test2(S("abcde"), S(""), S("abcde"));
    114     test2(S("abcde"), S("12345"), S("abcde12345"));
    115     test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
    116     test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    117     test2(S("abcdefghij"), S(""), S("abcdefghij"));
    118     test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    119     test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    120     test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    121     test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    122     test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    123     test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    124     test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    125 
    126     test3(S(""), S(""), S(""));
    127     test3(S(""), S("12345"), S("12345"));
    128     test3(S(""), S("1234567890"), S("1234567890"));
    129     test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
    130     test3(S("abcde"), S(""), S("abcde"));
    131     test3(S("abcde"), S("12345"), S("abcde12345"));
    132     test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
    133     test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    134     test3(S("abcdefghij"), S(""), S("abcdefghij"));
    135     test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    136     test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    137     test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    138     test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    139     test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    140     test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    141     test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    142 
    143 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    144     }
    145 #if __cplusplus >= 201103L
    146     {
    147     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
    148     test0(S(""), S(""), S(""));
    149     test0(S(""), S("12345"), S("12345"));
    150     test0(S(""), S("1234567890"), S("1234567890"));
    151     test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
    152     test0(S("abcde"), S(""), S("abcde"));
    153     test0(S("abcde"), S("12345"), S("abcde12345"));
    154     test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
    155     test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    156     test0(S("abcdefghij"), S(""), S("abcdefghij"));
    157     test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    158     test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    159     test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    160     test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    161     test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    162     test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    163     test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    164 
    165 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    166 
    167     test1(S(""), S(""), S(""));
    168     test1(S(""), S("12345"), S("12345"));
    169     test1(S(""), S("1234567890"), S("1234567890"));
    170     test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
    171     test1(S("abcde"), S(""), S("abcde"));
    172     test1(S("abcde"), S("12345"), S("abcde12345"));
    173     test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
    174     test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    175     test1(S("abcdefghij"), S(""), S("abcdefghij"));
    176     test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    177     test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    178     test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    179     test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    180     test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    181     test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    182     test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    183 
    184     test2(S(""), S(""), S(""));
    185     test2(S(""), S("12345"), S("12345"));
    186     test2(S(""), S("1234567890"), S("1234567890"));
    187     test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
    188     test2(S("abcde"), S(""), S("abcde"));
    189     test2(S("abcde"), S("12345"), S("abcde12345"));
    190     test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
    191     test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    192     test2(S("abcdefghij"), S(""), S("abcdefghij"));
    193     test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    194     test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    195     test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    196     test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    197     test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    198     test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    199     test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    200 
    201     test3(S(""), S(""), S(""));
    202     test3(S(""), S("12345"), S("12345"));
    203     test3(S(""), S("1234567890"), S("1234567890"));
    204     test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
    205     test3(S("abcde"), S(""), S("abcde"));
    206     test3(S("abcde"), S("12345"), S("abcde12345"));
    207     test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
    208     test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
    209     test3(S("abcdefghij"), S(""), S("abcdefghij"));
    210     test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
    211     test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
    212     test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
    213     test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
    214     test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
    215     test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
    216     test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
    217 
    218 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    219     }
    220 #endif
    221 }
    222