xref: /llvm-project/libcxx/test/support/test_format_context.h (revision 8cd5e672602676877b9025a750b20f895ca0bc25)
10922ce56SMark de Wever // -*- C++ -*-
20922ce56SMark de Wever //===----------------------------------------------------------------------===//
30922ce56SMark de Wever //
40922ce56SMark de Wever // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50922ce56SMark de Wever // See https://llvm.org/LICENSE.txt for license information.
60922ce56SMark de Wever // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70922ce56SMark de Wever //
80922ce56SMark de Wever //===----------------------------------------------------------------------===//
90922ce56SMark de Wever 
100922ce56SMark de Wever #ifndef SUPPORT_TEST_FORMAT_CONTEXT_HPP
110922ce56SMark de Wever #define SUPPORT_TEST_FORMAT_CONTEXT_HPP
120922ce56SMark de Wever 
130922ce56SMark de Wever /**
140922ce56SMark de Wever  * @file Helper functions to create a @ref std::basic_format_context.
150922ce56SMark de Wever  *
160922ce56SMark de Wever  * Since the standard doesn't specify how a @ref std::basic_format_context is
170922ce56SMark de Wever  * constructed this is implementation defined. To make the public API tests of
180922ce56SMark de Wever  * the class generic this header defines helper functions to create the
190922ce56SMark de Wever  * required object.
200922ce56SMark de Wever  *
210922ce56SMark de Wever  * @note This requires every standard library implementation to write their own
22*8cd5e672SMark de Wever  * helper function. Vendors are encouraged to file a PR at
23*8cd5e672SMark de Wever  * https://github.com/llvm/llvm-project so their specific implementation can be
24*8cd5e672SMark de Wever  * part of this file.
250922ce56SMark de Wever  */
260922ce56SMark de Wever 
27c0ac3c11SMark de Wever #include "test_macros.h"
28c0ac3c11SMark de Wever 
290922ce56SMark de Wever #if TEST_STD_VER < 20
300922ce56SMark de Wever #error "The format header requires at least C++20"
310922ce56SMark de Wever #endif
320922ce56SMark de Wever 
330922ce56SMark de Wever #include <format>
340922ce56SMark de Wever 
35e70887ddSMark de Wever #ifndef TEST_HAS_NO_LOCALIZATION
360922ce56SMark de Wever #  include <locale>
370922ce56SMark de Wever #endif
380922ce56SMark de Wever 
39e70887ddSMark de Wever #ifdef _LIBCPP_VERSION
400922ce56SMark de Wever 
410922ce56SMark de Wever /** Creates a std::basic_format_context as-if the formatting function takes no locale. */
420922ce56SMark de Wever template <class OutIt, class CharT>
test_format_context_create(OutIt out_it,std::basic_format_args<std::basic_format_context<OutIt,CharT>> args)430922ce56SMark de Wever std::basic_format_context<OutIt, CharT> test_format_context_create(
440922ce56SMark de Wever     OutIt out_it,
450922ce56SMark de Wever     std::basic_format_args<std::basic_format_context<OutIt, CharT>> args) {
460922ce56SMark de Wever   return std::__format_context_create(std::move(out_it), args);
470922ce56SMark de Wever }
480922ce56SMark de Wever 
49e70887ddSMark de Wever #  ifndef TEST_HAS_NO_LOCALIZATION
500922ce56SMark de Wever /** Creates a std::basic_format_context as-if the formatting function takes locale. */
510922ce56SMark de Wever 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)520922ce56SMark de Wever std::basic_format_context<OutIt, CharT> test_format_context_create(
530922ce56SMark de Wever     OutIt out_it,
540922ce56SMark de Wever     std::basic_format_args<std::basic_format_context<OutIt, CharT>> args,
550922ce56SMark de Wever     std::locale loc) {
560922ce56SMark de Wever   return std::__format_context_create(std::move(out_it), args, std::move(loc));
570922ce56SMark de Wever }
58e70887ddSMark de Wever #  endif // TEST_HAS_NO_LOCALIZATION
59e70887ddSMark de Wever #else    // _LIBCPP_VERSION
60*8cd5e672SMark de Wever #  error                                                                                                               \
61*8cd5e672SMark de Wever       "Please create a vendor specific version of the test typedef and file a PR at https://github.com/llvm/llvm-project"
62e70887ddSMark de Wever #endif // _LIBCPP_VERSION
630922ce56SMark de Wever 
640922ce56SMark de Wever #endif // SUPPORT_TEST_FORMAT_CONTEXT_HPP
65