On Wed, Oct 15, 2014 at 7:38 PM, Indiana
The only way to prevent binding to temporaries in C++98 is to take arguments by non-const (lvalue) reference, but if write_all() does that then the "as lvalue" code above won't work.
So my options come down to this: 1) Declare the library C++11-or-better-only. That can be enforced by ensuring that BOOST_NO_CXX11_RVALUE_REFERENCES is not defined, and issuing an error message otherwise. 2) Allow the library to be used in C++98 code, with a warning - either in documentation or, less than ideally, as a diagnostic - about temporaries. Note that there is no way to detect or diagnose if the warning is ignored, deliberately or accidentally, so things that are perfectly legal in C++11 mode can silently introduce undefined behaviour in C++98 mode.
A third potential option would be to restrict the API based on BOOST_NO_CXX11_RVALUE_REFERENCES. That is, when that macro is set, make write_all() accept non-const reference. This could potentially allow *some* use of the library even with C++03 code -- say, with a local vector -- without loss of safety.
I don't think it's a worthwhile to introduce potentially undetectable bugs. Better to say "if you can't use it safely, you can't use it"
I agree with the above. I simply suggest that even in C++03, you could potentially support a safe subset of desirable use cases.