Giter Club home page Giter Club logo

Comments (5)

whoshuu avatar whoshuu commented on May 17, 2024

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.

whoshuu avatar whoshuu commented on May 17, 2024

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.

vittorioromeo avatar vittorioromeo commented on May 17, 2024

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.

vittorioromeo avatar vittorioromeo commented on May 17, 2024

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.

whoshuu avatar whoshuu commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.