File indexing completed on 2026-04-17 07:59:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <memory>
0021 #include <ostream>
0022 #include <string>
0023 #include <type_traits>
0024 #include <utility>
0025
0026 #include "arrow/util/visibility.h"
0027
0028 namespace arrow {
0029
0030 namespace internal {
0031
0032 class ARROW_EXPORT StringStreamWrapper {
0033 public:
0034 StringStreamWrapper();
0035 ~StringStreamWrapper();
0036
0037 std::ostream& stream() { return ostream_; }
0038 std::string str();
0039
0040 protected:
0041 std::unique_ptr<std::ostringstream> sstream_;
0042 std::ostream& ostream_;
0043 };
0044
0045 template <typename... Args>
0046 std::string JoinToString(Args&&... args) {
0047 StringStreamWrapper ss;
0048 (
0049 [&ss](auto&& arg) {
0050
0051 if constexpr (std::is_floating_point_v<std::decay_t<decltype(arg)>>) {
0052 ss.stream() << std::to_string(arg);
0053 } else {
0054 ss.stream() << arg;
0055 }
0056 }(std::forward<Args>(args)),
0057 ...);
0058 return ss.str();
0059 }
0060 }
0061
0062 namespace util {
0063
0064 template <typename T>
0065 class ToStringOstreamable {
0066 public:
0067 ~ToStringOstreamable() {
0068 static_assert(
0069 std::is_same<decltype(std::declval<const T>().ToString()), std::string>::value,
0070 "ToStringOstreamable depends on the method T::ToString() const");
0071 }
0072
0073 private:
0074 const T& cast() const { return static_cast<const T&>(*this); }
0075
0076 friend inline std::ostream& operator<<(std::ostream& os, const ToStringOstreamable& t) {
0077 return os << t.cast().ToString();
0078 }
0079 };
0080
0081 }
0082 }