65 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef SUPPORT_TEST_FORMAT_CONTEXT_HPP11#define SUPPORT_TEST_FORMAT_CONTEXT_HPP12 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 is17 * constructed this is implementation defined. To make the public API tests of18 * the class generic this header defines helper functions to create the19 * required object.20 *21 * @note This requires every standard library implementation to write their own22 * helper function. Vendors are encouraged to file a PR at23 * https://github.com/llvm/llvm-project so their specific implementation can be24 * part of this file.25 */26 27#include "test_macros.h"28 29#if TEST_STD_VER < 2030#error "The format header requires at least C++20"31#endif32 33#include <format>34 35#ifndef TEST_HAS_NO_LOCALIZATION36# include <locale>37#endif38 39#ifdef _LIBCPP_VERSION40 41/** Creates a std::basic_format_context as-if the formatting function takes no locale. */42template <class OutIt, class CharT>43std::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_LOCALIZATION50/** Creates a std::basic_format_context as-if the formatting function takes locale. */51template <class OutIt, class CharT>52std::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_LOCALIZATION59#else // _LIBCPP_VERSION60# 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_VERSION63 64#endif // SUPPORT_TEST_FORMAT_CONTEXT_HPP65