开发者

Why does std::istreambuf_iterator fail boost's SinglePassIterator concept check?

The following program:

#include <boost/range/concepts.hpp>
#include <iterator>
#include <istream>

using boost::range_detail::SinglePassIteratorConcept;


int main()
{
    BOOST_CONCEPT_ASSERT(( SinglePassIteratorConcept<std::istreambuf_iterator<char>> ));
}

Fails to compile with both MSVC and gcc. The MSVC error is as follows:

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 &'

As a result, Boost.Range algorithms like boost::copy do not work with istreambuf_iterator.

What is going on here? What can I do to fix it or work around it?

EDIT: The proximate cause of the error seems to be that istreambuf_iterator's reference_type is char&, but it's operator* returns char. For a well-formed iterator, shouldn't operator* always return reference_type?


The only requirement of the type of operator* of an InputIterator is that it be convertible to value_type (§24.1.1/2). Since it's meaningless to assign a value to the result of operator* for an istreambuf_iterator, it would be incorrect for it to return a reference or any kind of lvalue. Boost is in error to check for that property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜