WPILibC++ 2025.0.0-alpha-1-14-g3b6f38d
print.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <system_error>
8#include <utility>
9
10#if __has_include(<fmt/base.h>)
11#include <fmt/base.h>
12#else
13#include <fmt/core.h>
14#endif
15
16namespace wpi {
17
18/**
19 * Wrapper around fmt::print() that squelches write failure exceptions.
20 */
21template <typename... T>
22inline void print(fmt::format_string<T...> fmt, T&&... args) {
23 try {
24 fmt::print(fmt, std::forward<T>(args)...);
25 } catch (const std::system_error&) {
26 }
27}
28
29/**
30 * Wrapper around fmt::print() that squelches write failure exceptions.
31 */
32template <typename... T>
33inline void print(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
34 try {
35 fmt::print(f, fmt, std::forward<T>(args)...);
36 } catch (const std::system_error&) {
37 }
38}
39
40/**
41 * Wrapper around fmt::println() that squelches write failure exceptions.
42 */
43template <typename... T>
44inline void println(fmt::format_string<T...> fmt, T&&... args) {
45 try {
46 fmt::println(fmt, std::forward<T>(args)...);
47 } catch (const std::system_error&) {
48 }
49}
50
51/**
52 * Wrapper around fmt::println() that squelches write failure exceptions.
53 */
54template <typename... T>
55inline void println(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
56 try {
57 fmt::println(f, fmt, std::forward<T>(args)...);
58 } catch (const std::system_error&) {
59 }
60}
61
62} // namespace wpi
auto system_error(int error_code, format_string< T... > fmt, T &&... args) -> std::system_error
Constructs std::system_error with a message formatted with fmt::format(fmt, args.....
Definition: format.h:3894
Definition: ntcore_cpp.h:26
void print(wpi::raw_ostream &os, const S &format_str, Args &&... args)
Prints formatted data to the stream os.
Definition: raw_ostream.h:25
void print(std::FILE *f, fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::print() that squelches write failure exceptions.
Definition: print.h:33
void println(fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::println() that squelches write failure exceptions.
Definition: print.h:44
void println(std::FILE *f, fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::println() that squelches write failure exceptions.
Definition: print.h:55