1 // This file is automatically generated from src/glog/stl_logging.h.in
2 // using src/windows/preprocess.sh.
5 // Copyright 2003 Google, Inc.
6 // All Rights Reserved.
8 // Stream output operators for STL containers; to be used for logging *only*.
9 // Inclusion of this file lets you do:
12 // LOG(INFO) << "data: " << x;
13 // vector<int> v1, v2;
16 // Note that if you want to use these operators from the non-global namespace,
17 // you may get an error since they are not in namespace std (and they are not
18 // in namespace std since that would result in undefined behavior). You may
21 // using ::operator<<;
23 // to fix these errors.
25 #ifndef UTIL_GTL_STL_LOGGING_INL_H_
26 #define UTIL_GTL_STL_LOGGING_INL_H_
29 # error We do not support stl_logging for this compiler
41 # include <ext/hash_set>
42 # include <ext/hash_map>
46 template<class First, class Second>
47 inline std::ostream& operator<<(std::ostream& out,
48 const std::pair<First, Second>& p) {
49 out << '(' << p.first << ", " << p.second << ')';
56 inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
58 // Output at most 100 elements -- appropriate if used for logging.
59 for (int i = 0; begin != end && i < 100; ++i, ++begin) {
60 if (i > 0) out << ' ';
70 #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \
71 template<class T1, class T2> \
72 inline std::ostream& operator<<(std::ostream& out, \
73 const Sequence<T1, T2>& seq) { \
74 google::PrintSequence(out, seq.begin(), seq.end()); \
78 OUTPUT_TWO_ARG_CONTAINER(std::vector)
79 OUTPUT_TWO_ARG_CONTAINER(std::deque)
80 OUTPUT_TWO_ARG_CONTAINER(std::list)
82 OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist)
85 #undef OUTPUT_TWO_ARG_CONTAINER
87 #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \
88 template<class T1, class T2, class T3> \
89 inline std::ostream& operator<<(std::ostream& out, \
90 const Sequence<T1, T2, T3>& seq) { \
91 google::PrintSequence(out, seq.begin(), seq.end()); \
95 OUTPUT_THREE_ARG_CONTAINER(std::set)
96 OUTPUT_THREE_ARG_CONTAINER(std::multiset)
98 #undef OUTPUT_THREE_ARG_CONTAINER
100 #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \
101 template<class T1, class T2, class T3, class T4> \
102 inline std::ostream& operator<<(std::ostream& out, \
103 const Sequence<T1, T2, T3, T4>& seq) { \
104 google::PrintSequence(out, seq.begin(), seq.end()); \
108 OUTPUT_FOUR_ARG_CONTAINER(std::map)
109 OUTPUT_FOUR_ARG_CONTAINER(std::multimap)
111 OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set)
112 OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset)
115 #undef OUTPUT_FOUR_ARG_CONTAINER
117 #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \
118 template<class T1, class T2, class T3, class T4, class T5> \
119 inline std::ostream& operator<<(std::ostream& out, \
120 const Sequence<T1, T2, T3, T4, T5>& seq) { \
121 google::PrintSequence(out, seq.begin(), seq.end()); \
126 OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map)
127 OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap)
130 #undef OUTPUT_FIVE_ARG_CONTAINER
132 #endif // UTIL_GTL_STL_LOGGING_INL_H_