-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastiostream.hpp
More file actions
89 lines (80 loc) · 2.58 KB
/
fastiostream.hpp
File metadata and controls
89 lines (80 loc) · 2.58 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef __LIGHT_STREAM_LIB_INC
#define __LIGHT_STREAM_LIB_INC
#define FASTIO_PATTERN(op, type, code) \
fastio &operator op (type) { \
code; \
return *this; \
}
class fastio {
private:
FILE *out = stdout;
FILE *in = stdin;
FILE *err = stderr;
template <class T> void write(const T &val) {
this->operator<< (val);
}
template <class T> void read(T &val) {
this->operator>> (val);
}
template <class T> void error(const T &val) {
this->operator<= (val);
}
public:
fastio() {}
~fastio() {}
/*fastio &operator >> (char *val) {
scanf("%s", val);
return *this;
}
fastio &operator << (const char *val) {
printf("%s", val);
return *this;
}
fastio &operator <= (const char *val) {
fprintf(this->err, "%s", val);
return *this;
}
//*/
FASTIO_PATTERN(>>, char *val, scanf("%s", val))
FASTIO_PATTERN(<<, const char *val, printf("%s", val))
FASTIO_PATTERN(<=, const char *val, fprintf(this->err, "%s", val))
FASTIO_PATTERN(>>, int &val, scanf("%d", &val))
FASTIO_PATTERN(<<, int val, printf("%d", val))
FASTIO_PATTERN(>>, long long &val, scanf("%lld", &val))
FASTIO_PATTERN(<<, long long val, printf("%lld", val))
FASTIO_PATTERN(>>, long &val, scanf("%ld", &val))
FASTIO_PATTERN(<<, long val, printf("%ld", val))
FASTIO_PATTERN(>>, short &val, scanf("%hd", &val))
FASTIO_PATTERN(<<, short val, printf("%hd", val))
FASTIO_PATTERN(>>, char &val, scanf("%c", &val))
FASTIO_PATTERN(<<, char val, printf("%c", val))
template <class T, class ...AT> void write
(const T &val, const AT &...args)
{
this->operator<< (val);
this->write(args...);
}
template <class T, class ...AT> void read
(T &val, AT &...args)
{
this->operator>> (val);
this->read(args...);
}
template <class T, class ...AT> void error
(const T &val, const AT &...args)
{
this->operator<= (val);
this->error(args...);
}
};
fastio console;
/** - usage of another types:
* - example:
* fastio& operator << (light_stream &out, XTYPE val) {
* out << val.MEMBER;
* ...
* return out;
* }
*/
#undef FASTIO_PATTERN
#endif