-
Notifications
You must be signed in to change notification settings - Fork 902
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
Avoid unnecessary runtime overhead due to std::string
"sink" parameters
#50
Comments
Sounds good to me. Thanks for catching this! To clarify for documentation purposes, the issue here is that the sink parameters will do a copy into each member parameter for the objects that have |
Since c-style strings can't be moved from, and since the forwarding references are greedy, a non-template constructor is necessary to consume c-style string arguments References #50
Not sure what the issue is with forwarding c-style strings (as you said in e8e15c7) - could you elaborate? I used perfect forwarding with |
Also, I really think having a #define CPR_FWD(...) \
::std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__) Note that: template<typename T>
void something(T&& x)
{
// All these are completely equivalent:
something_else(std::forward<T>(x));
something_else(std::forward<decltype(x)>(x));
something_else(CPR_FWD(x));
}
// But the macro version is the one with least code repetition.
// And it's also the shortest one. |
You're right about the c-style strings. I must've written the forwarding reference constructor wrong the first time and thought the issue was that I was passing c-style strings in the tests when it wouldn't build. This'll be fixed. |
Most of the constructors in cpr take
std::string
parameters byconst std::string&
.Digest(const std::string& username, const std::string& password);
This is not the most efficient way of dealing with "sink" parameters.
Refer to isocpp/CppCoreGuidelines's parameter passing diagram.
My suggestion is using perfect-forwarding, to always make sure sink
std::string
members are initialized as efficiently as possible. Example:The text was updated successfully, but these errors were encountered: