// // example: // ・transform( x.begin(), x.end(), y.begin(), sin_(X)*sin_(X) ); // // // petitfex の double 版 // namespace petit_fex_double { // 定数 ---------------------------------------- struct val { val(double v) : v_(v) {} const double v_; double operator()(double t) const { return v_; } }; // double型 => val型へのフィルタ ------------------ template struct tr { typedef V typ; }; template<> struct tr { typedef val typ; }; template<> struct tr { typedef val typ; }; // 変数 ---------------------------------------- struct var { double operator()(double t) const { return t; } }; // 単項演算子 ---------------------------------- #define unary_op( NAME, OP ) \ template struct NAME { \ NAME(A a) : a_(a) {} A a_; \ double operator()(double t) { return OP a_(t); } \ }; \ template \ NAME::typ> \ operator OP ( A a ) { \ return NAME::typ> \ (typename tr::typ(a)); \ } unary_op( pf_neg, - ) unary_op( pf_pos, + ) #undef unary_op // 二項演算子 ---------------------------------- #define binary_op( NAME, OP ) \ template struct NAME { \ NAME(A a, B b) : a_(a), b_(b) {} A a_; B b_; \ double operator()(double t) { return a_(t) OP b_(t); } \ }; \ template \ NAME::typ,typename tr::typ> \ operator OP (A a, B b) { \ return NAME::typ, \ typename tr::typ> \ (typename tr::typ(a), \ typename tr::typ(b)); \ } binary_op( pf_plus, + ) binary_op( pf_minus, - ) binary_op( pf_mult, * ) binary_op( pf_div, / ) binary_op( pf_mod, % ) #undef binary_op // 関数 ---------------------------------- typedef double (*func)(double); #define func_op( NAME, FP ) \ template struct NAME##x { \ NAME##x(A a, func f) : a_(a), f_(f) {} A a_; func f_; \ double operator()(double t) { return f_(t); } \ }; \ template \ NAME##x::typ> \ NAME (A a) { \ return NAME##x::typ> \ (typename tr::typ(a), FP); \ } func_op( sin_, sin ) func_op( cos_, cos ) func_op( tan_, tan ) #undef func_op } namespace { static petit_fex_double::var X; }