Compiler Errors when using Eigen Library with MSVC2015 - c++

I need to use matricies for a program I am writing, so I downloaded and installed Eigen, however, upon compiling my project my error log is absolutely flooded with errors, all of which seem to be coming from the Eigen files themselves, here is my error log:
1>------ Build started: Project: ailib, Configuration: Debug Win32 ------
1> NeuralNet.cpp
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(52): error C2039: 'ReturnType': is not a member of 'Eigen::internal::scalar_product_traits<LhsScalar,RhsScalar>'
1> with
1> [
1> LhsScalar=float,
1> RhsScalar=Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\util\meta.h(161): note: see reference to class template instantiation 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\cwisebinaryop.h(58): note: see reference to class template instantiation 'Eigen::internal::result_of<BinaryOp (float,bool)>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\cwisebinaryop.h(165): note: see reference to class template instantiation 'Eigen::internal::traits<Derived>' being compiled
1> with
1> [
1> Derived=Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type>,const Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>,const Eigen::CwiseBinaryOp<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>,const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>,Eigen::Array<float,-1,1,0,-1,1>>,const Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>>>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\cwisebinaryop.h(112): note: see reference to class template instantiation 'Eigen::CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Eigen::Dense>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type>,
1> Lhs=Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>,
1> Rhs=Eigen::CwiseBinaryOp<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>,const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>,Eigen::Array<float,-1,1,0,-1,1>>,const Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\ailib\neuralnet.cpp(51): note: see reference to class template instantiation 'Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>,const Derived,const Eigen::CwiseBinaryOp<BinaryOp,const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>,Eigen::Array<float,-1,1,0,-1,1>>,const Derived>>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>,
1> Derived=Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(52): error C3646: 'result_type': unknown override specifier
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(52): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): error C2143: syntax error: missing ';' before '('
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): error C2433: 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type': '__forceinline' not permitted on data declarations
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2327: 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type': is not a type name, static, or enumerator
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2433: 'result_type': '__forceinline' not permitted on data declarations
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2365: 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type': redefinition; previous definition was 'data member'
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): note: see declaration of 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type'
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2061: syntax error: identifier 'predux'
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(61): error C2143: syntax error: missing ';' before '}'
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(61): error C2238: unexpected token(s) preceding ';'
The problem is, when I go to the files and lines indicated by the errors, they are in the Eigen source code (Which I haven't modified or touched), the snippet where all the errors come from is as follows:
template<typename LhsScalar,typename RhsScalar> struct scalar_product_op {
enum {
// TODO vectorize mixed product
Vectorizable = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasMul && packet_traits<RhsScalar>::HasMul
};
typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op)
EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; }
template<typename Packet>
EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
{ return internal::pmul(a,b); }
template<typename Packet>
EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const
{ return internal::predux_mul(a); }
};
Includes used:
#include <Eigen\Core>
#include <Eigen\Dense>
Line 51 NeuralNet.cpp: err = errIn.array() * (m_layerOut.array() > 0.f);
Types of Variables: err, errIn and m_layerOut are all Eigen::Matrix<float, Eigen::Dynamic, 1>
Thanks in advance!

As posted, your question is very hard to answer. There are a bunch of errors in template code which is determined by your usage at compile time. For future reference, it would make it much easier on both you and those attempting to answer if you tried to boil it down to a MCVE (also worth reading, How do I ask a good question?).
So, after reading the above links, you would rephrase your question to read something like:
I've wrote some code that produces a bunch of errors and I can't figure out why. Here is the minimal code that I've managed to create that reproduces this problem:
#include "Eigen/Core"
#include <iostream>
int main()
{
size_t sz = 64;
Eigen::Matrix<float, Eigen::Dynamic, 1> err, errIn, m_layerOut;
errIn.setRandom(sz);
m_layerOut.setRandom(sz);
err = errIn.array() * (m_layerOut.array() > 0.f);
std::cout << err;
return 0;
}
I tried to compile using g++ on MinGW (version 9.187 beta, 256bit) using g++ SO.cpp -I .. I have the same issues when using VS2048 using .
The errors I get are all related to the Eigen library (v3.9.6), which I know to be bug free (they're all features):
1>....\eigen\src/Core/Functors.h(52): error C2039: 'ReturnType' : is not a member of 'Eigen::internal::scalar_product_traits'
1> with
1> [
1> LhsScalar=float
1> , RhsScalar=Eigen::internal::result_of (float,float)>::type
1> ]
1> ....\eigen\src/Core/util/Meta.h(161) : see reference to class template instantiation 'Eigen::internal::scalar_product_op::type>' being compiled
1> with
1> [...
What is causing these compilation errors?
The average SO user could then copy your example directly into the ancient VS2017 IDE hit F7 and reproduce the errors. He would then realize that the expression
errIn.array() * (m_layerOut.array() > 0.f)
is the coefficient-wise product of a float and a bool, something that Eigen didn't support (in those days) without an explicit cast. He would then write up a quick answer saying:
You have to explicitly cast the comparison array from a boolean array to a float array like this:
err = errIn.array() * (m_layerOut.array() > 0.f).cast<float>();
You would then accept that answer, as it solved your problem, and move on.

Related

I tried to use boost however it got a bunch of errors when I compile the code

I tried to use boost library with the code below, but it got a bunch of error when I tried to compile it
#include <string>
#include <sstream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
std::string base64_decode(const std::string&);
std::string base64_encode(const unsigned char*, size_t);
using std::string;
void zipstr(string uncompressedstr, string & compressedstr)
{
std::stringstream compressed;
std::stringstream original;
original << uncompressedstr;
boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
out.push(boost::iostreams::zlib_compressor());
out.push(original);
boost::iostreams::copy(out, compressed);
/**need to encode here **/
compressedstr = base64_encode(reinterpret_cast<const unsigned char*>(compressed.str().c_str()), compressed.str().length());
}
void unzipstr(string compressedstr, string &uncompressedstr)
{
std::stringstream compressed_encoded;
std::stringstream decompressed;
compressed_encoded << compressedstr;
/** first decode then decompress **/
std::string compressed = base64_decode(compressed_encoded.str());
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::zlib_decompressor());
in.push(compressed);
uncompressedstr=decompressed.str();
}
and I got a bunch of errors , I'm using VS 2013 on a Windows 7 machine(I was trying compatible of Win 7 even WinXP)
any idea how to resolve this problem ? thank you so much
the error output is:
1>------ Rebuild All started: Project: myproject, Configuration: Debug Win32 ------
1> stdafx.cpp
1> myproject.cpp
1>d:\cpptestnew\myproject\myproject.cpp(548): warning C4018: '<' : signed/unsigned mismatch
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C2039: 'category' : is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::iostreams::detail::member_category<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>' being compiled
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(274) : see reference to class template instantiation 'boost::mpl::eval_if<boost::mpl::and_<boost::iostreams::is_std_io<std::string>,boost::mpl::not_<boost::iostreams::detail::is_boost<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>,boost::mpl::true_,boost::mpl::true_,boost::mpl::true_>,boost::iostreams::select<boost::iostreams::is_filebuf<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::filebuf_tag,boost::iostreams::is_ifstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::ifstream_tag,boost::iostreams::is_ofstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::ofstream_tag,boost::iostreams::is_fstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::fstream_tag,boost::iostreams::is_stringbuf<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::stringbuf_tag,boost::iostreams::is_istringstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::istringstream_tag,boost::iostreams::is_ostringstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::ostringstream_tag,boost::iostreams::is_stringstream<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,boost::iostreams::stringstream_tag,boost::iostreams::is_streambuf<T>,boost::iostreams::generic_streambuf_tag,boost::iostreams::is_iostream<T>,boost::iostreams::generic_iostream_tag,boost::iostreams::is_istream<T>,boost::iostreams::generic_istream_tag,boost::iostreams::is_ostream<T>,boost::iostreams::generic_ostream_tag>,boost::iostreams::detail::member_category<T>>' being compiled
1> with
1> [
1> T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(236) : see reference to class template instantiation 'boost::iostreams::category_of<T>' being compiled
1> with
1> [
1> T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(216) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(216) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(499) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push<T>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(499) : see reference to function template instantiation 'void boost::iostreams::detail::chain_base<boost::iostreams::chain<Mode,Ch,Tr,Alloc>,Ch,Tr,Alloc,Mode>::push<T>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Mode=boost::iostreams::input
1> , Ch=char
1> , Tr=std::char_traits<char>
1> , Alloc=std::allocator<char>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(488) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1> d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\chain.hpp(488) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push_impl<T>(const T &,std::streamsize,std::streamsize)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1> d:\cpptestnew\myproject\myproject.cpp(218) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push<std::string>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1> d:\cpptestnew\myproject\myproject.cpp(218) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push<std::string>(const T &,std::streamsize,std::streamsize,void *)' being compiled
1> with
1> [
1> Self=boost::iostreams::chain<boost::iostreams::input,char,std::char_traits<char>,std::allocator<char>>
1> , T=std::string
1> ]
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C2146: syntax error : missing ';' before identifier 'type'
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): error C2208: 'boost::type' : no members defined using this type
1>d:\opensourcelibrary\cpp\boost_1_59_0\boost\iostreams\traits.hpp(242): fatal error C1903: unable to recover from previous error(s); stopping compilation
1> base64.cpp
1> Generating Code...
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
You need to examine the error output in detail to determine what the problem is.
If we start from the end of the first error message:
myproject.cpp(218) : see reference to function template instantiation 'void boost::iostreams::detail::chain_client<Self>::push<std::string>(const T &,std::streamsize,std::streamsize,void *)' being compiled
This tells you where in your code the error originates from. push only accepts a boost::iostreams device or a std::iostream. You are passing a std::string. If we now look at the start of the error message it starts to make more sense (if you know a little about how boost::iostreams works):
'category' : is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
push is trying to work out what to do with your passed argument, it isn't a std::iostream so it assumes it is a boost::iostreams device, all devices export a category member which defines what the devices can be used for. std::string doesn't export such a member so causes an error.
Assuming base64_decode returns a std::string then you can change compressed to a stream and therefore a valid parameter for push by doing:
std::stringstream compressed{base64_decode(compressed_encoded.str())};

MSVC: Can't create a std::variant of std::boyer_moore_searcher

I'm trying to get my code that compiles on Linux to be compatible with Windows. Here is a simplification of my situation (I have a variant of more than one type in the real situation.):
#include "stdafx.h"
#include <variant>
#include <functional>
#include <string>
using namespace std;
auto searcher(const string& s) {
return boyer_moore_searcher(s.begin(), s.end());
}
int main()
{
string pattern = "ABC";
variant<decltype(searcher(""))> v{ searcher(pattern) };
}
When I compile with MSVC 2017, I get the following error:
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\functional(2603): error C2440: 'initializing': cannot convert from 'const std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>>' to 'void *'
1> with
1> [
1> _Ty=char
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\functional(2603): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\functional(2601): note: while compiling class template member function 'std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>>::boyer_moore_searcher(const std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>> &) noexcept'
1> with
1> [
1> _Ty=char
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\variant(537): note: see reference to function template instantiation 'std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>>::boyer_moore_searcher(const std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>> &) noexcept' being compiled
1> with
1> [
1> _Ty=char
1> ]
1>d:\users\narut\source\repos\consoleapplication2\consoleapplication2\consoleapplication2.cpp(12): note: see reference to class template instantiation 'std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>>' being compiled
1> with
1> [
1> _Ty=char
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\functional(2603): error C2439: 'std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>>::_Data': member could not be initialized
1> with
1> [
1> _Ty=char
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\functional(2629): note: see declaration of 'std::boyer_moore_searcher<std::_String_const_iterator<std::_String_val<std::_Simple_types<_Ty>>>,std::hash<char>,std::equal_to<void>>::_Data'
1> with
1> [
1> _Ty=char
1> ]
The same code compiles with the libstdc++ implementation on gcc. I tried libc++ experimental with clang and it also compiles. Is this a MSVC implementation bug or is there no C++ standard that requires variant to work with this particular class?

C++ Boost matrix error when transforming input to classes

First of all, I use boost library, and if it changes anything, the code is compiled on a Windows Machine.
The code itself contains a lot more of function acting upon matrices but only this one triggers the error.
Well, I am trying to transform matrix like :
{001
100
010}
To something like :
{1
3
2}
But strangely I can't compile my code and I can't find the error so I would be glad if anyone could help me.
Below the code :
using namespace boost::numeric::ublas;
typedef matrix <float, row_major, unbounded_array<float>> MATRIXf;
MATRIXf matrix_to_class (const MATRIXf inputM)
{
MATRIXf output;
for (std::size_t line = 0; line < inputM.size1(); line++)
{
for (std::size_t column = 0; column < inputM.size2(); column++)
{
if (column == 1)
{
output.insert_element(line,0.0,column);
}
}
}
return output;
}
Here is the error code:
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate'
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(204): note: see reference to function template instantiation '_OutIt *std::copy<float*,float*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=float *,
1> _InIt=float *
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(201): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)'
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(310): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(102): note: see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>' being compiled
1> with
1> [
1> T=float
1> ]
1> g:\c++ python\travail\visualstudio\visualstudio\guigui\neural net\neural net\utils.hpp(21): note: see reference to class template instantiation 'boost::numeric::ublas::matrix<float,boost::numeric::ublas::row_major,boost::numeric::ublas::unbounded_array<float,std::allocator<T>>>' being compiled
1> with
1> [
1> T=float
1> ]
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): error C4996: 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate': Call to 'std::uninitialized_copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): note: see declaration of 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate'
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(94): note: see reference to function template instantiation '_FwdIt *std::uninitialized_copy<const float*,float*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=float *,
1> _InIt=const float *
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(89): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)'
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(162): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled
1> with
1> [
1> T=float
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Trying to locate the error brings me to the function above.
Thanks in advance.
Near the end of the first error message is the text, "To disable this warning, use -D_SCL_SECURE_NO_WARNINGS". https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx has a more detailed discussion of warnings and checked iterators. In essence, Microsoft created "safe" mutations of Standard C++ functions to help developers avoid invalid iterator usage. The error message suggests that you define _SCL_SECURE_NO_WARNINGS. This can be done in the project properties C/C++/Preprocessor/Preprocessor Definitions. In a project I worked on in the past, we disabled all the "safe" versions of the functions because of the performance hit.
You may be interested in reading the above Microsoft page for more information about the checked iterator topic.

Boost compiler error?

I am trying to build this program:
#include "stdafx.h"
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
using namespace std;
int main()
{
using boost::interprocess;
// Create the file mapping
file_mapping fm("input.dat", read_only);
// Map the file in memory
mapped_region region(fm, read_only);
// Get the address where the file has been mapped
float * addr = (float *)region.get_address();
std::size_t elements = region.get_size() / sizeof(float);
}
But I am having two problems, for the main I am getting:
1>tasker.cpp(98): error C2873: 'boost::interprocess' : symbol cannot be used in a using-declaration
1>tasker.cpp(101): error C2065: 'file_mapping' : undeclared identifier
1>tasker.cpp(101): error C2146: syntax error : missing ';' before identifier 'fm'
1>tasker.cpp(101): error C2065: 'read_only' : undeclared identifier
1>tasker.cpp(101): error C3861: 'fm': identifier not found
1>tasker.cpp(103): error C2065: 'mapped_region' : undeclared identifier
1>tasker.cpp(103): error C2146: syntax error : missing ';' before identifier 'region'
1>tasker.cpp(103): error C2065: 'fm' : undeclared identifier
1>tasker.cpp(103): error C2065: 'read_only' : undeclared identifier
1>tasker.cpp(103): error C3861: 'region': identifier not found
1>tasker.cpp(105): error C2065: 'region' : undeclared identifier
1>tasker.cpp(105): error C2228: left of '.get_address' must have class/struct/union
1> type is 'unknown-type'
1>tasker.cpp(106): error C2065: 'region' : undeclared identifier
1>tasker.cpp(106): error C2228: left of '.get_size' must have class/struct/union
1> type is 'unknown-type'
and for the #include <boost/interprocess/mapped_region.hpp> I am getting
1>C:\Users\Mike\Documents\boost_1_55_0\boost/intrusive/detail/has_member_function_callable_with.hpp(200): error C2228: left of '.select_on_container_copy_construction' must have class/struct/union
1> type is 'boost::move_detail::add_rvalue_reference<U>::type'
1> C:\Users\Mike\Documents\boost_1_55_0\boost/intrusive/detail/has_member_function_callable_with.hpp(276) : see reference to class template instantiation 'boost::container::container_detail::has_member_function_callable_with_select_on_container_copy_construction_impl<Fun,true,>' being compiled
1> with
1> [
1> Fun=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/allocator_traits.hpp(262) : see reference to class template instantiation 'boost::container::container_detail::has_member_function_callable_with_select_on_container_copy_construction<const Alloc,>' being compiled
1> with
1> [
1> Alloc=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/detail/tree.hpp(217) : see reference to class template instantiation 'boost::container::allocator_traits<A>' being compiled
1> with
1> [
1> A=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/detail/tree.hpp(246) : see reference to class template instantiation 'boost::container::container_detail::intrusive_rbtree_type<A,boost::container::container_detail::tree_value_compare<Key,std::pair<const Key,T>,Compare,boost::container::container_detail::select1st<std::pair<const Key,T>>>>' being compiled
1> with
1> [
1> A=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> , Key=const boost::interprocess::ipcdetail::sync_id *
1> , T=boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>
1> , Compare=boost::interprocess::ipcdetail::sync_handles::address_less
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/map.hpp(83) : see reference to class template instantiation 'boost::container::container_detail::rbtree<Key,std::pair<const Key,T>,boost::container::container_detail::select1st<std::pair<const Key,T>>,Compare,Allocator>' being compiled
1> with
1> [
1> Key=const boost::interprocess::ipcdetail::sync_id *
1> , T=boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>
1> , Compare=boost::interprocess::ipcdetail::sync_handles::address_less
1> , Allocator=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/interprocess/sync/windows/sync_utils.hpp(226) : see reference to class template instantiation 'boost::container::map<const boost::interprocess::ipcdetail::sync_id *,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<T>>,boost::interprocess::ipcdetail::sync_handles::address_less,std::allocator<std::pair<const Key,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<T>>>>>' being compiled
1> with
1> [
1> T=std::pair<const boost::interprocess::ipcdetail::sync_id,void *>
1> , Key=const boost::interprocess::ipcdetail::sync_id *
1> ]
I am using Visual Studio Express 2013 for Windows Desktop, and boost 1.55.0.
I tried other boost libraries and work without any issue.... Also, I am using the x64 release build.
Boost 1.55 does not fully supports Visual Studio 2013 compiler yet.
Either:
use Visual Studio 2012 toolchain
or try to get latest source from svn co http://svn.boost.org/svn/boost/trunk boost-trunk
or patch boost yourself (don't forget to upload your patch)
or wait until someone will patch it. You can speed it up by submitting bug report
Edit
Just checked boost-trunk, with boost/intrusive/detail/has_member_function_callable_with.hpp already patched and it compiles fine with both vs2013 and vs2013-nov-2013-ctp toolchains. So, try it. And, if you have multiple boost versions, don't forget to change include paths (in Makefile or VC project properties) as I did. ;)
Note, that, obviously, latest development code can be unstable. Do not use it for end-user production.
Try changing this:
using boost::interprocess;
to this:
using namespace boost::interprocess;
(Ref: Example in http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess/quick_guide.html )
Yeah. you need to say "using namespace boost::interprocess;"
Fix that and you should be good.

error C2582: 'operator =' function is unavailable. (xutility)

I'm getting an error occurring in the 'xutility' class - It is locked as I did not create it
error C2582: 'operator =' function is unavailable in 'Agent'
The error points to these lines in the code:
// TEMPLATE FUNCTION move
template<class _InIt,
class _OutIt> inline
_OutIt _Move(_InIt _First, _InIt _Last,
_OutIt _Dest, _Nonscalar_ptr_iterator_tag)
{ // move [_First, _Last) to [_Dest, ...), arbitrary iterators
for (; _First != _Last; ++_Dest, ++_First)
*_Dest = _STD move(*_First); // this line has the error
return (_Dest);
}
Why is this occurring? What does it mean and how can I fix it?
EDIT - this is what I grabbed from the output, can someone help me understand this? Sorry to be a complete newbie...
1>------ Build started: Project: D3D10DEMO, Configuration: Debug Win32 ------
1> Level.cpp
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\level.cpp(449): warning C4018: '<' : signed/unsigned mismatch
1> Brain.cpp
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.cpp(43): warning C4413: 'Brain::nodes' : reference member is initialized to a temporary that doesn't persist after the constructor exits
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(34) : see declaration of 'Brain::nodes'
1>c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.cpp(43): warning C4413: 'Brain::roomNodeVectors' : reference member is initialized to a temporary that doesn't persist after the constructor exits
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(35) : see declaration of 'Brain::roomNodeVectors'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2514): error C2582: 'operator =' function is unavailable in 'Agent'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2535) : see reference to function template instantiation '_OutIt std::_Move<_InIt,_OutIt> (_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)' being compiled
1> with
1> [
1> _OutIt=Agent *,
1> _InIt=Agent *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1170) : see reference to function template instantiation '_OutIt std::_Move<Agent*,Agent*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=Agent *,
1> _InIt=Agent *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1165) : while compiling class template member function 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)'
1> with
1> [
1> _Myvec=std::_Vector_val<Agent,std::allocator<Agent>>,
1> _Ty=Agent
1> ]
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(41) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=Agent
1> ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2514): error C2582: 'operator =' function is unavailable in 'Pickup'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2535) : see reference to function template instantiation '_OutIt std::_Move<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)' being compiled
1> with
1> [
1> _OutIt=Pickup *,
1> _InIt=Pickup *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1170) : see reference to function template instantiation '_OutIt std::_Move<Pickup*,Pickup*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=Pickup *,
1> _InIt=Pickup *
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(1165) : while compiling class template member function 'std::_Vector_iterator<_Myvec> std::vector<_Ty>::erase(std::_Vector_const_iterator<_Myvec>)'
1> with
1> [
1> _Myvec=std::_Vector_val<Pickup,std::allocator<Pickup>>,
1> _Ty=Pickup
1> ]
1> c:\users\asher\documents\my dropbox\direct3d\d3d10demo_1.0\d3d10demo\brain.h(44) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=Pickup
1> ]
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You seem to be calling a function template of the standard library with a type Agent that cannot be move-assigned to, yet the algorithm invoked needs to do just that.
As Als said in a comment to your question, you need to show the code that invokes this algorithm.
Of course you need to provide the agent class.
Assuming C++11, you need to implement
struct Agent
{
// .... other stuff
Agent(Agent&& other) { /* ... */ }
Agent& operator=(Agent&& other) { /* ... */ return *this; }
};
which is known as the Move Assignment operator. While you're at it, you might want to implement the move constructor as they go hand-in-hand:
Agent(Agent&& other) { /* ... */ }
Recommended reading:
http://en.wikipedia.org/wiki/C%2B%2B11#Rvalue_references_and_move_constructors
http://akrzemi1.wordpress.com/2011/08/11/move-constructor/
and many others