diff --git a/src/torch_stablesort/dispatch_test.cpp b/src/torch_stablesort/dispatch_test.cpp index 8079998..5756088 100644 --- a/src/torch_stablesort/dispatch_test.cpp +++ b/src/torch_stablesort/dispatch_test.cpp @@ -1,33 +1,25 @@ #include #include -template -class Dispatcher { -public: - void dispatch(int x, Ts&& ...args) { - if (x > 0) - call(std::forward(args)...); - else - call(std::forward(args)...); - } +template class F, typename... Ts> +void dispatch(int x, Ts&& ...args) { + if (x > 0) + F()(std::forward(args)...); + else + F()(std::forward(args)...); +} -protected: - template - void call(Ts&& ...args) { - throw std::runtime_error("Not implemented"); +template +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 -void Dispatcher::call(int&& a, char&& b, double&& c) { - std::cout << typeid(T).name() << " " << a << " " << b << " " << c << std::endl; -} main() { std::cout << "main()" << std::endl; - Dispatcher d; - d.dispatch(5, 1, 'a', 5.5); - d.dispatch(-5, 1, 'a', 5.5); + //bla()(1, 'a', 5.5); + dispatch(5, 1, 'a', 5.5); + dispatch(-5, 1, 'a', 5.5); }