Comments (5)
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 std::string
members. Using a forwarding reference template parameter will copy lvalues (which is safe and correct) and move rvalues (which is efficient). This is similar to how the Session
API has different methods for lvalue payload types and rvalue payload types.
from cpr.
Places where this optimization can be done:
https://github.com/whoshuu/cpr/blob/c39b567a2cba6c69ab1ee35b46c9ab214f763520/include/auth.h#L10
https://github.com/whoshuu/cpr/blob/c39b567a2cba6c69ab1ee35b46c9ab214f763520/include/digest.h#L12
https://github.com/whoshuu/cpr/blob/c39b567a2cba6c69ab1ee35b46c9ab214f763520/include/parameters.h#L11
https://github.com/whoshuu/cpr/blob/c39b567a2cba6c69ab1ee35b46c9ab214f763520/include/payload.h#L21
https://github.com/whoshuu/cpr/blob/c39b567a2cba6c69ab1ee35b46c9ab214f763520/include/response.h#L12-L18
from cpr.
Not sure what the issue is with forwarding c-style strings (as you said in e8e15c7) - could you elaborate?
I used perfect forwarding with std::string
lvalues/rvalues and const char*
and it seems to handle all the cases correctly. Coliru live example
from cpr.
Also, I really think having a CPR_FWD(...)
macro would make the code much easier to read (and much less error prone). Perfectly forwarding arguments is one of the places where I really think macros can shine.
#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.
from cpr.
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.
from cpr.
Related Issues (20)
- SSL certificate pinning HOT 3
- Question: Is `WriteCallback` asynchronous? HOT 1
- cpr::Buffer data lifetime question HOT 4
- constexpr methods for some string-like types HOT 1
- Add support for identifying whether a Session is currently busy or not HOT 1
- zlib ignores --prefix/CMAKE_INSTALL_PREFIX when using cpr as external dependency HOT 2
- Link error when creating a cpr::Header, segment fault when making cpr::Get request HOT 1
- Question: Does cpr support ftp? HOT 1
- Confused on something HOT 3
- Call of overloaded ‘SetOption(std::__cxx11::basic_string<char>)’ is ambiguous HOT 1
- 13.2.0 gcc compiler, vcpkg and cpr: compilation error. HOT 7
- cpr::ThreadPool high CPU usage when Paused HOT 4
- Interceptors are single-shot
- async callback with highest performance?
- Thread Pool Deadlock While Task Wait HOT 1
- Possible race condition in singleton class GetInstance() function HOT 1
- cpr use system default curl? HOT 8
- parallelized http get/post request with trying best to reuse connections? HOT 1
- Multiple Invocations of cpr::MultiPerform Segfault
- cpr/cpr.h: No such file or directory HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpr.