2011-08-09 6 views
2

次のプログラム:std :: istreambuf_iteratorがなぜブーストのSinglePassIteratorコンセプトチェックに失敗するのですか?

#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では動作しません。

ここでは何が起こっていますか?それを修正したり回避したりするにはどうすればよいですか?

EDIT:エラーの近因はistreambuf_iteratorreference_typechar&であることのようですが、それはoperator*戻りcharです。整形式イテレータの場合、operator*は常にreference_typeを返すべきではありませんか?

+0

idkですが、それは良いキャッチだと思われます! :-)おそらくブーストメーリングリストでそれを尋ねます。 –

答えて

3

InputIteratoroperator*のタイプの唯一の要件は、value_type(§24.1.1/ 2)に変換可能であることです。 istreambuf_iteratorにはoperator*の結果に値を代入するのは無意味なので、参照や任意の種類の左辺値を返すのは間違いです。 Boostがそのプロパティをチェックするのに間違っています。

関連する問題