Sleipnir C++ API
Loading...
Searching...
No Matches
print.hpp
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
6#include <cstdio>
7#include <print>
8#include <system_error>
9#include <utility>
10#endif
11
12namespace slp {
13
14#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
15
17template <typename... T>
18void print(std::format_string<T...> fmt, T&&... args) {
19 try {
20 std::print(fmt, std::forward<T>(args)...);
21 } catch (const std::system_error&) {
22 }
23}
24
26template <typename... T>
27void print(std::FILE* f, std::format_string<T...> fmt, T&&... args) {
28 try {
29 std::print(f, fmt, std::forward<T>(args)...);
30 } catch (const std::system_error&) {
31 }
32}
33
35template <typename... T>
36void println(std::format_string<T...> fmt, T&&... args) {
37 try {
38 std::println(fmt, std::forward<T>(args)...);
39 } catch (const std::system_error&) {
40 }
41}
42
44template <typename... T>
45void println(std::FILE* f, std::format_string<T...> fmt, T&&... args) {
46 try {
47 std::println(f, fmt, std::forward<T>(args)...);
48 } catch (const std::system_error&) {
49 }
50}
51
52#else
53
54template <typename... Args>
55void print([[maybe_unused]] Args&&... args) {}
56
57template <typename... Args>
58void println([[maybe_unused]] Args&&... args) {}
59
60#endif
61
62} // namespace slp