【问题标题】:Why does std::istreambuf_iterator fail boost's SinglePassIterator concept check?为什么 std::istreambuf_iterator 无法提升 SinglePass Iterator 概念检查?
【发布时间】:2011-08-09 23:08:27
【问题描述】:

以下程序:

#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_iteratorreference_typechar&amp;,但它是operator* 返回char。对于格式良好的迭代器,operator* 不应该总是返回reference_type吗?

【问题讨论】:

  • idk,但这似乎是一个不错的选择! :-) 也许在 boost 邮件列表中询问它。

标签: c++ boost iterator range concept


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-11-05
    • 2016-07-28
    • 2023-02-26
    • 1970-01-01
    • 2020-10-24
    • 2021-02-20
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    相关资源
    最近更新 更多