Is this a Boost bug or am I doing something wrong?
#include <map>
#include <boost/pool/pool_alloc.hpp>
int main()
{
typedef const std::string key;
typedef double* (*value)(const int&);
std::map<key, value, std::less<key>> map_with_standard_allocator; // works
std::map<key, value, std::less<key>, boost::fast_pool_allocator<std::pair<const key, value> > > map_with_boost_allocator; // fails
}
the last line fails to compile under MS Visual Studio 2008 with Boost 1.40 and 1.48. It compiles fine under g++ 4.5.3 (Cygwin), though.
The error is:
1>Compiling...
1>main.cpp
1>C:\UniLib1\trunk\External\boost/pool/pool_alloc.hpp(205) : error C2535: 'const std::basic_string<_Elem,_Traits,_Ax> *boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address(const std::basic_string<_Elem,_Traits,_Ax> &)' : member function already defined or declared
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1> UserAllocator=boost::default_user_allocator_new_delete,
1> Mutex=boost::details::pool::default_mutex,
1> NextSize=32
1> ]
1> C:\UniLib1\trunk\External\boost/pool/pool_alloc.hpp(202) : see declaration of 'boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address'
1> with
1> [
1> T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1> UserAllocator=boost::default_user_allocator_new_delete,
1> Mutex=boost::details::pool::default_mutex,
1> NextSize=32
1> ]
1> c:\Program Files\Microsoft Visual Studio 9.0\VC\include\xtree(137) : see reference to class template instantiation 'boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>' being compiled
1> with
1> [
1> T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1> UserAllocator=boost::default_user_allocator_new_delete,
1> Mutex=boost::details::pool::default_mutex,
1> NextSize=32
1> ]
1> c:\Program Files\Microsoft Visual Studio 9.0\VC\include\map(78) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<key,value ,std::less<key>,boost::fast_pool_allocator<std::pair<key,value >>,false>
1> ]
1> .\main.cpp(9) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
1> with
1> [
1> _Kty=key,
1> _Ty=value,
1> _Pr=std::less<key>,
1> _Alloc=boost::fast_pool_allocator<std::pair<key,value >>
1> ]
This is not a bug in VS2008 (as I mistakenly claimed in an earlier edit to this answer). The C++03 standard requires that the key type for an associative container, like std::map, must be 'assignable' (per Table 69 in 23.1.2 "Associative containers"). And a const std::string is not assignable. Note that the C++11 standard seems to relax this requirement, but the new standard doesn't apply to since VC++ 2008.
It's not clear to me that a compiler is required to diagnose code that tries to use std::map with a non-assignable key, so I don't think one can claim that GCC or VC++ 2010 are accepting this code improperly (I think it falls into the area of undefined code that works as you might expect, even though there's no guarantee it'll work). However it is clear that it's OK for VC++ 2008 to refuse to compile it.
All that said, I think that VC++ 2008's library parameterizing the allocator's address() function on the map's key rather than map's element is still suspect (see the first edit of this answer for details if you're interested), but I don't think there's any real bug there since the std::pair<> used to hold the map element will always be set up such that key part will be at the same address as the whole element.
Related
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.
This code fails to build in VC2013: (EDIT: I'm not asking why it fails to build)
#include <functional>
struct MyStruct
{
std::function<void()> m_Func;
MyStruct( const std::function<void()>& func) : m_Func(func) {}
};
int main()
{
MyStruct rc( NULL );
return 0;
}
With error:
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(283): error C2064: term does not evaluate to a function taking 0 arguments
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(228) : see reference to function template instantiation '_Ret std::_Callable_obj<int,false>::_ApplyX<_Rx,>(void)' being compiled
1> with
1> [
1> _Ret=void
1> , _Rx=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(228) : see reference to function template instantiation '_Ret std::_Callable_obj<int,false>::_ApplyX<_Rx,>(void)' being compiled
1> with
1> [
1> _Ret=void
1> , _Rx=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(226) : while compiling class template member function 'void std::_Func_impl<_MyWrapper,_Alloc,_Ret,>::_Do_call(void)'
1> with
1> [
1> _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Ret=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(495) : see reference to class template instantiation 'std::_Func_impl<_MyWrapper,_Alloc,_Ret,>' being compiled
1> with
1> [
1> _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Ret=void
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(396) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Do_alloc<_Myimpl,_Ty,_Alloc>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Fty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(396) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Do_alloc<_Myimpl,_Ty,_Alloc>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> , _Fty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(385) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset_alloc<_Ty,std::allocator<std::_Func_class<_Ret,>>>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(385) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset_alloc<_Ty,std::allocator<std::_Func_class<_Ret,>>>(_Fty &&,_Alloc)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> , _Alloc=std::allocator<std::_Func_class<void,>>
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset<_Ty>(_Fty &&)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,>::_Reset<_Ty>(_Fty &&)' being compiled
1> with
1> [
1> _Ret=void
1> , _Ty=int
1> , _Fty=int
1> ]
1> f:\work\teststdfunction\teststdfunction.cpp(16) : see reference to function template instantiation 'std::function<void (void)>::function<int>(_Fx &&)' being compiled
1> with
1> [
1> _Fx=int
1> ]
1> f:\work\teststdfunction\teststdfunction.cpp(16) : see reference to function template instantiation 'std::function<void (void)>::function<int>(_Fx &&)' being compiled
1> with
1> [
1> _Fx=int
1> ]
(Note the '_Fx=int' at the last two reported errors).
I can live with that, as changing MyStruct rc(NULL) to MyStruct rc(nullptr) solves the error. Two things however remain a mystery:
1) Removing the const qualifier from MyStruct ctor (MyStruct( std::function<void()>& func) gives a very, very different error:
1>f:\work\main\dev\common\teststdfunction\teststdfunction\teststdfunction.cpp(16):
error C2664: 'MyStruct::MyStruct(const MyStruct &)' : cannot convert
argument 1 from 'int' to 'std::function &'
Which makes more sense than the original error, and now fixing NULL to nullptr doesn't solve it. Why does int (or nullptr) refuse to cast to std::function<>& but agree to cast to a const std::function<>& ?
2) The original code compiles and works as expected in VS2010. Is it an obscure VS2010 library bug?
EDIT:
As far as the const/non const question goes, I now think the casting involved and potential type mismatch are probably a red herring. The argument passed - either NULL or nullptr - is a literal and thus a const. It just cannot bind to a non const reference. For example:
const int& a = 8; // Ok
int& b = 9; // error C2440: 'initializing' : cannot convert from 'int' to 'int &'
Does that sound right? Am I still missing something?
The special here has to do with constructor template constraints and other implicit conversions.
The reason why nullptr works is because std::function has a particular constructor taking it. This constructor will always be the best match for that argument because function templates are ranked as lower preference, all else being equal.
Normally, 0 will implicitly convert to nullptr and that's fine. The problem is that it can also be passed to the unconstrained function template constructor which constructs from function objects. This does not require an implicit conversion, so all is not equal, so this constructor is preferred- which results in the error that you see that int is not a valid function object.
libstdc++ and libc++ don't not exhibit this behaviour because they have implemented the C++14 fix for this problem, which constrains the constructor. C++11 did not so this behaviour is quite conforming for a C++11 implementation.
This kind of issue is why NULL is a terrible thing that you shouldn't use. In fact, the VS2010 team had to rush nullptr out the door as an additional feature in the last minute because NULL interacts so badly with every other feature in C++, ever, and especially with C++11.
For const vs non-const references, other answers have explained that issue adequately.
There are other WTFs you can find when using std::function without the constrained constructor fix shipped in C++14- this isn't the only one. The long and short is that it's a defect in the C++11 Standard, and not in VS. VS2010 compiling it is probably a compiler overload resolution bug.
Casting a T to a U& never works, and that's intentionally. You can cast to a U const&. The reason is that changes to the temporary U object wouldn't propagate back to the T value.
VS2010 is slightly buggy in this respect, and did allow the cast (but with the proper settings, will warn about it)
I'm trying to use a boost::bimap to provide bi-directional mapping of some node numbers. I have been using boost unordered maps for a few other things, and have no problems using them. I'm on visual studio 2010.
However I get a ton of template errors whenever I try and use a bimap. Even cutting and pasting the code from the examples at here I get the same masses of template problems. E.g: I inserted this code, direct from the examples:
typedef boost::bimap< int, std::string > bm_type;
bm_type bm;
bm.insert( bm_type::value_type(1, "one" ) );
bm.insert( bm_type::value_type(2, "two" ) );
and I get about 750 lines of errors, starting with this:
c:\data\boost\boost_1_56_0\boost\bimap\relation\mutant_relation.hpp(94): error C2220: warning treated as error - no 'object' file generated
1> c:\data\boost\boost_1_56_0\boost\bimap\relation\mutant_relation.hpp(157) : see reference to class template instantiation 'boost::bimaps::relation::detail::relation_storage<LeftType,RightType,force_mutable>' being compiled
1> with
1> [
1> LeftType=boost::bimaps::tags::tagged<const int,boost::bimaps::relation::member_at::left>,
1> RightType=boost::bimaps::tags::tagged<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,boost::bimaps::relation::member_at::right>,
1> force_mutable=false
1> ]
and ending in
IteratorToBaseConverter=boost::bimaps::container_adaptor::support::iterator_facade_to_base<boost::bimaps::detail::map_view_iterator<boost::bimaps::relation::member_at::right,boost::bimaps::detail::bimap_core<int,std::string,boost::mpl::na,boost::mpl::na,boost::mpl::na>>,boost::bimaps::detail::const_map_view_iterator<boost::bimaps::relation::member_at::right,boost::bimaps::detail::bimap_core<int,std::string,boost::mpl::na,boost::mpl::na,boost::mpl::na>>>,
1> IteratorFromBaseConverter=boost::mpl::na,
1> ReverseIteratorFromBaseConverter=boost::mpl::na,
1> ValueToBaseConverter=boost::bimaps::relation::detail::pair_to_relation_functor<boost::bimaps::relation::member_at::right,boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>,
1> ValueFromBaseConverter=boost::bimaps::relation::support::get_pair_functor<boost::bimaps::relation::member_at::right,boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>
1> ]
1>c:\data\my_code.cpp(194): error C2665: 'boost::bimaps::relation::mutant_relation<TA,TB,Info,force_mutable>::mutant_relation' : none of the 5 overloads could convert all the argument types
1> with
1> [
1> TA=boost::bimaps::tags::tagged<const int,boost::bimaps::relation::member_at::left>,
1> TB=boost::bimaps::tags::tagged<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,boost::bimaps::relation::member_at::right>,
1> Info=boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,
1> force_mutable=false
1> ]
1> c:\data\boost\boost_1_56_0\boost\bimap\relation\mutant_relation.hpp(265): could be 'boost::bimaps::relation::mutant_relation<TA,TB,Info,force_mutable>::mutant_relation(const int,const std::basic_string<_Elem,_Traits,_Ax> &)'
1> with
1> [
1> TA=boost::bimaps::tags::tagged<const int,boost::bimaps::relation::member_at::left>,
1> TB=boost::bimaps::tags::tagged<const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,boost::bimaps::relation::member_at::right>,
1> Info=boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,
1> force_mutable=false,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> while trying to match the argument list '(int, int)'
The same code on a linux machine compiles without errors. Any help most appreciated!
As noted in the comments below, the line
boost::bimap< int, std::string > test;
on its own will trigger similar errors. Ignore the error above regarding (int, int), I had left an earlier line in the code which was using a boost::bimap. Now removed, no significant change in the volume of errors.
I am facing strange problem.Same code is working fine in vs 2008 and VS 2010 Debug and Dubug Unicode Version but failed to compile in Release and Release Unicode.
What could be the reason for this.
This code is generating the error
struct bitset_extractor
{
typedef std::forward_iterator_tag iterator_category;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef ptrdiff_t difference_type;
bitset_extractor(const boost::dynamic_bitset<T>& bs, T *buffer)
: bs_(bs), buffer_(buffer), current_(0)
{}
bitset_extractor(const bitset_extractor& it)
: bs_(it.bs_), buffer_(it.buffer_), current_(it.current_)
{}
T& operator*()
{
return buffer_[current_];
}
bitset_extractor& operator++()
{
++current_;
return *this;
}
private:
void operator=(T const&); // unimplemented
const boost::dynamic_bitset<T>& bs_;
T * const buffer_;
unsigned int current_;
};
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(275): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'bitstream::bitset_extractor<T>' (or there is no acceptable conversion)
1> with
1> [
1> T=uint8_t
1> ]
1> C:\vikram\Project\Seurat\src\app\logitech\LogiRTP\Library\Filters\plc\common\bitstream.h(195): could be 'void bitstream::bitset_extractor<T>::operator =(const T &)'
1> with
1> [
1> T=uint8_t
1> ]
1> while trying to match the argument list '(bitstream::bitset_extractor<T>, bitstream::bitset_extractor<T>)'
1> with
1> [
1> T=uint8_t
1> ]
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(2176) : see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
1> with
1> [
1> _Iter=bitstream::bitset_extractor<uint8_t>,
1> _OutIt=bitstream::bitset_extractor<uint8_t>,
1> _UIter=bitstream::bitset_extractor<uint8_t>
1> ]
1> C:\vikram\Project\Seurat\3rdparty\boost\boost/dynamic_bitset/dynamic_bitset.hpp(1090) : see reference to function template instantiation '_OutIt std::copy<std::_Vector_const_iterator<_Myvec>,BlockOutputIterator>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=bitstream::bitset_extractor<uint8_t>,
1> _Myvec=std::_Vector_val<unsigned char,std::allocator<uint8_t>>,
1> BlockOutputIterator=bitstream::bitset_extractor<uint8_t>,
1> _InIt=std::_Vector_const_iterator<std::_Vector_val<unsigned char,std::allocator<uint8_t>>>
1> ]
1> C:\vikram\Project\Seurat\src\app\logitech\LogiRTP\Library\Filters\plc\common\bitstream.h(210) : see reference to function template instantiation 'void boost::to_block_range<uint8_t,std::allocator<_Ty>,bitstream::bitset_extractor<T>>(const boost::dynamic_bitset<Block> &,BlockOutputIterator)' being compiled
1> with
1> [
1> _Ty=uint8_t,
1> T=uint8_t,
1> Block=uint8_t,
1> BlockOutputIterator=bitstream::bitset_extractor<uint8_t>
1> ]
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(275): error C2582: 'operator =' function is unavailable in 'bitstream::bitset_extractor<T>'
1> with
1> [
1> T=uint8_t
1> ]
The problem is that your bitset_extractor is being used as an iterator, but it doesn't meet all of the requirements for an iterator.
The std::copy function is calling operator= with two bitset_extractor<uint8_t> objects as it attempts to convert the original iterator into a checked iterator. Since no checked iterator exists for user defined iterators, the checked iterator type and original iterator type are the same, resulting in a regular copy of the iterator being used.
The culprit is the _Rechecked function, which is used to convert a regular iterator into a checked iterator. This is done differently, depending on the iterator debug level; that's why your Debug build works, but not your Release build, as they have different iterator debug levels by default.
The solution is to implement operator= for bitset_extractor. If you want to use it as an iterator, it must support all of the functionality required for an iterator of it's type.
Disabling checked iterators won't help. Your iterators will still go through the _Rechecked function, no matter what you do.
Problem is solved .I added _SECURE_SCL=1 in VS Project Setting->preprocessor.
It is working fine.
I want to use a vector to hold read-only integer-matrices of the size 5x5
vector<const int[5][5]> startingPieces;
But this declaration causes a bunch of weird errors I've never ever seen before.
error C2535: 'const int (*std::allocator<_Ty>::address(const int (&)[5][5]) const)[5][5]' : member function already defined or declared
1> with
1> [
1> _Ty=const int [5][5]
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xmemory(109) : see declaration of 'std::allocator<_Ty>::address'
1> with
1> [
1> _Ty=const int [5][5]
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(429) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=const int [5][5]
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(439) : see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled
1> with
1> [
1> _Ty=const int [5][5],
1> _Alloc=std::allocator<const int [5][5]>
1> ]
1> c:\users\eric\documents\visual studio 2008\projects\testing grounds\testing grounds\main.cpp(14) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=const int [5][5]
1> ]
So, what is wrong with this declaration?
Two things - firstly vectors cannot hold const objects - see Can I use const in vectors to allow adding elements, but not modifications to the already added? for a discussion of this. And secondly they cannot hold arrays, as the things they hold must be copyable and assignable, and arrays are neither.
What you should do here is create your own matrix class that stores the 5x5 array of data and then create your vector with that.
One option is to use the array class (your implementation may support std::array or std::tr1::array; if not, you can use boost::array from the Boost libraries):
std::vector<std::array<std::array<int, 5> > >
The elements stored in the container still cannot be const; you can make the entire vector const if that works for your use case.