Skip to content
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

Add template keyword to CROW_MIDDLEWARES macro #369

Closed
The-EDev opened this issue Mar 21, 2022 · 2 comments
Closed

Add template keyword to CROW_MIDDLEWARES macro #369

The-EDev opened this issue Mar 21, 2022 · 2 comments
Labels
feature Code based project improvement

Comments

@The-EDev
Copy link
Member

As mentioned in #365, Allows for app.route() to use template arguments. Though should make sure nothing is being messed up by that addition.

@The-EDev
Copy link
Member Author

@dranikpg What do you think about this?

@dranikpg
Copy link
Member

dranikpg commented Jul 23, 2022

Oh crap, I totally forgot about this issue 😰 (#365 (comment)).

Giving the compiler a hint that the following function is a template function should theoretically not break anything. This is a good explanation where the template keyword should(can) be used.

The problem however is a bit more complex. Lets examine the following example:

template<typename App>
void run() {
    App app;
    CROW_ROUTE(app, "/secret")
      .CROW_MIDDLEWARES(app, SecretContentGuard)([]() {
          return "";
      });
    app.port(18080).run();
}

We need to make 3 changes to make this work:

#define CROW_ROUTE(app, url) app.template route<crow::black_magic::get_parameter_tag(url)>(url)
#define CROW_MIDDLEWARES(app, ...) template middlewares<typename std::remove_reference<decltype(app)>::type, __VA_ARGS__>()

I added two templates and one typename. Again, those changes should theoretically not break anything:

The syntax allows typename only before qualified names

std::remove_reference<decltype(app)>::type is a qualified name in any case, so typename is valid.

route() and middlewares() are template functions in any case, so template is valid.

Not sure yet about the websockets. I haven't used them much, so I don't have a lot of examples to quickly test on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Code based project improvement
Projects
None yet
Development

No branches or pull requests

2 participants