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 // UNSUPPORTED: c++03, c++11, c++14, c++17 9 10 // <string> 11 12 // constexpr bool ends_with(basic_string_view x) const noexcept; 13 14 #include <string> 15 #include <cassert> 16 17 #include "test_macros.h" 18 19 constexpr bool test() { 20 { 21 typedef std::string S; 22 typedef std::string_view SV; 23 const char *s = "abcde"; 24 25 S s0; 26 S s1 { s + 4, 1 }; 27 S s2 { s + 3, 2 }; 28 // S s3 { s + 2, 3 }; 29 // S s4 { s + 1, 4 }; 30 // S s5 { s, 5 }; 31 S sNot { "def", 3 }; 32 33 SV sv0; 34 SV sv1 { s + 4, 1 }; 35 SV sv2 { s + 3, 2 }; 36 SV sv3 { s + 2, 3 }; 37 SV sv4 { s + 1, 4 }; 38 SV sv5 { s , 5 }; 39 SV svNot {"def", 3 }; 40 41 ASSERT_NOEXCEPT(s0.ends_with(sv0)); 42 43 assert ( s0.ends_with(sv0)); 44 assert (!s0.ends_with(sv1)); 45 46 assert ( s1.ends_with(sv0)); 47 assert ( s1.ends_with(sv1)); 48 assert (!s1.ends_with(sv2)); 49 assert (!s1.ends_with(sv3)); 50 assert (!s1.ends_with(sv4)); 51 assert (!s1.ends_with(sv5)); 52 assert (!s1.ends_with(svNot)); 53 54 assert ( s2.ends_with(sv0)); 55 assert ( s2.ends_with(sv1)); 56 assert ( s2.ends_with(sv2)); 57 assert (!s2.ends_with(sv3)); 58 assert (!s2.ends_with(sv4)); 59 assert (!s2.ends_with(sv5)); 60 assert (!s2.ends_with(svNot)); 61 62 assert ( sNot.ends_with(sv0)); 63 assert (!sNot.ends_with(sv1)); 64 assert (!sNot.ends_with(sv2)); 65 assert (!sNot.ends_with(sv3)); 66 assert (!sNot.ends_with(sv4)); 67 assert (!sNot.ends_with(sv5)); 68 assert ( sNot.ends_with(svNot)); 69 } 70 71 return true; 72 } 73 74 int main(int, char**) { 75 test(); 76 static_assert(test()); 77 78 return 0; 79 } 80