/root/doris/be/src/util/to_string.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | |
19 | | #pragma once |
20 | | |
21 | | #include <fmt/format.h> |
22 | | |
23 | | #include <map> |
24 | | #include <set> |
25 | | #include <string> |
26 | | #include <vector> |
27 | | |
28 | | namespace doris { |
29 | | template <typename T> |
30 | 0 | std::string to_string(const T& t) { |
31 | 0 | return fmt::format("{}", t); |
32 | 0 | } |
33 | | |
34 | | template <typename K, typename V> |
35 | | std::string to_string(const std::map<K, V>& m); |
36 | | |
37 | | template <typename T> |
38 | | std::string to_string(const std::set<T>& s); |
39 | | |
40 | | template <typename T> |
41 | | std::string to_string(const std::vector<T>& t); |
42 | | |
43 | | template <typename K, typename V> |
44 | | std::string to_string(const typename std::pair<K, V>& v) { |
45 | | return fmt::format("{}: {}", to_string(v.first), to_string(v.second)); |
46 | | } |
47 | | |
48 | | template <typename T> |
49 | 0 | std::string to_string(const T& beg, const T& end) { |
50 | 0 | std::string out; |
51 | 0 | for (T it = beg; it != end; ++it) { |
52 | 0 | if (it != beg) out += ", "; |
53 | 0 | out += to_string(*it); |
54 | 0 | } |
55 | 0 | return out; |
56 | 0 | } |
57 | | |
58 | | template <typename T> |
59 | 0 | std::string to_string(const std::vector<T>& t) { |
60 | 0 | return "[" + to_string(t.begin(), t.end()) + "]"; |
61 | 0 | } |
62 | | |
63 | | template <typename K, typename V> |
64 | | std::string to_string(const std::map<K, V>& m) { |
65 | | return "{" + to_string(m.begin(), m.end()) + "}"; |
66 | | } |
67 | | |
68 | | template <typename T> |
69 | | std::string to_string(const std::set<T>& s) { |
70 | | return "{" + to_string(s.begin(), s.end()) + "}"; |
71 | | } |
72 | | |
73 | | } // namespace doris |