Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:00:10

0001 /**
0002  * Copyright (c) 2017-present, Facebook, Inc.
0003  * All rights reserved.
0004  *
0005  * This source code is licensed under the BSD-style license found in the
0006  * LICENSE file in the root directory of this source tree.
0007  */
0008 
0009 #pragma once
0010 
0011 #include <sstream>
0012 #include <vector>
0013 
0014 namespace gloo {
0015 
0016 inline void MakeStringInternal(std::stringstream& /*ss*/) {}
0017 
0018 template <typename T>
0019 inline void MakeStringInternal(std::stringstream& ss, const T& t) {
0020   ss << t;
0021 }
0022 
0023 template <>
0024 inline void MakeStringInternal(
0025     std::stringstream& ss,
0026     const std::stringstream& t) {
0027   ss << t.str();
0028 }
0029 
0030 template <typename T, typename... Args>
0031 inline void
0032 MakeStringInternal(std::stringstream& ss, const T& t, const Args&... args) {
0033   MakeStringInternal(ss, t);
0034   MakeStringInternal(ss, args...);
0035 }
0036 
0037 template <typename... Args>
0038 std::string MakeString(const Args&... args) {
0039   std::stringstream ss;
0040   MakeStringInternal(ss, args...);
0041   return std::string(ss.str());
0042 }
0043 
0044 template <typename T>
0045 std::string MakeString(const std::vector<T>& v, const std::string& delim=" ") {
0046   std::stringstream ss;
0047   for (auto it = v.begin(); it < v.end(); it++) {
0048     if (it != v.begin()) {
0049       MakeStringInternal(ss, delim);
0050     }
0051     MakeStringInternal(ss, *it);
0052   }
0053   return std::string(ss.str());
0054 }
0055 
0056 // Specializations for already-a-string types.
0057 template <>
0058 inline std::string MakeString(const std::string& str) {
0059   return str;
0060 }
0061 inline std::string MakeString(const char* cstr) {
0062   return std::string(cstr);
0063 }
0064 
0065 } // namespace gloo