以下程序:
#include <boost/range/concepts.hpp>
#include <iterator>
#include <istream>
using boost::range_detail::SinglePassIteratorConcept;
int main()
{
BOOST_CONCEPT_ASSERT(( SinglePassIteratorConcept<std::istreambuf_iterator<char>> ));
}
无法同时使用 MSVC 和 gcc 进行编译。MSVC错误如下:
D:\libraries\boost\boost/range/concepts.hpp(157) : error C2440: 'initializing' : cannot convert from 'char' to 'char &'
D:\libraries\boost\boost/range/concepts.hpp(147) : while compiling class template member function 'boost::range_detail::SinglePassIteratorConcept<Iterator>::~SinglePassIteratorConcept(void)'
with
[
Iterator=std::istreambuf_iterator<char,std::char_traits<char>>
]
D:\libraries\boost\boost/concept/detail/has_constraints.hpp(42) : see reference to class template instantiation 'boost::range_detail::SinglePassIteratorConcept<Iterator>' being compiled
with
[
Iterator=std::istreambuf_iterator<char,std::char_traits<char>>
]
D:\libraries\boost\boost/concept/detail/msvc.hpp(58) : see reference to class template instantiation 'boost::concepts::not_satisfied<Model>' being compiled
with
[
Model=boost::range_detail::SinglePassIteratorConcept<std::istreambuf_iterator<char,std::char_traits<char>>>
]
test.cpp(10) : see reference to class template instantiation 'boost::concepts::require<Model>' being compiled
with
[
Model=boost::range_detail::SinglePassIteratorConcept<std::istreambuf_iterator<char,std::char_traits<char>>>
]
D:\libraries\boost\boost/range/concepts.hpp(160) : error C2440: 'initializing' : cannot convert from 'char' to 'char &'
因此,Boost.Range 等算法boost::copy
不适用于istreambuf_iterator
.
这里发生了什么?我可以做些什么来修复它或解决它?
编辑:错误的直接原因似乎是istreambuf_iterator
它reference_type
是char&
,但它的operator*
回报char
。对于格式良好的迭代器,不应该operator*
总是返回reference_type
吗?