|
16 | 16 | // basic_string<charT,traits,Allocator>&&
|
17 | 17 | // operator+(const charT* lhs, basic_string<charT,traits,Allocator>&& rhs); // constexpr since C++20
|
18 | 18 |
|
| 19 | +#include <cassert> |
19 | 20 | #include <string>
|
20 | 21 | #include <utility>
|
21 |
| -#include <cassert> |
22 | 22 |
|
23 | 23 | #include "test_macros.h"
|
24 | 24 | #include "min_allocator.h"
|
25 | 25 |
|
26 |
| -template <class S> |
27 |
| -TEST_CONSTEXPR_CXX20 void test0(const 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> |
33 |
| -TEST_CONSTEXPR_CXX20 void test1(const typename S::value_type* lhs, S&& rhs, const S& x) { |
34 |
| - assert(lhs + std::move(rhs) == x); |
35 |
| -} |
36 |
| -#endif |
37 |
| - |
38 | 26 | template <class S>
|
39 | 27 | TEST_CONSTEXPR_CXX20 void test_string() {
|
40 |
| - test0("", S(""), S("")); |
41 |
| - test0("", S("12345"), S("12345")); |
42 |
| - test0("", S("1234567890"), S("1234567890")); |
43 |
| - test0("", S("12345678901234567890"), S("12345678901234567890")); |
44 |
| - test0("abcde", S(""), S("abcde")); |
45 |
| - test0("abcde", S("12345"), S("abcde12345")); |
46 |
| - test0("abcde", S("1234567890"), S("abcde1234567890")); |
47 |
| - test0("abcde", S("12345678901234567890"), S("abcde12345678901234567890")); |
48 |
| - test0("abcdefghij", S(""), S("abcdefghij")); |
49 |
| - test0("abcdefghij", S("12345"), S("abcdefghij12345")); |
50 |
| - test0("abcdefghij", S("1234567890"), S("abcdefghij1234567890")); |
51 |
| - test0("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890")); |
52 |
| - test0("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst")); |
53 |
| - test0("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345")); |
54 |
| - test0("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890")); |
55 |
| - test0("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); |
| 28 | + const char* test_data[2][4] = { |
| 29 | + {"", "abcde", "abcdefghij", "abcdefghijklmnopqrst"}, {"", "12345", "1234567890", "12345678901234567890"}}; |
| 30 | + |
| 31 | + const char* results[4][4] = { |
| 32 | + {"", "12345", "1234567890", "12345678901234567890"}, |
| 33 | + {"abcde", "abcde12345", "abcde1234567890", "abcde12345678901234567890"}, |
| 34 | + {"abcdefghij", "abcdefghij12345", "abcdefghij1234567890", "abcdefghij12345678901234567890"}, |
| 35 | + {"abcdefghijklmnopqrst", |
| 36 | + "abcdefghijklmnopqrst12345", |
| 37 | + "abcdefghijklmnopqrst1234567890", |
| 38 | + "abcdefghijklmnopqrst12345678901234567890"}}; |
56 | 39 |
|
| 40 | + for (size_t i = 0; i != 4; ++i) { |
| 41 | + for (size_t k = 0; k != 4; ++k) { |
| 42 | + { // operator+(const value_type*, const string&); |
| 43 | + const char* lhs = test_data[0][i]; |
| 44 | + const S rhs(test_data[1][k]); |
| 45 | + assert(lhs + rhs == results[i][k]); |
| 46 | + } |
57 | 47 | #if TEST_STD_VER >= 11
|
58 |
| - test1("", S(""), S("")); |
59 |
| - test1("", S("12345"), S("12345")); |
60 |
| - test1("", S("1234567890"), S("1234567890")); |
61 |
| - test1("", S("12345678901234567890"), S("12345678901234567890")); |
62 |
| - test1("abcde", S(""), S("abcde")); |
63 |
| - test1("abcde", S("12345"), S("abcde12345")); |
64 |
| - test1("abcde", S("1234567890"), S("abcde1234567890")); |
65 |
| - test1("abcde", S("12345678901234567890"), S("abcde12345678901234567890")); |
66 |
| - test1("abcdefghij", S(""), S("abcdefghij")); |
67 |
| - test1("abcdefghij", S("12345"), S("abcdefghij12345")); |
68 |
| - test1("abcdefghij", S("1234567890"), S("abcdefghij1234567890")); |
69 |
| - test1("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890")); |
70 |
| - test1("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst")); |
71 |
| - test1("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345")); |
72 |
| - test1("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890")); |
73 |
| - test1("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890")); |
| 48 | + { // operator+(const value_type*, string&&); |
| 49 | + const char* lhs = test_data[0][i]; |
| 50 | + S rhs(test_data[1][k]); |
| 51 | + assert(lhs + std::move(rhs) == results[i][k]); |
| 52 | + } |
74 | 53 | #endif
|
| 54 | + } |
| 55 | + } |
75 | 56 | }
|
76 | 57 |
|
77 | 58 | TEST_CONSTEXPR_CXX20 bool test() {
|
78 | 59 | test_string<std::string>();
|
79 | 60 | #if TEST_STD_VER >= 11
|
80 |
| - test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); |
| 61 | + test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>(); |
81 | 62 | #endif
|
82 | 63 |
|
83 | 64 | return true;
|
84 | 65 | }
|
85 | 66 |
|
86 | 67 | int main(int, char**) {
|
87 | 68 | test();
|
88 |
| -#if TEST_STD_VER > 17 |
| 69 | +#if TEST_STD_VER >= 20 |
89 | 70 | static_assert(test());
|
90 | 71 | #endif
|
91 | 72 |
|
|
0 commit comments