[mlir][acc] Introduce MappableType interface (#122146)
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.cons / move.pass.cpp
blob5d2d774b3606383e1cb587b65fe4ac3c2d10bf21
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <string>
13 // basic_string(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
15 #include <string>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 #include "asan_testing.h"
23 template <class S>
24 TEST_CONSTEXPR_CXX20 void test(S s0) {
25 S s1 = s0;
26 S s2 = std::move(s0);
27 LIBCPP_ASSERT(s2.__invariants());
28 LIBCPP_ASSERT(s0.__invariants());
29 assert(s2 == s1);
30 assert(s2.capacity() >= s2.size());
31 assert(s2.get_allocator() == s1.get_allocator());
32 LIBCPP_ASSERT(is_string_asan_correct(s0));
33 LIBCPP_ASSERT(is_string_asan_correct(s1));
34 LIBCPP_ASSERT(is_string_asan_correct(s2));
37 template <class Alloc>
38 TEST_CONSTEXPR_CXX20 void test_string(Alloc const& a) {
39 using S = std::basic_string<char, std::char_traits<char>, Alloc>;
40 test(S(Alloc(a)));
41 test(S("1", Alloc(a)));
42 test(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc(a)));
45 TEST_CONSTEXPR_CXX20 bool test() {
46 test_string(std::allocator<char>());
47 test_string(test_allocator<char>());
48 test_string(test_allocator<char>(3));
49 test_string(min_allocator<char>());
51 return true;
54 int main(int, char**) {
55 test();
56 #if TEST_STD_VER > 17
57 static_assert(test());
58 #endif
60 return 0;