-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.h
33 lines (27 loc) · 901 Bytes
/
io.h
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
30
31
32
33
#pragma once
#include <format>
#include <iostream>
#include <mutex>
#include <utility>
extern std::recursive_mutex io_mutex;
template <typename... Args>
void mPrint(std::ostream& os, std::format_string<Args...> fmt, Args&&... args) {
auto s = std::format(fmt, std::forward<Args>(args)...);
std::lock_guard lk(io_mutex);
os << std::move(s);
}
template <typename... Args>
void mPrintLn(std::ostream& os, std::format_string<Args...> fmt,
Args&&... args) {
auto s = std::format(fmt, std::forward<Args>(args)...);
std::lock_guard lk(io_mutex);
os << std::move(s) << '\n';
}
template <typename... Args>
void mPrint(std::format_string<Args...> fmt, Args&&... args) {
mPrint(std::cout, fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void mPrintLn(std::format_string<Args...> fmt, Args&&... args) {
mPrintLn(std::cout, fmt, std::forward<Args>(args)...);
}