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 
9 // <locale>
10 
11 // template <> class codecvt<char32_t, char8_t, mbstate_t>
12 
13 // int length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
14 
15 // UNSUPPORTED: c++03, c++11, c++14, c++17
16 
17 // C++20 codecvt specializations for char8_t are not yet implemented:
18 // UNSUPPORTED: libc++
19 
20 #include <cassert>
21 #include <locale>
22 
main(int,char **)23 int main(int, char**) {
24   using F = std::codecvt<char32_t, char8_t, std::mbstate_t>;
25   const F& f = std::use_facet<F>(std::locale::classic());
26   std::mbstate_t mbs = {};
27   const char8_t from[] = u8"some text";
28   assert(f.length(mbs, from, from + 10, 0) == 0);
29   assert(f.length(mbs, from, from + 10, 8) == 8);
30   assert(f.length(mbs, from, from + 10, 9) == 9);
31   assert(f.length(mbs, from, from + 10, 10) == 10);
32   assert(f.length(mbs, from, from + 10, 100) == 10);
33   return 0;
34 }
35