2011-08-09 3 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 모두 컴파일에 실패.

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 작동하지 않습니다 다음과 같이 MSVC 오류입니다.

여기에 무슨 일이 일어나고 있습니까? 문제를 해결하거나 해결하려면 어떻게해야합니까?

편집 : 오류의 근인은 istreambuf_iteratorreference_typechar& 인 것 같다,하지만 operator* 반환 char입니다. 잘 구성된 반복자의 경우 operator*은 항상 reference_type을 반환하지 않아야합니다.

+0

idk하지만 좋은 캐치 인 것 같습니다! :-) 아마도 메일 링리스트를 부탁 할 것입니다. –

답변

3

InputIteratoroperator* 유형의 유일한 요구 사항은 value_type (§24.1.1/2)로 변환 할 수 있다는 것입니다. istreambuf_iterator에 대해 operator*의 결과에 값을 할당하는 것은 의미가 없으므로 참조 또는 모든 종류의 lvalue를 반환하는 것은 올바르지 않습니다. 부스트가 잘못되어 해당 속성을 확인합니다.