Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:05:44

0001 // Copyright (c) ONNX Project Contributors
0002 //
0003 // SPDX-License-Identifier: Apache-2.0
0004 
0005 #pragma once
0006 
0007 #include <sstream>
0008 #include <string>
0009 
0010 namespace ONNX_NAMESPACE {
0011 
0012 #if defined(__ANDROID__)
0013 template <typename T>
0014 std::string to_string(T value) {
0015   std::ostringstream os;
0016   os << value;
0017   return os.str();
0018 }
0019 
0020 inline int stoi(const std::string& str) {
0021   std::stringstream ss;
0022   int n = 0;
0023   ss << str;
0024   ss >> n;
0025   return n;
0026 }
0027 
0028 #else
0029 using std::stoi;
0030 using std::to_string;
0031 #endif // defined(__ANDROID__)
0032 
0033 inline void MakeStringInternal(std::stringstream& /*ss*/) {}
0034 
0035 template <typename T>
0036 inline void MakeStringInternal(std::stringstream& ss, const T& t) {
0037   ss << t;
0038 }
0039 
0040 template <typename T, typename... Args>
0041 inline void MakeStringInternal(std::stringstream& ss, const T& t, const Args&... args) {
0042   MakeStringInternal(ss, t);
0043   MakeStringInternal(ss, args...);
0044 }
0045 
0046 template <typename... Args>
0047 std::string MakeString(const Args&... args) {
0048   std::stringstream ss;
0049   MakeStringInternal(ss, args...);
0050   return std::string(ss.str());
0051 }
0052 
0053 // Specializations for already-a-string types.
0054 template <>
0055 inline std::string MakeString(const std::string& str) {
0056   return str;
0057 }
0058 inline std::string MakeString(const char* c_str) {
0059   return std::string(c_str);
0060 }
0061 } // namespace ONNX_NAMESPACE