Call another overload function

I'm going to understand the library odeintfrom c++ boost, and I need to know which part does what. In boost/numeric/odeint/integrate/integrate_adaptive.hppthere is a function called integrate_adaptive. This function has several overloads. A simplified file with my little manipulations is as follows:

integrate_adaptive_minimal.hpp

#define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_ADAPTIVE_HPP_INCLUDED

#include <boost/type_traits/is_same.hpp>

#include <boost/numeric/odeint/stepper/stepper_categories.hpp>
#include <boost/numeric/odeint/integrate/null_observer.hpp>
#include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
using namespace std;
namespace boost {
namespace numeric {
namespace odeint {


/*
 * the two overloads are needed in order to solve the forwarding problem
 */
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
        Stepper stepper , System system , State &start_state ,
        Time start_time , Time end_time , Time dt ,
        Observer observer )
{
    cout<<"type one"<<endl;  //added by me ***************************************
    typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
    return detail::integrate_adaptive(
            stepper , system , start_state ,
            start_time , end_time , dt ,
            observer , stepper_category() );
    /*
     * Suggestion for a new extendable version:
     *
     * integrator_adaptive< Stepper , System, State , Time , Observer , typename Stepper::stepper_category > integrator;
     * return integrator.run( stepper , system , start_state , start_time , end_time , dt , observer );
     */
}

/**
 * \brief Second version to solve the forwarding problem,
 * can be called with Boost.Range as start_state.
 */
template< class Stepper , class System , class State , class Time , class Observer >
size_t integrate_adaptive(
        Stepper stepper , System system , const State &start_state ,
        Time start_time , Time end_time , Time dt ,
        Observer observer )
{
    cout<<"type two"<<endl;  //added by me ***************************************
    typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
    return detail::integrate_adaptive(
            stepper , system , start_state ,
            start_time , end_time , dt ,
            observer , stepper_category() );
}


} // namespace odeint
} // namespace numeric
} // namespace boost

The difference between the two functions is related to the parameter start_state. In the second function, it contains a keyword const. I want to know what overload is called. So, I added cout to each function. Then I call them from this test file:

minimal.cpp

#include "integrate_adaptive_minimal.hpp"
#include <boost/numeric/odeint.hpp>
#include <armadillo>

using namespace arma;
using namespace boost::numeric::odeint;

typedef vec::fixed<2> state_type;

void sys( const state_type &x , state_type &dxdt , const double t)
{
    mat A;
    A<<-1<<0<<endr<<0<<-1;
    mat B;
    B<<1<<endr<<1;

    dxdt=A*x+B*(t>0?1:0);
}

void observer( const state_type &x , const double t )
{
}

typedef runge_kutta_dopri5<state_type> stepper_type;

int main()
{
    state_type x;
    x(0) = 0.0;
    x(1) = 0.0;
    integrate_adaptive(make_controlled(1E-10,1E-10,stepper_type()),
                        sys,x,0.0,11.0,0.1,observer);
    return 0;
}

When I compile and run:

g++ -std=c++11 minimal.cpp  -larmadillo -lboost_thread -lboost_filesystem -lboost_system -Wfatal-errors

./a.out

, integrate_adaptive, const. , , ? x const!

- boost, , .

Update:

: github, doc

+4
3

. , const, , . const integrate_adaptive. , ,

integrate_adaptive( stepper , system , make_pair( a.begin() , a.begin() + 3 ) , t0 , t1 , dt , obs );

, .

auto r = make_pair( a.begin() , a.begin() + 3 );    //  Without auto the type will be really complicated.
integrate_adaptive( stepper , system , r , t0 , t1 , dt , obs );

pre ++ 11 r , - pair< vector< double >::iterator , vector< double >::iterator > . steppers do_step .

+2

, .

integrate_adaptive odeint::copy ( odeint/util/copy.hpp) controlled_step_result try_step(System, const StateInOut&x, time_type&, time_type&). ( )

  • \param system , , r.h.s. . Simple System.
  • \param x ODE, . , . .

, const. , , , const.

, , , const. , double * const& ( double const* const&), .

const:

/*
* the two overloads are needed in order to solve the forwarding problem
*/

,

/**
* \brief Second version to solve the forwarding problem,
* can be called with Boost.Range as start_state.
*/

, , boost::make_iterator_range(a,b), Boost Range ( const&), .


:

, const, (, , ):

state_type const x { 0, 0 };
integrate_adaptive(make_controlled(1E-10, 1E-10, stepper_type()), sys, x, 0.0, 11.0, 0.1/*, observer*/);

integrate_adaptive(make_controlled(1E-10, 1E-10, stepper_type()), sys, 
                 state_type { 0.0, 0.0 }, 0.0, 11.0, 0.1/*, observer*/);
+2

x const, integrate_adaptive():

integrate_adaptive(make_controlled(1E-10,1E-10,stepper_type()),
                        sys, const_cast<const state_type &>(x),0.0,11.0,0.1,observer);

const promises, x , main() integrate_adaptive().

( ++ const_cast , , - x - .)

0

All Articles