Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame^] | 1 | // This file is automatically generated from src/glog/stl_logging.h.in |
| 2 | // using src/windows/preprocess.sh. |
| 3 | // DO NOT EDIT! |
| 4 | |
| 5 | // Copyright (c) 2003, Google Inc. |
| 6 | // All rights reserved. |
| 7 | // |
| 8 | // Redistribution and use in source and binary forms, with or without |
| 9 | // modification, are permitted provided that the following conditions are |
| 10 | // met: |
| 11 | // |
| 12 | // * Redistributions of source code must retain the above copyright |
| 13 | // notice, this list of conditions and the following disclaimer. |
| 14 | // * Redistributions in binary form must reproduce the above |
| 15 | // copyright notice, this list of conditions and the following disclaimer |
| 16 | // in the documentation and/or other materials provided with the |
| 17 | // distribution. |
| 18 | // * Neither the name of Google Inc. nor the names of its |
| 19 | // contributors may be used to endorse or promote products derived from |
| 20 | // this software without specific prior written permission. |
| 21 | // |
| 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | // |
| 34 | // Stream output operators for STL containers; to be used for logging *only*. |
| 35 | // Inclusion of this file lets you do: |
| 36 | // |
| 37 | // list<string> x; |
| 38 | // LOG(INFO) << "data: " << x; |
| 39 | // vector<int> v1, v2; |
| 40 | // CHECK_EQ(v1, v2); |
| 41 | // |
| 42 | // If you want to use this header file with hash_compare maps or slist, you |
| 43 | // need to define macros before including this file: |
| 44 | // |
| 45 | // - GLOG_STL_LOGGING_FOR_UNORDERED - <unordered_map> and <unordered_set> |
| 46 | // - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - <tr1/unordered_(map|set)> |
| 47 | // - GLOG_STL_LOGGING_FOR_EXT_HASH - <ext/hash_(map|set)> |
| 48 | // - GLOG_STL_LOGGING_FOR_EXT_SLIST - <ext/slist> |
| 49 | // |
| 50 | |
| 51 | #ifndef UTIL_GTL_STL_LOGGING_INL_H_ |
| 52 | #define UTIL_GTL_STL_LOGGING_INL_H_ |
| 53 | |
| 54 | #if !1 |
| 55 | # error We do not support stl_logging for this compiler |
| 56 | #endif |
| 57 | |
| 58 | #include <deque> |
| 59 | #include <list> |
| 60 | #include <map> |
| 61 | #include <ostream> |
| 62 | #include <set> |
| 63 | #include <utility> |
| 64 | #include <vector> |
| 65 | |
| 66 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED |
| 67 | # include <unordered_map> |
| 68 | # include <unordered_set> |
| 69 | #endif |
| 70 | |
| 71 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED |
| 72 | # include <tr1/unordered_map> |
| 73 | # include <tr1/unordered_set> |
| 74 | #endif |
| 75 | |
| 76 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH |
| 77 | # include <ext/hash_set> |
| 78 | # include <ext/hash_map> |
| 79 | #endif |
| 80 | #ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST |
| 81 | # include <ext/slist> |
| 82 | #endif |
| 83 | |
| 84 | // Forward declare these two, and define them after all the container streams |
| 85 | // operators so that we can recurse from pair -> container -> container -> pair |
| 86 | // properly. |
| 87 | template<class First, class Second> |
| 88 | std::ostream& operator<<(std::ostream& out, const std::pair<First, Second>& p); |
| 89 | |
| 90 | namespace google { |
| 91 | |
| 92 | template<class Iter> |
| 93 | void PrintSequence(std::ostream& out, Iter begin, Iter end); |
| 94 | |
| 95 | } |
| 96 | |
| 97 | #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \ |
| 98 | template<class T1, class T2> \ |
| 99 | inline std::ostream& operator<<(std::ostream& out, \ |
| 100 | const Sequence<T1, T2>& seq) { \ |
| 101 | google::PrintSequence(out, seq.begin(), seq.end()); \ |
| 102 | return out; \ |
| 103 | } |
| 104 | |
| 105 | OUTPUT_TWO_ARG_CONTAINER(std::vector) |
| 106 | OUTPUT_TWO_ARG_CONTAINER(std::deque) |
| 107 | OUTPUT_TWO_ARG_CONTAINER(std::list) |
| 108 | #ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST |
| 109 | OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist) |
| 110 | #endif |
| 111 | |
| 112 | #undef OUTPUT_TWO_ARG_CONTAINER |
| 113 | |
| 114 | #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \ |
| 115 | template<class T1, class T2, class T3> \ |
| 116 | inline std::ostream& operator<<(std::ostream& out, \ |
| 117 | const Sequence<T1, T2, T3>& seq) { \ |
| 118 | google::PrintSequence(out, seq.begin(), seq.end()); \ |
| 119 | return out; \ |
| 120 | } |
| 121 | |
| 122 | OUTPUT_THREE_ARG_CONTAINER(std::set) |
| 123 | OUTPUT_THREE_ARG_CONTAINER(std::multiset) |
| 124 | |
| 125 | #undef OUTPUT_THREE_ARG_CONTAINER |
| 126 | |
| 127 | #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \ |
| 128 | template<class T1, class T2, class T3, class T4> \ |
| 129 | inline std::ostream& operator<<(std::ostream& out, \ |
| 130 | const Sequence<T1, T2, T3, T4>& seq) { \ |
| 131 | google::PrintSequence(out, seq.begin(), seq.end()); \ |
| 132 | return out; \ |
| 133 | } |
| 134 | |
| 135 | OUTPUT_FOUR_ARG_CONTAINER(std::map) |
| 136 | OUTPUT_FOUR_ARG_CONTAINER(std::multimap) |
| 137 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED |
| 138 | OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set) |
| 139 | OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset) |
| 140 | #endif |
| 141 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED |
| 142 | OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_set) |
| 143 | OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_multiset) |
| 144 | #endif |
| 145 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH |
| 146 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set) |
| 147 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset) |
| 148 | #endif |
| 149 | |
| 150 | #undef OUTPUT_FOUR_ARG_CONTAINER |
| 151 | |
| 152 | #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \ |
| 153 | template<class T1, class T2, class T3, class T4, class T5> \ |
| 154 | inline std::ostream& operator<<(std::ostream& out, \ |
| 155 | const Sequence<T1, T2, T3, T4, T5>& seq) { \ |
| 156 | google::PrintSequence(out, seq.begin(), seq.end()); \ |
| 157 | return out; \ |
| 158 | } |
| 159 | |
| 160 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED |
| 161 | OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) |
| 162 | OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) |
| 163 | #endif |
| 164 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED |
| 165 | OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_map) |
| 166 | OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_multimap) |
| 167 | #endif |
| 168 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH |
| 169 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map) |
| 170 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap) |
| 171 | #endif |
| 172 | |
| 173 | #undef OUTPUT_FIVE_ARG_CONTAINER |
| 174 | |
| 175 | template<class First, class Second> |
| 176 | inline std::ostream& operator<<(std::ostream& out, |
| 177 | const std::pair<First, Second>& p) { |
| 178 | out << '(' << p.first << ", " << p.second << ')'; |
| 179 | return out; |
| 180 | } |
| 181 | |
| 182 | namespace google { |
| 183 | |
| 184 | template<class Iter> |
| 185 | inline void PrintSequence(std::ostream& out, Iter begin, Iter end) { |
| 186 | // Output at most 100 elements -- appropriate if used for logging. |
| 187 | for (int i = 0; begin != end && i < 100; ++i, ++begin) { |
| 188 | if (i > 0) out << ' '; |
| 189 | out << *begin; |
| 190 | } |
| 191 | if (begin != end) { |
| 192 | out << " ..."; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | } |
| 197 | |
| 198 | // Note that this is technically undefined behavior! We are adding things into |
| 199 | // the std namespace for a reason though -- we are providing new operations on |
| 200 | // types which are themselves defined with this namespace. Without this, these |
| 201 | // operator overloads cannot be found via ADL. If these definitions are not |
| 202 | // found via ADL, they must be #included before they're used, which requires |
| 203 | // this header to be included before apparently independent other headers. |
| 204 | // |
| 205 | // For example, base/logging.h defines various template functions to implement |
| 206 | // CHECK_EQ(x, y) and stream x and y into the log in the event the check fails. |
| 207 | // It does so via the function template MakeCheckOpValueString: |
| 208 | // template<class T> |
| 209 | // void MakeCheckOpValueString(strstream* ss, const T& v) { |
| 210 | // (*ss) << v; |
| 211 | // } |
| 212 | // Because 'glog/logging.h' is included before 'glog/stl_logging.h', |
| 213 | // subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only |
| 214 | // find these operator definitions via ADL. |
| 215 | // |
| 216 | // Even this solution has problems -- it may pull unintended operators into the |
| 217 | // namespace as well, allowing them to also be found via ADL, and creating code |
| 218 | // that only works with a particular order of includes. Long term, we need to |
| 219 | // move all of the *definitions* into namespace std, bet we need to ensure no |
| 220 | // one references them first. This lets us take that step. We cannot define them |
| 221 | // in both because that would create ambiguous overloads when both are found. |
| 222 | namespace std { using ::operator<<; } |
| 223 | |
| 224 | #endif // UTIL_GTL_STL_LOGGING_INL_H_ |