Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- template< typename ...types >
- auto
- make_caller(types &&... _values)
- {
- return [=] (auto && callee) mutable -> decltype(auto) { return static_cast< decltype(callee) >(callee)(std::forward< types >(_values)...); };
- }
- // main.cpp
- #include <iostream>
- #include <cstdlib>
- #define PRETTY_PRINT() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
- struct A
- {
- template< typename ...types >
- void
- operator () (types...) const &
- {
- PRETTY_PRINT();
- }
- template< typename ...types >
- void
- operator () (types...) &&
- {
- PRETTY_PRINT();
- }
- };
- void
- f(int, float, double, long double)
- {
- PRETTY_PRINT();
- }
- struct B
- {
- template< typename type >
- void
- operator () (type const &) const
- {
- PRETTY_PRINT();
- }
- template< typename type >
- void
- operator () (type &&) const
- {
- PRETTY_PRINT();
- }
- };
- int
- main()
- {
- auto caller = make_caller(1, 1.0f, 1.0, 1.0L);
- caller(A{});
- A const a{};
- caller(a);
- caller(f);
- caller(&f);
- make_caller(int{})(B{});
- int const i{};
- make_caller(i)(B{});
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment