【问题标题】:boost::odeint deduction/substitution failureboost::odeint 扣除/替换失败
【发布时间】:2016-12-23 05:04:31
【问题描述】:

我应该如何更改我的代码以正确重载 vector_space_norm_inf 以实现自定义状态类型?

template<typename T>
class Traits{
public:
  typedef T value_t;
  typedef complex<value_t> scalar_t;
  typedef vector<scalar_t> state_t;
}

using namespace boost;
using namespace numeric;
using namespace odeint;

template<typename T>
struct vector_space_norm_inf<typename Traits<T>::state_t>{
  typedef typename Traits<T>::value_t result_type;
  typedef typename Traits<T>::scalar_t scalar_t;
  typedef typename Traits<T>::state_t state_t;

  result_type operator()(const state_t& x) const{
    auto comparator=[](const scalar_t& x1, const scalar_t& x2){
      return std::abs(x1)<std::abs(x2);
    };
    auto result=std::max_element(x.begin(),x.end(),comparator);
    result_type maxElement=std::abs(*result);
    return maxElement;
  }
};

问题是我尝试从依赖范围推断模板参数。我知道这是不可能的,我在这里询问如何更改我的代码以避免它。

【问题讨论】:

  • 你想专攻所有有 trait 类的东西吗?

标签: c++ templates boost odeint


【解决方案1】:

只是不要使用你的 Traits 类模板 - 直接使用你想要的 state_t

namespace boost { namespace numeric { namespace odeint {
    template<typename T>
    struct vector_space_norm_inf<vector<complex<T>>> {
        ...
    };
}}}

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2013-06-20
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多