Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / containers / container.adaptors / container.adaptors.format / parse.pass.cpp
blob0e6f6207267b87529b3740bf53d0f432debec3b4
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 //===----------------------------------------------------------------------===//
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
16 // template:
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.
28 #include <cassert>
29 #include <concepts>
30 #include <format>
31 #include <memory>
32 #include <queue>
33 #include <stack>
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() {
69 test_fmt<char>();
70 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
71 test_fmt<wchar_t>();
72 #endif
74 return true;
77 int main(int, char**) {
78 test();
79 static_assert(test());
81 return 0;