133 template<
typename, SampleOutputTarget>
134 friend class SampleOutput;
136 static constexpr OS& autoStream() {
137 constexpr bool is_cout_type = std::is_same_v< OS, std::ostream >;
138 constexpr bool is_wcout_type = std::is_same_v< OS, std::wostream >;
140 if constexpr ( is_cout_type ) {
142 }
else if constexpr ( is_wcout_type ) {
147 "Default init of ActiveOutput is only allowed for "
148 "ostream or wostream stream types."
153 template<
typename T>
constexpr void ignoreType() {};
155 constexpr bool doWrite(SampleOutputTarget tgt = Target) {
156 return tgt == SAMPLE_ACTIVE_OUTPUT || tgt == SAMPLE_ALWAYS_OUTPUT;
160 constexpr void write(T&& v) {
161 if constexpr ( doWrite() ) {
162 stream << std::forward<T>(v);
168 ignoreType<decltype(stream << std::forward<T>(v))>();
173 constexpr SampleOutput() : stream(autoStream()) { }
174 SampleOutput(
const SampleOutput&) =
default;
175 constexpr SampleOutput(OS& os) : stream(os) { }
188 template<
typename T, SampleOutputTarget Tgt>
190 : stream(other.stream)
195 constexpr auto normal() {
return out(); }
197 constexpr SampleOutput<OS, SAMPLE_TEST_OUTPUT> expected() {
return stream; }
198 constexpr auto expect() {
return expected(); }
200 constexpr SampleOutput<OS, SAMPLE_ALWAYS_OUTPUT> always() {
return stream; }
201 constexpr auto both() {
return always(); }
204 constexpr SampleOutput& operator<< (T&& v) {
205 write(std::forward<T>(v));