File indexing completed on 2025-09-18 09:09:39
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <iosfwd>
0010 #include <iterator>
0011 #include <sstream>
0012 #include <string>
0013
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018
0019
0020
0021
0022 struct StreamValue
0023 {
0024 template<class T>
0025 void operator()(std::ostream& os, T&& v)
0026 {
0027 os << std::forward<T>(v);
0028 }
0029 };
0030
0031
0032
0033
0034
0035 template<class UnaryOp>
0036 struct UnaryToStream
0037 {
0038 UnaryOp op;
0039
0040 template<class T>
0041 void operator()(std::ostream& os, T&& v)
0042 {
0043 os << op(std::forward<T>(v));
0044 }
0045 };
0046
0047
0048
0049
0050
0051
0052
0053
0054 template<class InputIterator, class Conjunction, class StreamOp = StreamValue>
0055 struct Joined
0056 {
0057 InputIterator first;
0058 InputIterator last;
0059 Conjunction conjunction;
0060 StreamOp op;
0061 };
0062
0063
0064 template<class I, class C, class S>
0065 std::ostream& operator<<(std::ostream& os, Joined<I, C, S> const& j)
0066 {
0067 auto iter = j.first;
0068 auto op = j.op;
0069
0070
0071 if (iter != j.last)
0072 {
0073 op(os, *iter++);
0074 }
0075
0076
0077 while (iter != j.last)
0078 {
0079 os << j.conjunction;
0080 op(os, *iter++);
0081 }
0082
0083 return os;
0084 }
0085
0086
0087 template<class I, class C, class S>
0088 std::string to_string(Joined<I, C, S> const& j)
0089 {
0090 std::ostringstream os;
0091 os << j;
0092 return os.str();
0093 }
0094
0095
0096 }
0097 }