summaryrefslogtreecommitdiff
path: root/libcxx/test/support/test_basic_format_arg.h
blob: 99cd558c3c5bf41dab2f6c9fe34dc16432128bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <concepts>
#include <format>
#include <utility>

#include "test_macros.h"

/// Returns whether the basic_format_arg contains a type T with the expected value.
template <class Context, class T>
bool test_basic_format_arg(std::basic_format_arg<Context> arg, T expected) {
  auto visitor = [expected](auto a) {
    if constexpr (std::same_as<decltype(a), T>)
      return a == expected;
    else
      return false;
  };
#if TEST_STD_VER >= 26
  return arg.visit(std::move(visitor));
#else
  return std::visit_format_arg(std::move(visitor), arg);
#endif
}