Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void a(int) {
- // do something
- }
- void b(int) {
- // something else
- }
- void function1() {
- a(123);
- a(456);
- }
- void function2() {
- b(123);
- b(456);
- }
- void test() {
- function1();
- function2();
- }
- void a(int) {
- // do something
- }
- void b(int) {
- // something else
- }
- template<void (*param)(int) >
- void function() {
- param(123);
- param(456);
- }
- void test() {
- function<a>();
- function<b>();
- }
- template<typename T>
- void a(T t) {
- // do something
- }
- template<typename T>
- void b(T t) {
- // something else
- }
- template< ...param... > // ???
- void function() {
- param<SomeType>(someobj);
- param<AnotherType>(someotherobj);
- }
- void test() {
- function<a>();
- function<b>();
- }
- template <typename T>
- struct a {
- static void foo (T = T ())
- {
- }
- };
- template <typename T>
- struct b {
- static void foo (T = T ())
- {
- }
- };
- struct SomeObj {};
- struct SomeOtherObj {};
- template <template <typename P> class T>
- void function ()
- {
- T<SomeObj>::foo ();
- T<SomeOtherObj>::foo ();
- }
- int main ()
- {
- function<a>();
- function<b>();
- }
- template <typename T, T param>
- void function() {
- param(123);
- param(456);
- }
- void test()
- {
- function< void(*)(int), a<int> >(); // space at end necessary to compiler
- function< void(*)(int), b<int> >(); // because the C++ grammar is ambiguous
- }
- #define function(x) do { x<thing1>(obj1); x<thing2>(obj2) } while(0)
- template<typename T> void a(T t) { /* do something */}
- template<typename T> void b(T t) { /* something else */ }
- template <typename F>
- void function(F&& f) {
- f(someobj);
- f(someotherobj);
- }
- void test() {
- // For simple cases, auto&& is even probably auto or const auto&
- function([](auto&& t){ a(t); });
- function([](auto&& t){ b(t); });
- // For perfect forwarding
- function([](auto&& t){ a(std::forward<decltype(t)>(t)); });
- function([](auto&& t){ b(std::forward<decltype(t)>(t)); });
- }
- template < typename F >
- void function(F f)
- {
- f(123);
- }
- void a(int x) { ... }
- struct b { void operator() (int x) { ... } };
- void outer()
- {
- function(&a);
- function(b());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement