1 //===----------------------------------------------------------------------===// 2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 // See https://llvm.org/LICENSE.txt for license information. 4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 // 6 //===----------------------------------------------------------------------===// 7 8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 10 // TODO FMT Fix this test using GCC, it currently times out. 11 // UNSUPPORTED: gcc-12 12 13 // <vector> 14 15 // template<class T, class charT> 16 // requires is-vector-bool-reference<T> 17 // struct formatter<T, charT> 18 19 // template<class ParseContext> 20 // constexpr typename ParseContext::iterator 21 // parse(ParseContext& ctx); 22 23 // Note this tests the basics of this function. It's tested in more detail in 24 // the format functions test. 25 26 #include <cassert> 27 #include <concepts> 28 #include <format> 29 #include <vector> 30 31 #include "test_format_context.h" 32 #include "test_macros.h" 33 #include "make_string.h" 34 35 #define SV(S) MAKE_STRING_VIEW(CharT, S) 36 37 template <class StringViewT> 38 constexpr void test_parse(StringViewT fmt, std::size_t offset) { 39 using CharT = typename StringViewT::value_type; 40 auto parse_ctx = std::basic_format_parse_context<CharT>(fmt); 41 std::formatter<std::vector<bool, std::allocator<bool>>::reference, CharT> formatter; 42 static_assert(std::semiregular<decltype(formatter)>); 43 44 std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx); 45 assert(it == fmt.end() - offset); 46 } 47 48 template <class CharT> 49 constexpr void test_fmt() { 50 test_parse(SV(""), 0); 51 test_parse(SV("b"), 0); 52 53 test_parse(SV("}"), 1); 54 test_parse(SV("b}"), 1); 55 } 56 57 constexpr bool test() { 58 test_fmt<char>(); 59 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 60 test_fmt<wchar_t>(); 61 #endif 62 63 return true; 64 } 65 66 int main(int, char**) { 67 test(); 68 static_assert(test()); 69 70 return 0; 71 } 72