xref: /llvm-project/libcxx/test/support/test_basic_format_arg.h (revision 27e67cdb31bed4c346af925686c031d57aef9846)
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 
8 #include <concepts>
9 #include <format>
10 #include <utility>
11 
12 #include "test_macros.h"
13 
14 /// Returns whether the basic_format_arg contains a type T with the expected value.
15 template <class Context, class T>
16 bool test_basic_format_arg(std::basic_format_arg<Context> arg, T expected) {
17   auto visitor = [expected](auto a) {
18     if constexpr (std::same_as<decltype(a), T>)
19       return a == expected;
20     else
21       return false;
22   };
23 #if TEST_STD_VER >= 26 && defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
24   return arg.visit(std::move(visitor));
25 #else
26   return std::visit_format_arg(std::move(visitor), arg);
27 #endif
28 }
29