-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathostream_stdcontainer.h
86 lines (67 loc) · 1.99 KB
/
ostream_stdcontainer.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
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
/*
* Author: LiZhaojia
*
* Last modified: 2014-09-29 22:01 +0800
*
* Description: 对标准容器重载的operator<<(std::ostream), 方便用std::cout输出容器内容
*/
#ifndef WATER_BASE_TEST_OSTREAM_STDCONTAINER_HPP
#define WATER_BASE_TEST_OSTREAM_STDCONTAINER_HPP
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <forward_list>
#include <tuple>
#include <iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
template<typename T1, typename T2>
std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& pair)
{
os << "[";
os << pair.first << " ";
os << ',';
os << pair.second << " ";
os << "]" << " ";
return os;
}
#define SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(Container) \
template<typename T>\
std::ostream& operator << (std::ostream& os, const Container<T>& con)\
{\
os << "{";\
for(const auto& item : con)\
os << item << " ";\
os << "}";\
return os;\
}
#define ASSOCIATIVE_CONTAINER_OSTREAM_OPERATOR(Container) \
template<typename T1, typename T2>\
std::ostream& operator << (std::ostream& os, const Container<T1, T2>& con)\
{\
os << "{";\
for(const auto& item : con)\
os << item << " ";\
os << "}";\
return os;\
}
ASSOCIATIVE_CONTAINER_OSTREAM_OPERATOR(std::map)
ASSOCIATIVE_CONTAINER_OSTREAM_OPERATOR(std::multimap)
ASSOCIATIVE_CONTAINER_OSTREAM_OPERATOR(std::unordered_map)
ASSOCIATIVE_CONTAINER_OSTREAM_OPERATOR(std::unordered_multimap)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::set)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::multiset)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::unordered_set)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::unordered_multiset)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::vector)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::deque)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::list)
SENQUENTIAL_CONTAINER_OSTREAM_OPERATOR(std::forward_list)
#endif