get_unit_value在提升ODEINT中的作用
role of get_unit_value in boost ODEINT
在Boost库的以下代码中:
template<class T , class Enabler = void >
struct get_unit_value_impl
{
static T value(const T &t)
{
return t;
}
typedef T result_type;
};
template<class T>
typename detail::get_unit_value_impl<T>::result_type get_unit_value(const T &t)
{
return detail::get_unit_value_impl<T>::value(t);
}
get_unit_value
的作用我不清楚。它做什么?我们传递一些东西给它,它返回相同的值。为什么要有人把它包成一个结构?除了减慢运行时间之外,它还能做什么吗?
这个代码是从这里调用的:
template< class Fac1 = double >
struct rel_error
{
const Fac1 m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt;
rel_error( Fac1 eps_abs , Fac1 eps_rel , Fac1 a_x , Fac1 a_dxdt )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) { }
template< class T1 , class T2 , class T3 >
void operator()( T3 &t3 , const T1 &t1 , const T2 &t2 ) const
{
using std::abs;
set_unit_value( t3 , abs( get_unit_value( t3 ) ) / ( m_eps_abs + m_eps_rel * ( m_a_x * abs( get_unit_value( t1 ) ) + m_a_dxdt * abs( get_unit_value( t2 ) ) ) ) );
}
typedef void result_type;
};
您忘记复制其中一个专业:
template<class T , class Enabler = void >
struct get_unit_value_impl
{
static T value(const T &t)
{
return t;
}
typedef T result_type;
};
#ifndef __CUDACC__
template<class Unit , class T>
struct get_unit_value_impl< boost::units::quantity< Unit , T> >
{
static T value( const boost::units::quantity< Unit , T> &t )
{
return t.value();
}
typedef T result_type;
};
#endif
点get_unit_value()
是取一个值并返回它,或者取一个boost::unit::quantity<Unit, T>
并返回它的值。这样,调用者就不需要担心t
是否只是int
或更复杂的东西:
int x = 7;
quantity<length> L = 2.0*meters;
get_unit_value(x); // 7
get_unit_value(L); // 2.0
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 未在作用域中声明unordered_map
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 有没有一种方法可以在编译时获得作用域类名
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- C++quit()函数中可能存在作用域问题
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- "using namespace std;"在C++的作用是什么?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- Eigen::VectorXd 和 Boost::Odeint,不起作用
- 提升 ODEINT 太多参数无法发挥作用
- get_unit_value在提升ODEINT中的作用