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 // basic_string<charT,traits,Allocator>& operator=(charT c); // constexpr since C++20 12 13 #include <string> 14 #include <cassert> 15 16 #include "test_macros.h" 17 #include "min_allocator.h" 18 19 template <class S> 20 TEST_CONSTEXPR_CXX20 void test(S s1, typename S::value_type s2) { 21 typedef typename S::traits_type T; 22 s1 = s2; 23 LIBCPP_ASSERT(s1.__invariants()); 24 assert(s1.size() == 1); 25 assert(T::eq(s1[0], s2)); 26 assert(s1.capacity() >= s1.size()); 27 } 28 29 template <class S> 30 TEST_CONSTEXPR_CXX20 void test_string() { 31 test(S(), 'a'); 32 test(S("1"), 'a'); 33 test(S("123456789"), 'a'); 34 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a'); 35 } 36 37 TEST_CONSTEXPR_CXX20 bool test() { 38 test_string<std::string>(); 39 #if TEST_STD_VER >= 11 40 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>(); 41 #endif 42 43 return true; 44 } 45 46 int main(int, char**) { 47 test(); 48 #if TEST_STD_VER > 17 49 static_assert(test()); 50 #endif 51 52 return 0; 53 } 54