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 const char_type* find(const char_type* s, size_t n, const char_type& a); 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 constexpr const char8_t *p = u8"123"; 26 return std::char_traits<char8_t>::find(p, 3, u8'1') == p 27 && std::char_traits<char8_t>::find(p, 3, u8'2') == p + 1 28 && std::char_traits<char8_t>::find(p, 3, u8'3') == p + 2 29 && std::char_traits<char8_t>::find(p, 3, u8'4') == nullptr; 30 } 31 32 int main() 33 { 34 char8_t s1[] = {1, 2, 3}; 35 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(1)) == s1); 36 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(2)) == s1+1); 37 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(3)) == s1+2); 38 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(4)) == 0); 39 assert(std::char_traits<char8_t>::find(s1, 3, char8_t(0)) == 0); 40 assert(std::char_traits<char8_t>::find(NULL, 0, char8_t(0)) == 0); 41 42 static_assert(test_constexpr(), "" ); 43 } 44 #else 45 int main () {} 46 #endif 47