WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
print.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
6#include <cstdio>
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
16#endif
17
18namespace slp {
19
20#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
21
22/**
23 * Wrapper around fmt::print() that squelches write failure exceptions.
24 */
25template <typename... T>
26inline void print(fmt::format_string<T...> fmt, T&&... args) {
27 try {
28 fmt::print(fmt, std::forward<T>(args)...);
29 } catch (const std::system_error&) {
30 }
31}
32
33/**
34 * Wrapper around fmt::print() that squelches write failure exceptions.
35 */
36template <typename... T>
37inline void print(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
38 try {
39 fmt::print(f, fmt, std::forward<T>(args)...);
40 } catch (const std::system_error&) {
41 }
42}
43
44/**
45 * Wrapper around fmt::println() that squelches write failure exceptions.
46 */
47template <typename... T>
48inline void println(fmt::format_string<T...> fmt, T&&... args) {
49 try {
50 fmt::println(fmt, std::forward<T>(args)...);
51 } catch (const std::system_error&) {
52 }
53}
54
55/**
56 * Wrapper around fmt::println() that squelches write failure exceptions.
57 */
58template <typename... T>
59inline void println(std::FILE* f, fmt::format_string<T...> fmt, T&&... args) {
60 try {
61 fmt::println(f, fmt, std::forward<T>(args)...);
62 } catch (const std::system_error&) {
63 }
64}
65
66#else
67
68template <typename... Args>
69inline void print([[maybe_unused]] Args&&... args) {}
70
71template <typename... Args>
72inline void println([[maybe_unused]] Args&&... args) {}
73
74#endif
75
76} // namespace slp
Definition expression_graph.hpp:11
void println(fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::println() that squelches write failure exceptions.
Definition print.hpp:48
void print(fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::print() that squelches write failure exceptions.
Definition print.hpp:26