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!
Browse Source

Improved dispatch.

master
Stanislaw Adaszewski 3 years ago
parent
commit
14321daf62
1 changed files with 14 additions and 22 deletions
  1. +14
    -22
      src/torch_stablesort/dispatch_test.cpp

+ 14
- 22
src/torch_stablesort/dispatch_test.cpp View File

@@ -1,33 +1,25 @@
#include <utility>
#include <iostream>
template<typename fun, typename... Ts>
class Dispatcher {
public:
void dispatch(int x, Ts&& ...args) {
if (x > 0)
call<int>(std::forward<Ts>(args)...);
else
call<double>(std::forward<Ts>(args)...);
}
template<template<typename T> class F, typename... Ts>
void dispatch(int x, Ts&& ...args) {
if (x > 0)
F<int>()(std::forward<Ts>(args)...);
else
F<double>()(std::forward<Ts>(args)...);
}
protected:
template<typename T>
void call(Ts&& ...args) {
throw std::runtime_error("Not implemented");
template<typename T>
struct bla {
void operator()(int&& a, char&& b, double&& c) const {
std::cout << typeid(T).name() << " " << a << " " << b << " " << c << std::endl;
}
};
class bla {};
template<> template<typename T>
void Dispatcher<bla, int, char, double>::call(int&& a, char&& b, double&& c) {
std::cout << typeid(T).name() << " " << a << " " << b << " " << c << std::endl;
}
main() {
std::cout << "main()" << std::endl;
Dispatcher<bla, int, char, double> d;
d.dispatch(5, 1, 'a', 5.5);
d.dispatch(-5, 1, 'a', 5.5);
//bla<double>()(1, 'a', 5.5);
dispatch<bla, int, char, double>(5, 1, 'a', 5.5);
dispatch<bla, int, char, double>(-5, 1, 'a', 5.5);
}

Loading…
Cancel
Save