2

次のプログラム:

#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_iteratorreference_typechar&それoperator*は戻りますchar。整形式の反復子の場合、常に?operator*を返す必要はありません。reference_type

4

1 に答える 1

3

operator*anの型の唯一の要件は、(§24.1.1/2)InputIteratorに変換可能であることです。for anvalue_typeの結果に値を割り当てるのは無意味なので、参照や任意の種類の左辺値を返すのは正しくありません。Boost は、そのプロパティをチェックするのにエラーが発生しています。operator*istreambuf_iterator

于 2011-08-09T23:40:42.413 に答える