Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / support / test_format_context.h
blobd7d38b5aceca607700ed9c42a9ec785bfceaf0f6
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 //===----------------------------------------------------------------------===//
10 #ifndef SUPPORT_TEST_FORMAT_CONTEXT_HPP
11 #define SUPPORT_TEST_FORMAT_CONTEXT_HPP
13 /**
14 * @file Helper functions to create a @ref std::basic_format_context.
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.
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.
27 #include "test_macros.h"
29 #if TEST_STD_VER < 20
30 #error "The format header requires at least C++20"
31 #endif
33 #include <format>
35 #ifndef TEST_HAS_NO_LOCALIZATION
36 # include <locale>
37 #endif
39 #ifdef _LIBCPP_VERSION
41 /** Creates a std::basic_format_context as-if the formatting function takes no locale. */
42 template <class OutIt, class CharT>
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);
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>
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));
58 # endif // TEST_HAS_NO_LOCALIZATION
59 #else // _LIBCPP_VERSION
60 # error "Please create a vendor specific version of the test functions and file a review at https://reviews.llvm.org/"
61 #endif // _LIBCPP_VERSION
63 #endif // SUPPORT_TEST_FORMAT_CONTEXT_HPP