xref: /aosp_15_r20/external/cronet/third_party/libc++/src/test/support/test_format_context.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 PR at
23  * https://github.com/llvm/llvm-project so their specific implementation can be
24  * part of this file.
25  */
26 
27 #include "test_macros.h"
28 
29 #if TEST_STD_VER < 20
30 #error "The format header requires at least C++20"
31 #endif
32 
33 #include <format>
34 
35 #ifndef TEST_HAS_NO_LOCALIZATION
36 #  include <locale>
37 #endif
38 
39 #ifdef _LIBCPP_VERSION
40 
41 /** Creates a std::basic_format_context as-if the formatting function takes no locale. */
42 template <class OutIt, class CharT>
test_format_context_create(OutIt out_it,std::basic_format_args<std::basic_format_context<OutIt,CharT>> args)43 std::basic_format_context<OutIt, CharT> test_format_context_create(
44     OutIt out_it,
45     std::basic_format_args<std::basic_format_context<OutIt, CharT>> args) {
46   return std::__format_context_create(std::move(out_it), args);
47 }
48 
49 #  ifndef TEST_HAS_NO_LOCALIZATION
50 /** Creates a std::basic_format_context as-if the formatting function takes locale. */
51 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)52 std::basic_format_context<OutIt, CharT> test_format_context_create(
53     OutIt out_it,
54     std::basic_format_args<std::basic_format_context<OutIt, CharT>> args,
55     std::locale loc) {
56   return std::__format_context_create(std::move(out_it), args, std::move(loc));
57 }
58 #  endif // TEST_HAS_NO_LOCALIZATION
59 #else    // _LIBCPP_VERSION
60 #  error                                                                                                               \
61       "Please create a vendor specific version of the test typedef and file a PR at https://github.com/llvm/llvm-project"
62 #endif // _LIBCPP_VERSION
63 
64 #endif // SUPPORT_TEST_FORMAT_CONTEXT_HPP
65