[Flang] Add semantics checks for CrayPointer usage in DSA list (#123171)
[llvm-project.git] / libcxx / test / std / thread / thread.threads / thread.thread.class / thread.thread.id / format.pass.cpp
blob39a257592809d4f467bff97cb5186f3d452c9ce4
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
10 // UNSUPPORTED: no-threads
12 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
14 // <thread>
16 // template<class charT>
17 // struct formatter<thread::id, charT>;
19 // template<class FormatContext>
20 // typename FormatContext::iterator
21 // format(const T& r, FormatContext& ctx) const;
23 // Note this tests the basics of this function. It's tested in more detail in
24 // the format functions test.
26 #include <cassert>
27 #include <concepts>
28 #include <iterator>
29 #include <thread>
31 #include "test_format_context.h"
32 #include "test_macros.h"
33 #include "make_string.h"
35 #define SV(S) MAKE_STRING_VIEW(CharT, S)
37 template <class StringViewT>
38 void 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>;
44 const std::formatter<std::thread::id, CharT> formatter;
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);
53 template <class CharT>
54 void test_fmt() {
55 #if !defined(__APPLE__) && !defined(__FreeBSD__)
56 test_format(SV("0"), std::thread::id());
57 #else
58 test_format(SV("0x0"), std::thread::id());
59 #endif
62 void test() {
63 test_fmt<char>();
64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
65 test_fmt<wchar_t>();
66 #endif
69 int main(int, char**) {
70 test();
72 return 0;