libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

length.pass.cpp (1185B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
     10 
     11 // <string>
     12 
     13 // template<> struct char_traits<char8_t>
     14 
     15 // static constexpr size_t length(const char_type* s);
     16 
     17 #include <string>
     18 #include <cassert>
     19 
     20 #include "test_macros.h"
     21 
     22 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
     23 constexpr bool test_constexpr()
     24 {
     25     return std::char_traits<char8_t>::length(u8"") == 0
     26         && std::char_traits<char8_t>::length(u8"abcd") == 4;
     27 }
     28 
     29 int main()
     30 {
     31     assert(std::char_traits<char8_t>::length(u8"") == 0);
     32     assert(std::char_traits<char8_t>::length(u8"a") == 1);
     33     assert(std::char_traits<char8_t>::length(u8"aa") == 2);
     34     assert(std::char_traits<char8_t>::length(u8"aaa") == 3);
     35     assert(std::char_traits<char8_t>::length(u8"aaaa") == 4);
     36 
     37     static_assert(test_constexpr(), "");
     38 }
     39 #else
     40 int main() { }
     41 #endif