1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // [container.adaptors.format]
14 // For each of queue, priority_queue, and stack, the library provides the
15 // following formatter specialization where adaptor-type is the name of the
18 // template<class charT, class T, formattable<charT> Container, class... U>
19 // struct formatter<adaptor-type<T, Container, U...>, charT>
21 // template<class ParseContext>
22 // constexpr typename ParseContext::iterator
23 // parse(ParseContext& ctx);
25 // Note this tests the basics of this function. It's tested in more detail in
26 // the format functions test.
35 #include "test_macros.h"
36 #include "make_string.h"
38 #define SV(S) MAKE_STRING_VIEW(CharT, S)
40 template <class Arg
, class StringViewT
>
41 constexpr void test_parse(StringViewT fmt
, std::size_t offset
) {
42 using CharT
= typename
StringViewT::value_type
;
43 auto parse_ctx
= std::basic_format_parse_context
<CharT
>(fmt
);
44 std::formatter
<Arg
, CharT
> formatter
;
45 static_assert(std::semiregular
<decltype(formatter
)>);
47 std::same_as
<typename
StringViewT::iterator
> auto it
= formatter
.parse(parse_ctx
);
48 // std::to_address works around LWG3989 and MSVC STL's iterator debugging mechanism.
49 assert(std::to_address(it
) == std::to_address(fmt
.end()) - offset
);
52 template <class StringViewT
>
53 constexpr void test_parse(StringViewT fmt
, std::size_t offset
) {
54 test_parse
<std::queue
<int>>(fmt
, offset
);
55 test_parse
<std::priority_queue
<int>>(fmt
, offset
);
56 test_parse
<std::stack
<int>>(fmt
, offset
);
59 template <class CharT
>
60 constexpr void test_fmt() {
61 test_parse(SV(""), 0);
62 test_parse(SV(":d"), 0);
64 test_parse(SV("}"), 1);
65 test_parse(SV(":d}"), 1);
68 constexpr bool test() {
70 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
77 int main(int, char**) {
79 static_assert(test());