None
NO
Reader Q&A: What’s the best way to pass an istream parameter?
['Herb Sutter', 'View All Posts Herb Sutter', 'Herb Sutter Is An Author', 'Speaker', 'A Technical Fellow At Citadel Securities. He Serves As Chair Of The Standard C', 'Foundation', 'Its Conference Cppcon', 'Served As Chair Of The Iso C', 'Standards Committee To']
Sutter’s Mill
Testing code may create a temporary [rvalue] stream, and it would be nice to not have to make it a named variable [lvalue], but this doesn’t work with just the above function: add_from_stream( std::stringstream(some_string_data) ); // ERROR, can't pass rvalue to A's parameter So I want to add an overload that takes an rvalue reference, like this: void add_from_stream( std::istream &&s ); // B // now the above call would work and call B // Option 3(a): Single function, takes lvalue and rvalue streams template <typename S> void add_from_stream( S&& s ) requires std::is_same_v<S, std::istream> { // do work + remember to use s as "std::forward<S>(s)" } // Option 3(b): Single function, takes lvalue and rvalue streams template <typename S> void add_from_stream( S&& s ) requires…