在不命名的情况下访问中间犰狳对象成员[C++]

Accessing intermediate armadillo object member without naming it [C++]

使用犰狳库,可以这样写

// Log if this is non-finite
if ( ! averages.is_finite() )
{
    arma::uvec nonfinites = arma::find_nonfinite( averages );
    LOG_WARN( "There are ",  nonfinites.n_elem, " of ", averages.n_elem,
            " non-finite elements in the band border averages of the input signal." );
}

我想在不使用 nonfinites 中间向量的情况下简化它,如下所示:

    LOG_WARN( "There are ",  (arma::find_nonfinite( averages )).n_elem, " of ", averages.n_elem,
            " non-finite elements in the band border averages of the input signal." );

但是我收到一条 g++ 错误消息

/path/to/file.cpp:901:71: error: ‘arma::enable_if2<true, const arma::mtOp<long long un
signed int, arma::Mat<double>, arma::op_find_nonfinite> >::result’ has no member named ‘n_elem’
         LOG_WARN( "There are ", (arma::find_nonfinite( averages )).n_elem, " of ", averages.n_elem,

我不确定我是在处理一般的 C++ 问题,还是 arma 库函数 return 类型不是 arma::uvec(如 g++ 错误所示)。实际上有成员n_elem。是否需要先将 returned 对象转换为 uvec

非常感谢任何解释!

使用.eval()成员函数强制计算表达式:

(arma::find_nonfinite( averages )).eval().n_elem

或者,直接将表达式转换为 uvec:

arma::uvec(arma::find_nonfinite( averages )).n_elem