| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | // UNSUPPORTED: no-threads |
| 11 | |
| 12 | // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 13 | |
| 14 | // <thread> |
| 15 | |
| 16 | // template<class charT> |
| 17 | // struct formatter<thread::id, charT>; |
| 18 | |
| 19 | // template<class FormatContext> |
| 20 | // typename FormatContext::iterator |
| 21 | // format(const T& r, FormatContext& ctx) const; |
| 22 | |
| 23 | // Note this tests the basics of this function. It's tested in more detail in |
| 24 | // 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 | |
| 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>; |
| 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 | |
| 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 |
| 60 | } |
| 61 | |
| 62 | void test() { |
| 63 | test_fmt<char>(); |
| 64 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 65 | test_fmt<wchar_t>(); |
| 66 | #endif |
| 67 | } |
| 68 | |
| 69 | int main(int, char**) { |
| 70 | test(); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |