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