Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template<typename> struct fx;
  2.  
  3. template<typename R, typename...Args>
  4. struct fx<R(Args...)>
  5. {
  6.     virtual R operator()(const Args & ...x) const = 0;
  7. };
  8.  
  9. template<typename> struct fx_err;
  10.  
  11. // I feel here something is wrong, but I can't figure it out.
  12. template<template<typename> class F, typename R, typename... Args>
  13. struct fx_err< F<R(Args...)> > : fx<R(R,Args...)>
  14. {
  15.     using fx_type = F<R(Args...)>;
  16.  
  17.     fx_type f;
  18.  
  19.     R operator ()(const R &y, const Args & ...x) const override
  20.     {
  21.         return y - f(x...);
  22.     }
  23. };
  24.  
  25. struct example_fun : fx<int(int,int,int)>
  26. {
  27.     int operator() (const int &a, const int &b, const int &c) const override
  28.     {
  29.         return a * b * c;
  30.     }
  31. };
  32.  
  33.  
  34.  
  35. //---------------------------------------------------------------
  36. int main(int argc, char *argv[])
  37. {
  38.     fx_err<example_fun> example;
  39.     int err = example(24,2,3,4);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement