1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef SUPPORT_TEST_FORMAT_CONTEXT_HPP
11 #define SUPPORT_TEST_FORMAT_CONTEXT_HPP
12
13 /**
14 * @file Helper functions to create a @ref std::basic_format_context.
15 *
16 * Since the standard doesn't specify how a @ref std::basic_format_context is
17 * constructed this is implementation defined. To make the public API tests of
18 * the class generic this header defines helper functions to create the
19 * required object.
20 *
21 * @note This requires every standard library implementation to write their own
22 * helper function. Vendors are encouraged to file a review at
23 * https://reviews.llvm.org/ so their specific implementation can be part of
24 * this file.
25 */
26
27 #if TEST_STD_VER < 20
28 #error "The format header requires at least C++20"
29 #endif
30
31 #include <format>
32
33 #ifndef _LIBCPP_HAS_NO_LOCALIZATION
34 #include <locale>
35 #endif
36
37 #if defined(_LIBCPP_VERSION)
38
39 /** Creates a std::basic_format_context as-if the formatting function takes no locale. */
40 template <class OutIt, class CharT>
test_format_context_create(OutIt out_it,std::basic_format_args<std::basic_format_context<OutIt,CharT>> args)41 std::basic_format_context<OutIt, CharT> test_format_context_create(
42 OutIt out_it,
43 std::basic_format_args<std::basic_format_context<OutIt, CharT>> args) {
44 return std::__format_context_create(std::move(out_it), args);
45 }
46
47 #ifndef _LIBCPP_HAS_NO_LOCALIZATION
48 /** Creates a std::basic_format_context as-if the formatting function takes locale. */
49 template <class OutIt, class CharT>
test_format_context_create(OutIt out_it,std::basic_format_args<std::basic_format_context<OutIt,CharT>> args,std::locale loc)50 std::basic_format_context<OutIt, CharT> test_format_context_create(
51 OutIt out_it,
52 std::basic_format_args<std::basic_format_context<OutIt, CharT>> args,
53 std::locale loc) {
54 return std::__format_context_create(std::move(out_it), args, std::move(loc));
55 }
56 #endif
57 #else
58 #error \
59 "Please create a vendor specific version of the test functions and file a review at https://reviews.llvm.org/"
60 #endif
61
62 #endif // SUPPORT_TEST_FORMAT_CONTEXT_HPP
63