[libc++] Add test_demangle.pass.cpp clang-format to .git-blame-ignore-revs
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.iterators / rend.pass.cpp
blobd34ee26fd9d04b776f3fc1dba9514d371cf08b6c
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 // <string>
11 // reverse_iterator rend(); // constexpr since C++20
12 // const_reverse_iterator rend() const; // constexpr since C++20
14 #include <string>
15 #include <cassert>
16 #include <cstddef>
18 #include "test_macros.h"
19 #include "min_allocator.h"
21 template <class S>
22 TEST_CONSTEXPR_CXX20 void test(S s) {
23 const S& cs = s;
24 typename S::reverse_iterator e = s.rend();
25 typename S::const_reverse_iterator ce = cs.rend();
26 if (s.empty()) {
27 assert(e == s.rbegin());
28 assert(ce == cs.rbegin());
30 assert(static_cast<std::size_t>(e - s.rbegin()) == s.size());
31 assert(static_cast<std::size_t>(ce - cs.rbegin()) == cs.size());
34 template <class S>
35 TEST_CONSTEXPR_CXX20 void test_string() {
36 test(S());
37 test(S("123"));
40 TEST_CONSTEXPR_CXX20 bool test() {
41 test_string<std::string>();
42 #if TEST_STD_VER >= 11
43 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
44 #endif
46 return true;
49 int main(int, char**) {
50 test();
51 #if TEST_STD_VER > 17
52 static_assert(test());
53 #endif
55 return 0;