在Boost ODEINT库中,您可以找到很多static_cast
关键字,例如:
template<
class State ,
class Value = double ,
class Deriv = State ,
class Time = Value ,
class Algebra = typename algebra_dispatcher< State >::algebra_type ,
class Operations = typename operations_dispatcher< State >::operations_type ,
class Resizer = initially_resizer
>
class runge_kutta_dopri5: ....
{
...
typedef typename stepper_base_type::value_type value_type;
...
template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut >
void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt_in , time_type t ,
StateOut &out , DerivOut &dxdt_out , time_type dt )
{
const value_type a2 = static_cast<value_type> ( 1 ) / static_cast<value_type>( 5 );
const value_type a3 = static_cast<value_type> ( 3 ) / static_cast<value_type> ( 10 );
const value_type a4 = static_cast<value_type> ( 4 ) / static_cast<value_type> ( 5 );
const value_type a5 = static_cast<value_type> ( 8 )/static_cast<value_type> ( 9 );
....
哪里value_type
由模板决定。
我的问题是,如果value_type
是一个简单的类型,和double
之间有什么区别 吗?我想知道他们为什么使用这种铸造方式。if is or一样吗?static_cast<value_type> ( 5 )
(double)5
value_type
double&
double&&