c++11 - c++ auto with overriding signed/unsigned -
in following code:
#include <armadillo> using namespace arma; int main() { mat a; auto x=a.n_rows-5; ....
x
long long unsigned int
, want long long int
. how can fix problem?
it should noticed on different versions of library, different types have been used, cannot mention long long int
directly , need use auto
.
you can use c++11 type traits library signed or unsigned version of numeric type.
to unsigned int:
std::make_unsigned<int>::type
so signed version of a.n_rows
, try:
std::make_signed<decltype(a.n_rows)>::type x = a.n_rows - 5;
for other qualifiers, there corresponding templates convert between types:
- reference types - http://en.cppreference.com/w/cpp/utility/functional/ref
- pointer types - http://en.cppreference.com/w/cpp/types/add_pointer
- etc. (add or remove const, or volatile qualifiers)
Comments
Post a Comment