Debian Codegraph @

libcxx/test/std/strings/char.traits/char.traits.specializations/char.traits.specializations.char8_t/length.pass.cpp

raw
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 // template<> struct char_traits<char8_t>
13
14 // static constexpr size_t length(const char_type* s);
15
16 #include <string>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 #ifndef TEST_HAS_NO_CHAR8_T
22 constexpr bool test_constexpr() {
23 return std::char_traits<char8_t>::length(u8"") == 0 && std::char_traits<char8_t>::length(u8"abcd") == 4;
24 }
25
26 int main(int, char**) {
27 assert(std::char_traits<char8_t>::length(u8"") == 0);
28 assert(std::char_traits<char8_t>::length(u8"a") == 1);
29 assert(std::char_traits<char8_t>::length(u8"aa") == 2);
30 assert(std::char_traits<char8_t>::length(u8"aaa") == 3);
31 assert(std::char_traits<char8_t>::length(u8"aaaa") == 4);
32
33 static_assert(test_constexpr(), "");
34 return 0;
35 }
36 #else
37 int main(int, char**) { return 0; }
38 #endif