Related
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())};
I'd like to use boost::compute and boost::range together, like below, but if I uncomment the #include <boost/range/combine.hpp> line I get an error saying that boost::compute::zip_iterator and boost::iterators::zip_iterator are ambiguous. Is there a way around this, so that I can use boost::compute and boost::range together in the same cpp file? I am using on Windows vs2015 64bit. Boost 1.67.0.
Update: I've found the same error occurs if I try to include boost/iterator/zip_iterator.hpp instead of boost/range/combine.hpp, so it is not specific to the Boost Range library.
Code:
#include <vector>
#include <iostream>
#include <algorithm>
//#include <boost/range/combine.hpp>
#include <boost/compute/lambda.hpp>
#include <boost/compute/functional/math.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/algorithm/transform.hpp>
namespace compute = boost::compute;
using compute::float4_;
using compute::lambda::_1;
using compute::lambda::_2;
using compute::lambda::distance;
int main()
{
// get default device and setup context
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);
// generate random data on the host
std::vector<float4_> a(10000);
std::vector<float4_> b(10000);
std::vector<float> r(10000);
std::generate((float*)a.data(), (float*)(a.data() + a.size()), rand);
std::generate((float*)b.data(), (float*)(b.data() + b.size()), rand);
// create a vector on the device
compute::vector<float4_> _a(a.size(), context);
compute::vector<float4_> _b(b.size(), context);
compute::vector<float> _r(r.size(), context);
// transfer data from the host to the device
compute::copy(a.begin(), a.end(), _a.begin(), queue);
compute::copy(b.begin(), b.end(), _b.begin(), queue);
boost::compute::transform(
_a.begin(), _a.end(),
_b.begin(),
_r.begin(),
distance(_1, _2),
queue
);
// copy values back to the host
compute::copy(_r.begin(), _r.end(), r.begin(), queue);
for (int i = 0; i < a.size(); ++i)
{
float4_ va = a[i];
float4_ vb = b[i];
float vr = r[i];
float e = std::sqrt(std::pow(va[0] - vb[0], 2) +
std::pow(va[1] - vb[1], 2) +
std::pow(va[2] - vb[2], 2) +
std::pow(va[3] - vb[3], 2));
std::cout << std::setprecision(12);
if (std::abs(e - vr) > 1e-2)
std::cout << e << " != " << vr << "\n";
}
return 0;
}
Error:
1>------ Build started: Project: demo, Configuration: Debug x64 ------
1> demo.cpp 1> This header is implementation detail and provided for
backwards compatibility.
1>C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(67):
error C2668: 'boost::compute::make_zip_iterator': ambiguous call to
overloaded function 1>
C:\local\boost_1_67_0\boost/compute/iterator/zip_iterator.hpp(276):
note: could be
'boost::compute::zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>
boost::compute::make_zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>(IteratorTuple)'
1> with 1> [ 1>
T=boost::compute::float4_, 1>
IteratorTuple=boost::tuples::tuple,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
1> ] 1>
C:\local\boost_1_67_0\boost/iterator/zip_iterator.hpp(357): note: or
'boost::iterators::zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>
boost::iterators::make_zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>(IteratorTuple)'
[found using argument-dependent lookup] 1> with 1> [
1> T=boost::compute::float4_, 1>
IteratorTuple=boost::tuples::tuple,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
1> ] 1>
C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(67): note:
while trying to match the argument list
'(boost::tuples::tuple,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>)'
1> with 1> [ 1>
T=boost::compute::float4_ 1> ] 1>
C:\workspaces\compute_test\src\demo.cpp(45): note: see reference to
function template instantiation 'OutputIterator
boost::compute::transform,boost::compute::buffer_iterator,boost::compute::buffer_iterator,boost::compute::lambda::expression>(InputIterator1,InputIterator1,InputIterator2,OutputIterator,BinaryOperator,boost::compute::command_queue
&)' being compiled 1> with 1> [ 1>
OutputIterator=boost::compute::buffer_iterator, 1>
T=boost::compute::float4_, 1>
Expr=boost::proto::exprns_::basic_expr,0>>,const
boost::compute::lambda::expression>,0>>
&,const
boost::compute::lambda::expression>,0>>
&>,3>, 1>
InputIterator1=boost::compute::buffer_iterator,
1>
InputIterator2=boost::compute::buffer_iterator,
1>
BinaryOperator=boost::compute::lambda::expression,0>>,const
boost::compute::lambda::expression>,0>>
&,const
boost::compute::lambda::expression>,0>>
&>,3>> 1> ]
1>C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(68):
error C2668: 'boost::compute::make_zip_iterator': ambiguous call to
overloaded function 1>
C:\local\boost_1_67_0\boost/compute/iterator/zip_iterator.hpp(276):
note: could be
'boost::compute::zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>
boost::compute::make_zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>(IteratorTuple)'
1> with 1> [ 1>
T=boost::compute::float4_, 1>
IteratorTuple=boost::tuples::tuple,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
1> ] 1>
C:\local\boost_1_67_0\boost/iterator/zip_iterator.hpp(357): note: or
'boost::iterators::zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>
boost::iterators::make_zip_iterator,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>>(IteratorTuple)'
[found using argument-dependent lookup] 1> with 1> [
1> T=boost::compute::float4_, 1>
IteratorTuple=boost::tuples::tuple,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>
1> ] 1>
C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(68): note:
while trying to match the argument list
'(boost::tuples::tuple,boost::compute::buffer_iterator,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>)'
1> with 1> [ 1>
T=boost::compute::float4_ 1> ]
1>C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(72):
error C2672: 'transform': no matching overloaded function found
1>C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(72):
error C2780: 'OutputIterator
boost::compute::transform(InputIterator1,InputIterator1,InputIterator2,OutputIterator,BinaryOperator,boost::compute::command_queue
&)': expects 6 arguments - 4 provided 1>
C:\local\boost_1_67_0\boost/compute/algorithm/transform.hpp(55): note:
see declaration of 'boost::compute::transform'
========== Build: 0 succeeded,
1 failed, 2 up-to-date, 0 skipped ==========
Short term fix is to modify boost/compute/algorithm/transform.hpp. Change both of the calls to make_zip_iterator to ::boost::compute::make_zip_iterator. This qualifies the call to avoid argument dependent look up.
Update: This is fixed in #790
I'm using visual studio 2012 and I isolated a problem in my code to this, but I can't solve it. When running it in release mode it works perfect, but I get an error if I run it in debug.
The code is:
#include "stdafx.h"
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::matrix<double> BMT;
BMT fun()
{
BMT mym;
mym.resize(3,3);
for(int i = 0; i<9;++i) mym(i/3,i%3)=i;
std::cout << mym << std::endl;
return mym;
}
int main(int argc, char* argv[])
{
fun();
//closing message
std::cout<<std::endl<<"press enter to exit."<<std::endl;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
and the error in debug is the following:
1>------ Build started: Project: myproject, Configuration: Debug x64 ------
1> myapp.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory(348): error C4996: 'std::_Uninitialized_copy0': Function call 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 11.0\VC\include\xmemory(333) : see declaration of 'std::_Uninitialized_copy0'
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/storage.hpp(94) : see reference to function template instantiation '_FwdIt std::uninitialized_copy<const double*,double*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=double *,
1> _InIt=const double *
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/storage.hpp(89) : while compiling class template member function 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)'
1> with
1> [
1> T=double
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/matrix.hpp(160) : see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)' being compiled
1> with
1> [
1> T=double
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/matrix.hpp(100) : see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<T>' being compiled
1> with
1> [
1> T=double
1> ]
1> junkApp1.cpp(10) : see reference to class template instantiation 'boost::numeric::ublas::matrix<T>' being compiled
1> with
1> [
1> T=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Do you know what can the problem be?
I was having a similar issue using ublas.
I am not sure what the cause might be but I suppose it's got to do with ublas' copy on write / copy on demand optimizations. Would it be an option to just use the define -D_SCL_SECURE_NO_WARNINGS and be done with it? I have that set globally as I consider 90% of those warnings OS specifc BS anyway.
The problem is that you are compiling with warnings treated as errors.
EDIT: Microsoft has decided that certain parts of C++ (and C) are deprecated, and the compiler reports use of those parts as errors unless _SCL_SECURE_NO_WARNINGS (respectively _CRT_SECURE_NO_WARNINGS) is defined.
I'm trying to move a unordered_map of unique_ptr's into another map, but getting the compile error below.
#include <memory>
#include <unordered_map>
#include <string>
int main()
{
std::unordered_map<int, std::unique_ptr<int>> aMap;
std::unordered_map<int, std::unique_ptr<int>> bMap;
std::unique_ptr<int> ptr(new int);
*ptr = 10;
aMap.insert(std::make_pair(0, std::move(ptr)));
std::move(aMap.begin(), aMap.end(), bMap.end());
return 0;
}
1>------ Build started: Project: Testing, Configuration: Debug Win32 ------
1>Build started 08.07.2012 23:54:16.
1>InitializeBuildStatus:
1> Creating "Debug\Testing.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> main.cpp
1>d:\progs\visual studio 2010\vc\include\utility(260): error C2166: l-value specifies const object
1> d:\progs\visual studio 2010\vc\include\utility(259) : while compiling class template member function 'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(std::pair<_Ty1,_Ty2> &&)'
1> with
1> [
1> _Ty1=const int,
1> _Ty2=std::unique_ptr<int>
1> ]
1> d:\coding\testing\main.cpp(12) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled
1> with
1> [
1> _Ty1=const int,
1> _Ty2=std::unique_ptr<int>
1> ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.64
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think this is an issue that you can't add elements to a map or set by copying to the end. A more simple example that illustrate this is
std::set<int> aSet;
std::set<int> bSet;
aSet.insert(0);
std::move(aSet.begin(), aSet.end(), bSet.end());
to get around this, you need an insert_iterator, so
std::move(aSet.begin(), aSet.end(), inserter(bSet, bSet.begin()));
or
std::move(aMap.begin(), aMap.end(), inserter(bMap, bMap.begin()));
Internally, the insert iterator will attempt to call 'insert' in the passed in container, so rather than trying to do '*(bMap.end()) = *(aMap.begin())', it will call 'bMap.insert(pos, *(aMap.begin()))', though pos is not extremely important for this situation.
sau_timer::sau_timer(int secs, timerparam f) : strnd(io),
t(io, boost::posix_time::seconds(secs))
{
assert(secs > 0);
this->f = f;
//t.async_wait(boost::bind(&sau_timer::exec, this, _1));
t.async_wait(strnd.wrap(boost::bind(&sau_timer::exec, this)));
boost::thread thrd(&io,this);
io.run();
//thrd(&sau_timer::start_timer);
}
This is the code I have in the constructor for the class 'sau_timer' (which will hopefully run a timer in a seperate thread and then call another function).
Unfortunately, atm when I try to compile, I get the following error:
1>c:\program files\boost\boost_1_39\boost\bind\bind.hpp(246) : error C2064: term does not evaluate to a function taking 1 arguments
Aswell as a whole bunch of warnings. What am I doing wrong? I've tried everything I can think of, thank you.
The explanation is at the end of the error messages:
c:\users\ben\documents\visual studio 2008\projects\sauria\sauria\sau_timer.cpp(11) :
see reference to function template instantiation
'boost::thread::thread<boost::asio::io_service*,sau_timer*>(F,A1)' being compiled
The error occurs while generating the ctor of boost::thread. It expects a function object (something with an opererator()()), and you pass it what (I guess) is an io::service. If what you want is a thread calling io_service::run, write:
boost::thread thrd(boost::bind(&io_service::run, &io));
If you use a relatively recent version of Boost, I believe that thread's ctor has a convenience overload that takes care of the bind(), allowing to simply write:
boost::thread thrd(&io_service::run, &io);
Each non-static member function has a first, hidden parameter - the instance on which function is to be called. So your exec function needs two arguments. And you have appropriate code, but it is commented out. I mean:
t.async_wait(boost::bind(&sau_timer::exec, this, _1));
Did you try it and had some other problems?
I need it to be used with strnd.wrap() aswell. I've changed it to this again:
sau_timer::sau_timer(int secs, timerparam f) : strnd(io),
t(io, boost::posix_time::seconds(secs))
{
assert(secs > 0);
this->f = f;
t.async_wait(strnd.wrap(boost::bind(&sau_timer::exec, this, _1)));
boost::thread thrd(&io);
io.run();
}
void sau_timer::exec(const boost::system::error_code&) { (f)(params); }
But now I get these errors:
1>------ Build started: Project: Sauria, Configuration: Debug Win32 ------
1>Compiling...
1>sau_timer.cpp
1>Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1>- add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1>- add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1>Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
1>c:\program files\boost\boost_1_39\boost\bind\bind.hpp(246) : error C2064: term does not evaluate to a function taking 1 arguments
1> c:\program files\boost\boost_1_39\boost\bind\bind_template.hpp(20) : see reference to function template instantiation 'void boost::_bi::list1<A1>::operator ()<F,boost::_bi::list0>(boost::_bi::type<T>,F &,A &,int)' being compiled
1> with
1> [
1> A1=boost::_bi::value<sau_timer *>,
1> F=boost::asio::io_service *,
1> T=void,
1> A=boost::_bi::list0
1> ]
1> c:\program files\boost\boost_1_39\boost\bind\bind_template.hpp(18) : while compiling class template member function 'void boost::_bi::bind_t<R,F,L>::operator ()(void)'
1> with
1> [
1> R=void,
1> F=boost::asio::io_service *,
1> L=boost::_bi::list1<boost::_bi::value<sau_timer *>>
1> ]
1> c:\program files\boost\boost_1_39\boost\thread\detail\thread.hpp(227) : see reference to class template instantiation 'boost::_bi::bind_t<R,F,L>' being compiled
1> with
1> [
1> R=void,
1> F=boost::asio::io_service *,
1> L=boost::_bi::list1<boost::_bi::value<sau_timer *>>
1> ]
1> c:\users\ben\documents\visual studio 2008\projects\sauria\sauria\sau_timer.cpp(11) : see reference to function template instantiation 'boost::thread::thread<boost::asio::io_service*,sau_timer*>(F,A1)' being compiled
1> with
1> [
1> F=boost::asio::io_service *,
1> A1=sau_timer *
1> ]
1>Build log was saved at "file://c:\Users\Ben\Documents\Visual Studio 2008\Projects\Sauria\Sauria\Debug\BuildLog.htm"
1>Sauria - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========