• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*!
18  * \file op_common_util.h
19  * \brief common util for op, in this file only original type or class in C++ allowed
20  */
21 
22 #ifndef CUSTOMIZE_OP_PROTO_UTIL_OP_COMMON_UTIL_H_
23 #define CUSTOMIZE_OP_PROTO_UTIL_OP_COMMON_UTIL_H_
24 
25 #include <set>
26 #include <string>
27 #include <vector>
28 #include <iostream>
29 #include <sstream>
30 
31 template <typename T1, typename T2>
32 std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &values) {
33   os << "[" << values.first << ", " << values.second << "]";
34   return os;
35 }
36 
37 template <typename T>
38 std::ostream &operator<<(std::ostream &os, const std::vector<T> &values) {
39   os << "[";
40   for (const auto &item : values) {
41     os << item << ", ";
42   }
43   os << "]";
44   return os;
45 }
46 
47 namespace ops {
48 template <typename T>
to_string(const std::vector<T> & items)49 std::string to_string(const std::vector<T> &items) {
50   std::ostringstream oss;
51   oss << "[";
52   for (const auto &item : items) {
53     oss << item << ", ";
54   }
55   oss << "]";
56   return oss.str();
57 }
58 
59 template <typename T>
to_string(const std::set<T> & items)60 std::string to_string(const std::set<T> &items) {
61   std::ostringstream oss;
62   oss << "[";
63   for (const auto &item : items) {
64     oss << item << ", ";
65   }
66   oss << "]";
67   return oss.str();
68 }
69 }  // namespace ops
70 
71 #endif  // CUSTOMIZE_OP_PROTO_UTIL_OP_COMMON_UTIL_H_
72