c ++ auto with overriding signed/unsigned

bar*_*rej 1 c++ types armadillo c++11

在以下代码中:

#include <armadillo>

using namespace arma;

int main()
{
    mat A;
    auto x=A.n_rows-5;
    ....
Run Code Online (Sandbox Code Playgroud)

x是的long long unsigned int,我想要它 long long int.我该如何解决这个问题?

应该注意的是,在这个库的不同版本中,使用了不同的类型,所以我不能long long int直接提及我需要使用auto.

Tit*_*nda 5

由于您已经在使用犰狳,我认为最好的(或最简单的)方式是使用arma::sword.

sword x = A.n_rows - 5; // This can also compile without C++11.
Run Code Online (Sandbox Code Playgroud)

它将解决"此库的不同版本,已使用的不同类型"的问题,因为A.n_rows具有类型arma::uword,即无符号版本arma::sword.请参阅http://arma.sourceforge.net/docs.html#uword