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!
Преглед на файлове

Improved dispatch.

master
Stanislaw Adaszewski преди 4 години
родител
ревизия
14321daf62
променени са 1 файла, в които са добавени 14 реда и са изтрити 22 реда
  1. +14
    -22
      src/torch_stablesort/dispatch_test.cpp

+ 14
- 22
src/torch_stablesort/dispatch_test.cpp Целия файл

@@ -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…
Отказ
Запис