|
|
|||
File indexing completed on 2026-10-26 09:34:35
0001 //------------------------------- -*- C++ -*- -------------------------------// 0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details 0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0004 //---------------------------------------------------------------------------// 0005 //! \file corecel/io/StreamUtils.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <sstream> 0010 #include <string> 0011 #include <type_traits> 0012 #include <utility> 0013 0014 namespace celeritas 0015 { 0016 //---------------------------------------------------------------------------// 0017 /*! 0018 * Write the operand to the contained stream. 0019 */ 0020 struct GenericToStream 0021 { 0022 std::ostream& os; 0023 0024 template<class T> 0025 void operator()(T&& obj) const 0026 { 0027 this->os << std::forward<T>(obj); 0028 } 0029 }; 0030 0031 //---------------------------------------------------------------------------// 0032 /*! 0033 * Return as a string any object that has an ostream operator. 0034 */ 0035 template<class T> 0036 inline std::string stream_to_string(T const& item) 0037 { 0038 std::ostringstream os; 0039 os << item; 0040 return std::move(os).str(); 0041 } 0042 0043 //---------------------------------------------------------------------------// 0044 /*! 0045 * Write a `to_cstring`-enabled enum to a stream. 0046 */ 0047 template<class T> 0048 auto operator<<(std::ostream& os, T value) -> std::enable_if_t< 0049 std::is_enum_v<T> && std::is_same_v<decltype(to_cstring(value)), char const*>, 0050 std::ostream&> 0051 { 0052 return os << to_cstring(value); 0053 } 0054 0055 //---------------------------------------------------------------------------// 0056 } // namespace celeritas
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|