brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 39a2575 Raw
74 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// UNSUPPORTED: no-threads11 12// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME13 14// <thread>15 16// template<class charT>17// struct formatter<thread::id, charT>;18 19// template<class FormatContext>20//   typename FormatContext::iterator21//     format(const T& r, FormatContext& ctx) const;22 23// Note this tests the basics of this function. It's tested in more detail in24// the format functions test.25 26#include <cassert>27#include <concepts>28#include <iterator>29#include <thread>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 37template <class StringViewT>38void test_format(StringViewT expected, std::thread::id arg) {39  using CharT      = typename StringViewT::value_type;40  using String     = std::basic_string<CharT>;41  using OutIt      = std::back_insert_iterator<String>;42  using FormatCtxT = std::basic_format_context<OutIt, CharT>;43 44  const std::formatter<std::thread::id, CharT> formatter;45 46  String result;47  OutIt out             = std::back_inserter(result);48  FormatCtxT format_ctx = test_format_context_create<OutIt, CharT>(out, std::make_format_args<FormatCtxT>(arg));49  formatter.format(arg, format_ctx);50  assert(result == expected);51}52 53template <class CharT>54void test_fmt() {55#if !defined(__APPLE__) && !defined(__FreeBSD__)56  test_format(SV("0"), std::thread::id());57#else58  test_format(SV("0x0"), std::thread::id());59#endif60}61 62void test() {63  test_fmt<char>();64#ifndef TEST_HAS_NO_WIDE_CHARACTERS65  test_fmt<wchar_t>();66#endif67}68 69int main(int, char**) {70  test();71 72  return 0;73}74