Debian Codegraph @

libcxx/test/std/utilities/format/format.range/format.range.fmtmap/parse.pass.cpp

raw
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 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11
12 // <format>
13
14 // template<ranges::input_range R, class charT>
15 // struct range-default-formatter<range_format::map, R, charT>
16
17 // template<class ParseContext>
18 // constexpr typename ParseContext::iterator
19 // parse(ParseContext& ctx);
20
21 // Note this tests the basics of this function. It's tested in more detail in
22 // the format.functions test.
23
24 #include <cassert>
25 #include <concepts>
26 #include <format>
27 #include <map>
28 #include <memory>
29
30 #include "test_macros.h"
31 #include "make_string.h"
32
33 #define SV(S) MAKE_STRING_VIEW(CharT, S)
34
35 template <class StringViewT>
36 constexpr void test_parse(StringViewT fmt, std::size_t offset) {
37 using CharT = typename StringViewT::value_type;
38 auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
39 std::formatter<std::map<int, int>, CharT> formatter;
40 static_assert(std::semiregular<decltype(formatter)>);
41
42 std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
43 // std::to_address works around LWG3989 and MSVC STL's iterator debugging mechanism.
44 assert(std::to_address(it) == std::to_address(fmt.end()) - offset);
45 }
46
47 template <class CharT>
48 constexpr void test_fmt() {
49 test_parse(SV(""), 0);
50 test_parse(SV(":5"), 0);
51
52 test_parse(SV("}"), 1);
53 test_parse(SV(":5}"), 1);
54 }
55
56 constexpr bool test() {
57 test_fmt<char>();
58 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
59 test_fmt<wchar_t>();
60 #endif
61
62 return true;
63 }
64
65 int main(int, char**) {
66 test();
67 static_assert(test());
68
69 return 0;
70 }