
Note: I'm using boost 1.33.1 here Sebastian Redl wrote:
This code should really not give you any warnings. (And doesn't on GCC, though I doubt that'll help you.) C4244, so that others don't have to look it up, is the "conversion with possible data loss" warning. This indicates that in VC++, make_counting_iterator returns a counting_iterator<long> or even <__int64>. Can somebody with that compiler post the output of this line? std::cout << typeid(boost::make_counting_iterator(1)).name() << std::endl;
A simple workaround for this particular warning ought to be to
Using Visual Studio .NET 2003, the output of this was: class boost::counting_iterator<int,struct boost::use_default,struct boost::use_default> as it should be. directly instantiate counting_iterators with their template parameter set correctly.
Sebastian Redl
The problem appears to be when operator += is called on the iterator. Here, the difference_type of the iterator, boost::iterator_facade<Derived,Value,CategoryOrTraversal,Reference,Difference>::difference_type, which is equal to boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::difference, is __int64. The counting_iterator_base uses the following typedef: typedef typename detail::ia_dflt_help< Difference , mpl::eval_if< is_numeric<Incrementable> , numeric_difference<Incrementable> , iterator_difference<Incrementable> > >::type difference; It seems this has been discovered before: http://lists.boost.org/Archives/boost/2004/07/69347.php The actual warnings I received compiling this code were: -------------------------------------------------------- Compiling... BoostTest1.cpp d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(481) : warning C4244: '+=' : conversion from 'boost::iterators::enabled<__formal>::base<T>::type' to 'std::vector<_Ty>::size_type', possible loss of data with [ __formal=true, T=std::iterator_traits<boost::counting_iterator<int,boost::use_default,boost::use_default>>::difference_type ] and [ _Ty=int ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(498) : see reference to function template instantiation 'void std::_Distance2<_InIt,_Diff>(_RanIt,_RanIt,_Diff &,std::random_access_iterator_tag)' being compiled with [ _InIt=boost::counting_iterator<int,boost::use_default,boost::use_default>, _Diff=std::vector<int>::size_type, _RanIt=boost::counting_iterator<int,boost::use_default,boost::use_default> ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(657) : see reference to function template instantiation 'void std::_Distance<_Iter,std::vector<_Ty>::size_type>(_InIt,_InIt,_Diff &)' being compiled with [ _Iter=boost::counting_iterator<int,boost::use_default,boost::use_default>, _Ty=int, _InIt=boost::counting_iterator<int,boost::use_default,boost::use_default>, _Diff=std::vector<int>::size_type ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(634) : see reference to function template instantiation 'void std::vector<_Ty>::_Insert<_Iter>(std::vector<_Ty>::iterator,_Iter,_Iter,std::forward_iterator_tag)' being compiled with [ _Ty=int, _Iter=boost::counting_iterator<int,boost::use_default,boost::use_default> ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(366) : see reference to function template instantiation 'void std::vector<_Ty>::insert<_Iter>(std::vector<_Ty>::iterator,_Iter,_Iter)' being compiled with [ _Ty=int, _Iter=boost::counting_iterator<int,boost::use_default,boost::use_default> ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(343) : see reference to function template instantiation 'void std::vector<_Ty>::_Construct<_Iter>(_Iter,_Iter,std::input_iterator_tag)' being compiled with [ _Ty=int, _Iter=boost::counting_iterator<int,boost::use_default,boost::use_default> ] g:\Projects\BoostTest1\BoostTest1.cpp(15) : see reference to function template instantiation 'std::vector<_Ty>::vector<boost::counting_iterator<Incrementable,CategoryOrTraversal,Difference>>(_Iter,_Iter)' being compiled with [ _Ty=int, Incrementable=int, CategoryOrTraversal=boost::use_default, Difference=boost::use_default, _Iter =boost::counting_iterator<int,boost::use_default,boost::use_default> ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\boost\iterator\iterator_adaptor.hpp(329) : warning C4244: '+=' : conversion from 'boost::iterator_facade<Derived,Value,CategoryOrTraversal,Reference,Difference>::difference_type' to 'int', possible loss of data with [ Derived=boost::counting_iterator<int,boost::use_default,boost::use_default>, Value=const boost::mpl::identity<const int>::type, CategoryOrTraversal=boost::mpl::identity<boost::random_access_traversal_tag>::type, Reference=boost::mpl::identity<const int &>::type, Difference=boost::mpl::identity<boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::difference>::type ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\boost\iterator\iterator_adaptor.hpp(327) : while compiling class-template member function 'void boost::iterator_adaptor<Derived,Base,Value,Traversal,Reference,Difference>::advance(boost::iterator_facade<Derived,Value,CategoryOrTraversal,Reference,Difference>::difference_type)' with [ Derived=boost::counting_iterator<int,boost::use_default,boost::use_default>, Base=int, Value=const int, Traversal=boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::traversal, Reference=const int &, Difference=boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::difference, CategoryOrTraversal=boost::mpl::identity<boost::random_access_traversal_tag>::type ] d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\boost\iterator\counting_iterator.hpp(153) : see reference to class template instantiation 'boost::iterator_adaptor<Derived,Base,Value,Traversal,Reference,Difference>' being compiled with [ Derived=boost::counting_iterator<int,boost::use_default,boost::use_default>, Base=int, Val ue=const int, Traversal=boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::traversal, Reference=const int &, Difference=boost::detail::counting_iterator_base<int,boost::use_default,boost::use_default>::difference ] g:\Projects\BoostTest1\BoostTest1.cpp(12) : see reference to class template instantiation 'boost::counting_iterator<Incrementable,CategoryOrTraversal,Difference>' being compiled with [ Incrementable=int, CategoryOrTraversal=boost::use_default, Difference=boost::use_default ]