Add -lpthread in addition to -pthread on Linux.
[platform/upstream/glog.git] / src / glog / stl_logging.h.in
1 // Copyright 2003 Google, Inc.
2 // All Rights Reserved.
3 //
4 // Stream output operators for STL containers; to be used for logging *only*.
5 // Inclusion of this file lets you do:
6 //
7 // list<string> x;
8 // LOG(INFO) << "data: " << x;
9 // vector<int> v1, v2;
10 // CHECK_EQ(v1, v2);
11 //
12 // Note that if you want to use these operators from the non-global namespace,
13 // you may get an error since they are not in namespace std (and they are not
14 // in namespace std since that would result in undefined behavior). You may
15 // need to write
16 //
17 //   using ::operator<<;
18 //
19 // to fix these errors.
20
21 #ifndef UTIL_GTL_STL_LOGGING_INL_H_
22 #define UTIL_GTL_STL_LOGGING_INL_H_
23
24 #if !@ac_cv_cxx_using_operator@
25 # error We do not support stl_logging for this compiler
26 #endif
27
28 #include <deque>
29 #include <list>
30 #include <map>
31 #include <ostream>
32 #include <set>
33 #include <utility>
34 #include <vector>
35
36 #ifdef __GNUC__
37 # include <ext/hash_set>
38 # include <ext/hash_map>
39 # include <ext/slist>
40 #endif
41
42 template<class First, class Second>
43 inline std::ostream& operator<<(std::ostream& out,
44                                 const std::pair<First, Second>& p) {
45   out << '(' << p.first << ", " << p.second << ')';
46   return out;
47 }
48
49 @ac_google_start_namespace@
50
51 template<class Iter>
52 inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
53   using ::operator<<;
54   // Output at most 100 elements -- appropriate if used for logging.
55   for (int i = 0; begin != end && i < 100; ++i, ++begin) {
56     if (i > 0) out << ' ';
57     out << *begin;
58   }
59   if (begin != end) {
60     out << " ...";
61   }
62 }
63
64 @ac_google_end_namespace@
65
66 #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
67 template<class T1, class T2> \
68 inline std::ostream& operator<<(std::ostream& out, \
69                                 const Sequence<T1, T2>& seq) { \
70   @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
71   return out; \
72 }
73
74 OUTPUT_TWO_ARG_CONTAINER(std::vector)
75 OUTPUT_TWO_ARG_CONTAINER(std::deque)
76 OUTPUT_TWO_ARG_CONTAINER(std::list)
77 #ifdef __GNUC__
78 OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
79 #endif
80
81 #undef OUTPUT_TWO_ARG_CONTAINER
82
83 #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
84 template<class T1, class T2, class T3> \
85 inline std::ostream& operator<<(std::ostream& out, \
86                                 const Sequence<T1, T2, T3>& seq) { \
87   @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
88   return out; \
89 }
90
91 OUTPUT_THREE_ARG_CONTAINER(std::set)
92 OUTPUT_THREE_ARG_CONTAINER(std::multiset)
93
94 #undef OUTPUT_THREE_ARG_CONTAINER
95
96 #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
97 template<class T1, class T2, class T3, class T4> \
98 inline std::ostream& operator<<(std::ostream& out, \
99                                 const Sequence<T1, T2, T3, T4>& seq) { \
100   @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
101   return out; \
102 }
103
104 OUTPUT_FOUR_ARG_CONTAINER(std::map)
105 OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
106 #ifdef __GNUC__
107 OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set)
108 OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
109 #endif
110
111 #undef OUTPUT_FOUR_ARG_CONTAINER
112
113 #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
114 template<class T1, class T2, class T3, class T4, class T5> \
115 inline std::ostream& operator<<(std::ostream& out, \
116                                 const Sequence<T1, T2, T3, T4, T5>& seq) { \
117   @ac_google_namespace@::PrintSequence(out, seq.begin(), seq.end()); \
118   return out; \
119 }
120
121 #ifdef __GNUC__
122 OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map)
123 OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
124 #endif
125
126 #undef OUTPUT_FIVE_ARG_CONTAINER
127
128 #endif  // UTIL_GTL_STL_LOGGING_INL_H_