IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
778B

  1. #include <utility>
  2. #include <iostream>
  3. template<typename fun, typename... Ts>
  4. class Dispatcher {
  5. public:
  6. void dispatch(int x, Ts&& ...args) {
  7. if (x > 0)
  8. call<int>(std::forward<Ts>(args)...);
  9. else
  10. call<double>(std::forward<Ts>(args)...);
  11. }
  12. protected:
  13. template<typename T>
  14. void call(Ts&& ...args) {
  15. throw std::runtime_error("Not implemented");
  16. }
  17. };
  18. class bla {};
  19. template<> template<typename T>
  20. void Dispatcher<bla, int, char, double>::call(int&& a, char&& b, double&& c) {
  21. std::cout << typeid(T).name() << " " << a << " " << b << " " << c << std::endl;
  22. }
  23. main() {
  24. std::cout << "main()" << std::endl;
  25. Dispatcher<bla, int, char, double> d;
  26. d.dispatch(5, 1, 'a', 5.5);
  27. d.dispatch(-5, 1, 'a', 5.5);
  28. }