-
Notifications
You must be signed in to change notification settings - Fork 4.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
Switch to vformat_to #2346
Switch to vformat_to #2346
Conversation
Drive-by: reduce the amount of occurences of #ifdef SPDLOG_USE_STD_FORMAT
That’ s great. Thanks. Makes everything much cleaner. |
I had only included that in there for to_string_view, which isn't really needed to begin with, so I went and removed that include from logger.h to return to manually building the string_view_t |
Returning with std::move is problematic since it prohibits copy elision optimization and compiler is allowed to move anyway (see https://stackoverflow.com/questions/17473753/c11-return-value-optimization-or-move). So I think your original version in this pr (just return by value, no references or moves) is probably the best after all. The compiler would optimize this easily anyway and the code is simplest. sorry for the confusion. |
Calling Until P1825R0, returning a rvalue reference does not move by default - we need to explicitly call std::move (this is because rvalue references are lvalues, thanks C++). This can be easily tested by trying to compile the following with GCC in C++17 mode or older (Clang backported P1825R0 to older standards). It won't compile: std::unique_ptr<int> test(std::unique_ptr<int> &&ptr)
{
return ptr;
} Changing the return to use All of the above is also confirmed by looking at the assembly output of when using different to_string methods:
So the "most optimal" solution is to use |
This all leads me to the think that ifdef should be used. Possibly by defining some macro like SPDLOG_BUF_TO_STRING(buf) |
Good idea that I didn't think of - done. |
Merged. Thanks @sylveon |
Drive-by: reduce the amount of occurences of
#ifdef SPDLOG_USE_STD_FORMAT