Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:59:39

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License. template <typename T>
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         // Avoid losing precision when printing floating point numbers
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 }  // namespace internal
0061 
0062 namespace util {
0063 /// CRTP helper for declaring string representation. Defines operator<<
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 }  // namespace util
0082 }  // namespace arrow