Debian Codegraph @

yo/advancedtemplates/concepts/examples/invocable.cc

raw
1 #include <concepts>
2 #include <iostream>
3 #include <utility>
4 #include <string>
5
6 //invocable
7 template <typename Function, typename ...Params>
8 void fun(Function &&fun, Params &&...params)
9 requires std::invocable<Function, Params ...>
10 {
11 fun(std::forward<Params>(params)...);
12 }
13
14 void hello(int value, char const *txt, std::string const &str)
15 {
16 std::cout << value << ' ' << txt << ' ' << str << '\n';
17 }
18
19 int main()
20 {
21 fun(hello, 1, "text", "string"); // promotions are still OK
22 // fun(hello, 1); // WC: not invocable
23 }
24 //=