brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 0e6f620 Raw
83 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME12 13// [container.adaptors.format]14// For each of queue, priority_queue, and stack, the library provides the15// following formatter specialization where adaptor-type is the name of the16// template:17//18// template<class charT, class T, formattable<charT> Container, class... U>19//   struct formatter<adaptor-type<T, Container, U...>, charT>20 21// template<class ParseContext>22//   constexpr typename ParseContext::iterator23//     parse(ParseContext& ctx);24 25// Note this tests the basics of this function. It's tested in more detail in26// the format functions test.27 28#include <cassert>29#include <concepts>30#include <format>31#include <memory>32#include <queue>33#include <stack>34 35#include "test_macros.h"36#include "make_string.h"37 38#define SV(S) MAKE_STRING_VIEW(CharT, S)39 40template <class Arg, class StringViewT>41constexpr 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)>);46 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);50}51 52template <class StringViewT>53constexpr 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);57}58 59template <class CharT>60constexpr void test_fmt() {61  test_parse(SV(""), 0);62  test_parse(SV(":d"), 0);63 64  test_parse(SV("}"), 1);65  test_parse(SV(":d}"), 1);66}67 68constexpr bool test() {69  test_fmt<char>();70#ifndef TEST_HAS_NO_WIDE_CHARACTERS71  test_fmt<wchar_t>();72#endif73 74  return true;75}76 77int main(int, char**) {78  test();79  static_assert(test());80 81  return 0;82}83