pistacheio / pistache

A high-performance REST toolkit written in C++
https://pistacheio.github.io/pistache/
Apache License 2.0
3.17k stars 698 forks source link

Add the ability to use Routes::bind with constant member functions #1127

Closed tyler92 closed 1 year ago

tyler92 commented 1 year ago

There was a compile error with the following scenario:

class MyHttpServer
{
    // ...
    void run()
    {
        using namespace Pistache::Rest;
        Routes::Get(router, "/ping", Routes::bind(&MyHttpServer::requestHandler, this));
    }

    void requestHandler(const Pistache::Rest::Request& request,
                        Pistache::Http::ResponseWriter response) const
    {
        response.send(Pistache::Http::Code::Ok, "OK");
    }

    // ...
};

Compiler output:

main.cpp:38: error: no matching function for call to ‘bind(void (MyHttpServer::*)(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter) const, MyHttpServer*)’
main.cpp: In member function ‘void MyHttpServer::run()’:
main.cpp:38:58: error: no matching function for call to ‘bind(void (MyHttpServer::*)(const Pistache::Rest::Request&, Pistache::Http::ResponseWriter) const, MyHttpServer*)’
   38 |                 Routes::Get(router, "/ping", Routes::bind(&MyHttpServer::requestHandler, this));
      |    
codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 :tada:

Comparison is base (7f6bb27) 78.45% compared to head (675b6f0) 78.49%.

:exclamation: Current head 675b6f0 differs from pull request most recent head fa6e5da. Consider uploading reports for the commit fa6e5da to get more accurate results

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1127 +/- ## ========================================== + Coverage 78.45% 78.49% +0.04% ========================================== Files 53 53 Lines 6879 6892 +13 ========================================== + Hits 5397 5410 +13 Misses 1482 1482 ``` | [Impacted Files](https://codecov.io/gh/pistacheio/pistache/pull/1127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [include/pistache/router.h](https://codecov.io/gh/pistacheio/pistache/pull/1127?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-aW5jbHVkZS9waXN0YWNoZS9yb3V0ZXIuaA==) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

kiplingw commented 1 year ago

@Tachi107, if you're fine with it too, I'll merge.

Tachi107 commented 1 year ago

Thanks for the patch! Looks good to me as well