LibQuicR
format.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) 2026 Cisco Systems
2 // SPDX-License-Identifier: BSD-2-Clause
3 
4 #pragma once
5 
6 #include <chrono>
7 #include <string>
8 #include <string_view>
9 #include <utility>
10 
11 #ifdef QUICR_HAS_STD_FORMAT
12 #include <format>
13 namespace std_or_fmt = std;
14 #else
15 #include <fmt/chrono.h>
16 namespace std_or_fmt = fmt;
17 #endif
18 
19 namespace quicr {
20 
29  template<typename... Args>
30  std::string format(std_or_fmt::format_string<Args...> msg, Args&&... args)
31  {
32  return std_or_fmt::format(msg, std::forward<Args>(args)...);
33  }
34 
44  template<typename... Args>
45  std::string vformat(std::string_view msg, Args&&... args)
46  {
47  const std_or_fmt::string_view format{ msg.data(), msg.size() };
48  return std_or_fmt::vformat(format, std_or_fmt::make_format_args(args...));
49  }
50 
51 }
Definition: attributes.h:13
std::string vformat(std::string_view msg, Args &&... args)
Formats arguments using a runtime format string.
Definition: format.h:45
std::string format(std_or_fmt::format_string< Args... > msg, Args &&... args)
Formats arguments using the configured std::format or {fmt} backend.
Definition: format.h:30