为什么std :: istreambuf_iterator失败提升SinglePass Iterator概念检查?

时间:2011-08-09 23:08:27

标签: c++ boost iterator range concept

以下计划:

#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::copy这样的Boost.Range算法无法与istreambuf_iterator一起使用。

这里发生了什么?我该怎么做才能解决它或解决它?

编辑:错误的最直接原因似乎是istreambuf_iterator的{​​{1}}为reference_type,但它是char&返回{ {1}}。对于格式良好的迭代器,operator*总是不应该返回char

1 个答案:

答案 0 :(得分:3)

operator*的{​​{1}}类型的唯一要求是它可以转换为InputIterator(§24.1.1/ 2)。由于为value_type的{​​{1}}的结果赋值是没有意义的,因此返回引用或任何类型的左值都是不正确的。检查该属性时Boost是错误的。