File tree Expand file tree Collapse file tree 3 files changed +70
-1
lines changed Expand file tree Collapse file tree 3 files changed +70
-1
lines changed Original file line number Diff line number Diff line change 1
- # coutln
1
+ # coutln
2
+ auto line-break cout.
3
+
4
+ ``` cpp
5
+ coutln << format(" {}" , value);
6
+ ```
7
+
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+ // Copyright Akira Takahashi 2020
3
+ // Use, modification and distribution is subject to the Boost Software License,
4
+ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5
+ // http://www.boost.org/LICENSE_1_0.txt)
6
+
7
+ #include < iostream>
8
+ #include < utility>
9
+
10
+ namespace io {
11
+
12
+ struct coutln_t {};
13
+ inline coutln_t coutln{};
14
+
15
+ struct cerrln_t {};
16
+ inline cerrln_t cerrln{};
17
+
18
+ struct clogln_t {};
19
+ inline clogln_t clogln{};
20
+
21
+ struct wcoutln_t {};
22
+ inline wcoutln_t wcoutln{};
23
+
24
+ struct wcerrln_t {};
25
+ inline wcerrln_t wcerrln{};
26
+
27
+ struct wclogln_t {};
28
+ inline wclogln_t wclogln{};
29
+
30
+
31
+ #define DEFINE_OSTREAM_OPERATOR (type, os ) \
32
+ template <class T > \
33
+ type& operator <<(type& out, const T& x) { \
34
+ os << x << std::endl; \
35
+ return out; \
36
+ } \
37
+ \
38
+ template <class T > \
39
+ type& operator <<(type& out, T&& x) { \
40
+ os << std::move (x) << std::endl; \
41
+ return out; \
42
+ }
43
+
44
+ DEFINE_OSTREAM_OPERATOR (coutln_t , std::cout);
45
+ DEFINE_OSTREAM_OPERATOR (cerrln_t , std::cerr);
46
+ DEFINE_OSTREAM_OPERATOR (clogln_t , std::clog);
47
+
48
+ DEFINE_OSTREAM_OPERATOR (wcoutln_t , std::wcout);
49
+ DEFINE_OSTREAM_OPERATOR (wcerrln_t , std::wcerr);
50
+ DEFINE_OSTREAM_OPERATOR (wclogln_t , std::wclog);
51
+
52
+ }
Original file line number Diff line number Diff line change
1
+ #include " coutln.h"
2
+
3
+ int main () {
4
+ io::coutln << " Hello" << " World" ;
5
+ io::cerrln << " Hello" << " World" ;
6
+ io::clogln << " Hello" << " World" ;
7
+
8
+ io::wcoutln << " Hello" << " World" ;
9
+ io::wcerrln << " Hello" << " World" ;
10
+ io::wclogln << " Hello" << " World" ;
11
+ }
You can’t perform that action at this time.
0 commit comments