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);
}

読み込み中…
キャンセル
保存