Answering my own question for completeness and future reference.
The goal was to find a workaround for the gcc error (<5), where it std::istringstreamdoes not provide a ctor move that will work in cases where I want to return an un-copyable and (bugly-) immutable stream.
As mentioned in the comments, I can actually change my function signature (at least to gcc <5) to return a proxy object that allows you to copy or move without changing the API for the code used for new / other compilers.
, , - std::istringstream, API, copy-ctor, std::istringstream - . -.
.
:
#if !defined(__GNUC__) || (__GNUC__ >= 5)
using string_stream = std::istringstream;
#else
class stringstream_proxy
{
public:
stringstream_proxy() = default;
stringstream_proxy(std::string const& value) :
stream_(value)
{}
stringstream_proxy(const stringstream_proxy& other) :
stream_(other.stream_.str())
{
stream_.setstate(other.stream_.rdstate());
}
void setstate(std::ios_base::iostate state) { stream_.setstate(state); }
template<typename T>
stringstream_proxy& operator >> (T& thing)
{
stream_ >> thing;
return *this;
}
std::string str() const { return stream_.str(); }
std::stringbuf* rdbuf() const { return stream_.rdbuf(); }
operator bool() const { return !!stream_; }
~stringstream_proxy() = default;
private:
std::istringstream stream_;
};
using string_stream = stringstream_proxy;
#endif