Open C++ Libraries.org develop
Loading...
Searching...
No Matches
print_fwd.hpp
1// SPDX-License-Identifier: BSL-1.0
2// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org)
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5// Official repository: https://github.com/open-cpp-libraries/core
6
7#ifndef OCL_CORE_PRINT
8#define OCL_CORE_PRINT
9
10#include <ocl/detail/config.hpp>
11#include <ocl/io_fwd.hpp>
12
13#ifdef OCL_HAS_PRINT_LIBRARY
14#include <print>
15#endif
16
18
19namespace ocl::io
20{
21
22 template <typename T>
23 inline void print(T fmt) noexcept
24 {
25 console_io_out << fmt;
26 }
27
28 inline void print() noexcept
29 {
31 extern void lf() noexcept;
32 lf();
33 }
34
35 template <typename... Args>
36 inline void print(Args... fmt) noexcept
37 {
38 print(fmt...);
39 print();
40 }
41
42 template <typename T, typename... Args>
43 inline void print(T fmt, Args... other) noexcept
44 {
45 console_io_out << fmt;
46 print(other...);
47 }
48
49 namespace detail
50 {
51 inline bool is_stdio_sync = true;
52
53 using io_error = std::runtime_error;
54
55 inline void throw_option_invalid_type_error(const boost::source_location& loc = BOOST_CURRENT_LOCATION)
56 {
57 ::boost::throw_exception(std::runtime_error(""), loc);
58 }
59 } // namespace detail
60
62 inline void enable_stdio_sync(const bool& enable) noexcept
63 {
64 detail::is_stdio_sync = enable;
65 console_io_out.sync_with_stdio(detail::is_stdio_sync);
66 }
67
69 inline const bool& is_stdio_sync()
70 {
71 return detail::is_stdio_sync;
72 }
73
74 inline void lf() noexcept
75 {
76#ifdef OCL_USE_CRLF_ENDINGS
77 if (!is_stdio_sync())
78 print("\r\n");
79#else
80 if (!is_stdio_sync())
81 print("\n");
82#endif
83
84 if (is_stdio_sync())
85 console_io_out << std::endl;
86 }
87
88 template <typename... T>
89 inline void println(T... fmt) noexcept
90 {
91 print(fmt...);
92 lf();
93 }
94
95} // namespace ocl::io
96
97#endif // ifndef OCL_CORE_PRINT
This file takes care of I/O manip.
Definition print_fwd.hpp:20
void print() noexcept
Definition print_fwd.hpp:28
const bool & is_stdio_sync()
Checks if standard I/O synchronization is enabled.
Definition print_fwd.hpp:69
void enable_stdio_sync(const bool &enable) noexcept
Enables or disables synchronization between C++ standard streams and C standard streams.
Definition print_fwd.hpp:62