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

불러오는 중...
취소
저장