#include "StatTools/Funct/GenericIntegral.h" #include "StatTools/Funct/FunctManip.h" #include "StatTools/Funct/FunctIO.h" #include using namespace std; using namespace Funct; template< typename X > struct MyExpr { MyExpr( const X& x ) : _( x ) { } double operator()() const { return std::pow( _(), 2 ); } X _; }; template< typename X > struct MyExprPrimitive { MyExprPrimitive( const X& x ) : _( x ) { } double operator()() const { return std::pow( _(), 3 ) / 3; } X _; }; DECLARE_PRIMITIVE( X, MyExpr< X >, MyExprPrimitive< X > ) template< typename X > struct MyExpr2 { MyExpr2( const X& x ) : _( x ) { } double operator()() const { return std::pow( _(), 2 ); } X _; }; const unsigned samples = 1000; NUMERICAL_INTEGRAL( X, MyExpr2< X >, samples ) template< typename X > std::ostream& operator<<( std::ostream& cout, const MyExpr& e ) { return cout << "sqr( " << e._ << " )"; } template< typename X > std::ostream& operator<<( std::ostream& cout, const MyExpr2& e ) { return cout << "sqare( " << e._ << " )"; } int main() { X x; Y y; cout << "analitic integration: " << endl; GenericIntegral i ( pow( x, num<2>() ) ); cout << i << " { 0, 1 } = " << i( 0, 1 ) << endl; cout << "specified analitic primitive: " << endl; MyExpr e ( x ); GenericIntegral j ( e ); cout << j << " { 0, 1 } = " << j( 0, 1 ) << endl; cout << "numeric integration ( " << samples << " samples ): " << endl; MyExpr2 e2 ( x ); GenericIntegral j2 ( e2 ); cout << j2 << " { 0, 1 } = " << j2( 0, 1 ) << endl; return 0; }