Debian Codegraph @

libcxx/test/support/test_format_string.h

raw
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_STRING_HPP
11 #define SUPPORT_TEST_FORMAT_STRING_HPP
12
13 #include <concepts>
14 #include <format>
15 #include <type_traits>
16
17 #include "test_macros.h"
18
19 #if TEST_STD_VER < 20
20 # error "The format header requires at least C++20"
21 #endif
22
23 // Wrapper for basic_format_string.
24 //
25 // This layer of indirection is used since it's not possible to use
26 // std::basic_format_string<CharT, Args...> in the test function directly.
27 //
28 // In C++20 the basic-format-string was an exposition only type. In C++23 is
29 // has been replaced with basic_format_string. Both libc++ and MSVC STL offer
30 // it as an extension in C++20.
31 #if TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined(_MSVC_STL_VERSION)
32 # ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 template <class CharT, class... Args>
34 using test_format_string =
35 std::conditional_t<std::same_as<CharT, char>, std::format_string<Args...>, std::wformat_string<Args...>>;
36 # else
37 template <class CharT, class... Args>
38 using test_format_string = std::format_string<Args...>;
39 # endif
40
41 #else // TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined( _MSVC_STL_VERSION)
42
43 # error \
44 "Please create a vendor specific version of the test typedef and file a PR at https://github.com/llvm/llvm-project"
45
46 #endif // TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined( _MSVC_STL_VERSION)
47
48 #endif // SUPPORT_TEST_FORMAT_STRING_HPP