/** * Copyright 2019 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef MINDSPORE_CCSRC_UTILS_OVERLOAD_H_ #define MINDSPORE_CCSRC_UTILS_OVERLOAD_H_ #include #include #include #include #include #include #include #include #include namespace mindspore { template std::ostream &operator<<(std::ostream &out, const std::vector &v) { out << "[const vector]["; size_t last = v.size() - 1; for (size_t i = 0; i < v.size(); ++i) { out << v[i]; if (i != last) out << ", "; } out << "]"; return out; } template std::ostream &operator<<(std::ostream &os, const std::list &vec) { bool begin = true; os << "[const list]["; for (auto &item : vec) { if (!begin) { os << ", "; } else { begin = false; } os << item; } os << "]"; return os; } template std::ostream &operator<<(std::ostream &os, const std::initializer_list &vec) { bool begin = true; os << "["; for (auto &item : vec) { if (!begin) { os << ", "; } else { begin = false; } os << item; } os << "]"; return os; } template bool operator==(const std::initializer_list &lhs, const std::initializer_list &rhs) { if (lhs.size() != rhs.size()) { return false; } auto lit = lhs.begin(); auto rit = rhs.begin(); while (lit != lhs.end()) { if (!(*lit == *rit)) { return false; } lit++; rit++; } return true; } template std::ostream &operator<<(std::ostream &os, const std::pair &pair) { os << "[const pair]"; return os; } template std::ostream &operator<<(std::ostream &os, const std::unordered_map &map) { os << "[const unordered_map]"; return os; } template std::ostream &operator<<(std::ostream &os, const std::map &map) { os << "[const map]"; return os; } template std::string ToString(const std::vector &vec) { std::ostringstream buffer; buffer << vec; return buffer.str(); } template std::string ToString(const std::unordered_map &map) { std::ostringstream buffer; buffer << map; return buffer.str(); } template std::string ToString(const std::map &map) { std::ostringstream buffer; buffer << map; return buffer.str(); } } // namespace mindspore #endif // MINDSPORE_CCSRC_UTILS_OVERLOAD_H_