Skip to content

Commit 05c1b8e

Browse files
committed
implement
1 parent 61b76ef commit 05c1b8e

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# coutln
1+
# coutln
2+
auto line-break cout.
3+
4+
```cpp
5+
coutln << format("{}", value);
6+
```
7+

coutln.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

example.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

0 commit comments

Comments
 (0)