Armadillo Initializer List Does Not Work

I am using the 64-bit compiler MSVC2013 under Windows 10.

In accordance with:

std::cout << arma::arma_version::as_string() << std::endl; 

I have version 6.100.1 (Midnight Blue) of the Armadillio library.

I have C ++ 11 enabled, e.g.

 auto il = { 10, 20, 30 }; for(auto ele : il) cout<<ele<<endl; 

works. Also, the library is correctly added, as the following code is executed:

 vec v; v<<10<<20<<30; cout<<v; 

But the attempt to use initialization lists for Armadillio failed.

 vec v = { 1.0, 2.0, 3.0 }; 

causes a compilation error:

error: C2440: 'initializing': cannot convert from 'initializer-list' to 'arma :: Col' The constructor cannot use the source type, or the resolution of the constructor overload was ambiguous.

+5
source share
2 answers

In the folder armadillo-6.100.1 \ include \ armadillo_bits there is a configuration file called config.hpp .

There you will find a paragraph that says:

 #if !defined(ARMA_USE_CXX11) // #define ARMA_USE_CXX11 //// Uncomment the above line to forcefully enable use of C++11 features (eg. initialiser lists). //// Note that ARMA_USE_CXX11 is automatically enabled when a C++11 compiler is detected. #endif 

So, it looks like 64-bit MSVC2013 is not detected as a C ++ 11 compiler from Armadillio. Therefore uncomment the line

 // #define ARMA_USE_CXX11 

Solved my problem. Now it works like a charm:

 vec v = { 1.0, 2.0, 3.0 }; cout<<v; 
+4
source

The documentation states that vec is a typedef for Col<double :

For convenience, the following typedefs have been defined:
vec = colvec = Col <double>

If we look at the Col constructors, we will find the following constructor that will accept a list of initializers:

 #if defined(ARMA_USE_CXX11) template<typename eT> inline Col<eT>::Col(const std::initializer_list<eT>& list) { <...> } 

So, I assume that ARMA_USE_CXX11 not defined, and therefore this constructor is not available.

+5
source

Source: https://habr.com/ru/post/1234600/


All Articles