-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent behavior of operator<< for known types #495
Conversation
Thanks a lot for the PR!
This is a bit unfortunate. I'll try to come up with an alternative solution that doesn't break existing code. If not then I guess we'll have to go with the backward-incompatible one. |
The (templated) operator<< defined in ostream.h currently prevents efficient handling of some basic types in BasicWriter. E.g.: MemoryWriter w; w << std::string("hello"); calls this operator (if visible). This will unneccessarily construct a std::ostream object using a FormatBuf as its streambuf and insert the string into the std::ostream object. (The same is true for float and some other built-in types.) The write_str method in BasicWriter basically does the same using a cheap memcpy. Fix this performance problem by providing additional overloads of operator<<.
For MSVC this was a better than the rvalue->lvalue conversion
Should be backwards compatible now. Turned out the only difficulty were some inconsistences between MSVC and other compilers. If this gets accepted, the commits should probably be squashed... :-) |
Thanks for working on this. Unfortunately there is still an issue with implicit conversions, so I decided to revert (dcfd40a) the commit that introduced this problem in the first place because it not only interferes with known types but is also not compatible with older compilers which is one of the goals of this library. |
Yes, thats clearly the easiest solution. Thanks! |
Revert fmtlib#456 because it causes issues for known types (fmtlib#495) and is not C++98-compatible.
Consistent behavior of operator<< for known types.
The (templated) operator<< defined in ostream.h currently prevents efficient
handling of known types in BasicWriter. E.g.:
calls this operator (if visible). This will unneccessarily construct a
std::ostream object using a FormatBuf as its streambuf and insert the string
into the std::ostream object. (The same is true for
float
and some otherbuilt-in types.) The write_str method in BasicWriter basically does the same
using a cheap memcpy.
This patch attempts to fix this performance problem.
But this patch might also break some code, e.g.:
only works in C++11 now. Note that
didn't work before, but should work now.
I haven't found another solution which works and is still safe (neither in C++03
nor in C++11), so I'm just posting this here for discussion...