MrHitch

Untitled

Oct 20th, 2020
488
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "composition.hpp"
  2.  
  3. double Compose(size_t n, ...) {
  4.     va_list vaList;
  5.     size_t m = n++;
  6.     va_start(vaList, n);
  7.     FuncT *fs = new FuncT[n];
  8.     for (size_t i = 1; i <= m; ++i) {
  9.         fs[i] = va_arg(vaList, FuncT);
  10.     }
  11.     double res = va_arg(vaList, double);
  12.     va_end(vaList);
  13.     if (m == 0) {
  14.         return res;
  15.     }
  16.     for (size_t i = m; i >= 1; --i) {
  17.         res = (fs[i])(res);
  18.     }
  19.     delete [] fs;
  20.     return res;
  21. }
RAW Paste Data