[libc++] Add test_demangle.pass.cpp clang-format to .git-blame-ignore-revs
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.iterators / cbegin.pass.cpp
blobdf2c38476197ed1a3ddc65f64ef9e451a89d6a39
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 // const_iterator cbegin() const; // constexpr since C++20
13 #include <string>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "min_allocator.h"
19 template <class S>
20 TEST_CONSTEXPR_CXX20 void test(const S& s) {
21 typename S::const_iterator cb = s.cbegin();
22 if (!s.empty()) {
23 assert(*cb == s[0]);
25 assert(cb == s.begin());
28 template <class S>
29 TEST_CONSTEXPR_CXX20 void test_string() {
30 test(S());
31 test(S("123"));
34 TEST_CONSTEXPR_CXX20 bool test() {
35 test_string<std::string>();
36 #if TEST_STD_VER >= 11
37 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
38 #endif
40 return true;
43 int main(int, char**) {
44 test();
45 #if TEST_STD_VER > 17
46 static_assert(test());
47 #endif
49 return 0;