32 #ifndef VSMC_INTEGRATE_NINTEGRATE_BASE_HPP
33 #define VSMC_INTEGRATE_NINTEGRATE_BASE_HPP
38 #define VSMC_STATIC_ASSERT_INTEGRATE_NINTEGRATE_BASE_DERIVED
40 #define VSMC_STATIC_ASSERT_INTEGRATE_NINTEGRATE_BASE_DERIVED \
42 (cxx11::is_base_of<NIntegrateBase<Derived>, Derived>::value), \
43 USE_CRTP_NIntegrateBase_WITH_A_CLASS_NOT_DERIVED_FROM_THE_BASE)
46 #define VSMC_STATIC_ASSERT_INTEGRATE_NINTEGRATE_BASE_NO_IMPL(member) \
47 VSMC_STATIC_ASSERT((cxx11::is_same<Derived, NullType>::value), \
48 DERIVED_FROM_NIntegrateBase_WITHOUT_IMPLEMENTATION_OF_##member##_IN_THE_Derived_TEMPLATE_PARAMETER)
50 #define VSMC_RUNTIME_ASSERT_INTEGRATE_NINTEGRATE_BASE_DERIVED \
51 VSMC_RUNTIME_ASSERT((dynamic_cast<Derived *>(this)), \
52 ("DERIVED FROM NIntegrateBase " \
53 "WITH INCORRECT **Derived** TEMPLATE PARAMTER"));
59 template <
typename Derived>
80 return integrate_segment_dispatch(a, b, eval,
81 &Derived::integrate_segment);
84 double operator() (size_type N,
const double *grid,
const eval_type &eval)
90 for (size_type i = 1; i != N; ++i)
99 double integrate_segment_dispatch (
double a,
double b,
100 const eval_type &eval,
101 double (D::*) (
double,
double,
const eval_type &))
108 template <
typename D>
109 double integrate_segment_dispatch (
double a,
double b,
110 const eval_type &eval,
111 double (D::*) (
double,
double,
const eval_type &)
const)
118 double integrate_segment_dispatch (
double a,
double b,
119 const eval_type &eval,
120 double (*) (
double,
double,
const eval_type &))
121 {
return Derived::integrate_segment(a, b, eval);}
123 double integrate_segment_dispatch (
double,
double,
const eval_type &,
155 #endif // VSMC_INTEGRATE_NINTEGRATE_BASE_HPP
Numerical integration base dispatch class.
NIntegrateBase(const NIntegrateBase< Derived > &)
#define VSMC_STATIC_ASSERT_INTEGRATE_NINTEGRATE_BASE_DERIVED
NIntegrateBase(const NIntegrateBase< Virtual > &)
cxx11::function< double(double)> eval_type
virtual ~NIntegrateBase()
double operator()(size_type N, const double *grid, const eval_type &eval)
#define VSMC_STATIC_ASSERT_INTEGRATE_NINTEGRATE_BASE_NO_IMPL(member)
double integrate_segment(double a, double b, const eval_type &eval)
Integrate a segment on the grid.
cxx11::function< double(double)> eval_type
NIntegrateBase< Derived > & operator=(const NIntegrateBase< Derived > &)
#define VSMC_RUNTIME_ASSERT_INTEGRATE_NINTEGRATE_BASE_DERIVED
#define VSMC_CRTP_DESTRUCTOR_PREFIX
CRTP style base classes (virtual) destructor.
virtual ~NIntegrateBase()
Numerical integration base dispatch class.