130 template<
typename, SampleOutputTarget>
131 friend class SampleOutput;
133 static constexpr OS& autoStream() {
134 constexpr bool is_cout_type = std::is_same_v< OS, std::ostream >;
135 constexpr bool is_wcout_type = std::is_same_v< OS, std::wostream >;
137 if constexpr ( is_cout_type ) {
139 }
else if constexpr ( is_wcout_type ) {
144 "Default init of ActiveOutput is only allowed for "
145 "ostream or wostream stream types."
150 template<
typename T>
constexpr void ignoreType() {};
152 constexpr bool doWrite(SampleOutputTarget tgt = Target) {
153 return tgt == SAMPLE_ACTIVE_OUTPUT || tgt == SAMPLE_ALWAYS_OUTPUT;
157 constexpr void write(T&& v) {
158 if constexpr ( doWrite() ) {
159 stream << std::forward<T>(v);
165 ignoreType<decltype(stream << std::forward<T>(v))>();
170 constexpr SampleOutput() : stream(autoStream()) { }
171 SampleOutput(
const SampleOutput&) =
default;
172 constexpr SampleOutput(OS& os) : stream(os) { }
182 template<
typename T, SampleOutputTarget Tgt>
184 : stream(other.stream)
189 constexpr auto normal() {
return out(); }
191 constexpr SampleOutput<OS, SAMPLE_TEST_OUTPUT> expected() {
return stream; }
192 constexpr auto expect() {
return expected(); }
194 constexpr SampleOutput<OS, SAMPLE_ALWAYS_OUTPUT> always() {
return stream; }
195 constexpr auto both() {
return always(); }
198 constexpr SampleOutput& operator<< (T&& v) {
199 write(std::forward<T>(v));