2016-05-31 11 views
0

내가 수행하여 vector에 단어를 깰 수 비주얼 스튜디오에서 string foo을 감안할 때 :Lvalue istringstream istream_iterator에 필요합니까?

vector fooVec{ istream_iterator<string>(istringstream(foo)), istream_iterator<string>() }; 

그러나 이것은 GCC 5.1에서 컴파일되지 않습니다. 나는 오류를 얻을 :

invalid initialization of non-const reference of type std::istream_iterator<std::basic_string<char> >::istream_type& {aka std::basic_istream<char>& } from an rvalue of type std::basic_istream<char>

는 지금은 GCC가 우리 자신의 Jonathan Wakely에 의해 고정이 a bug을 한 것으로 알고있다. 이것은 버그의 연장인가요? 아니면 Rvalue istringstream을 사용하는 것은 불법입니까?

답변

2

이것은 gcc 버그가 아니며 evil MSVC extension입니다. std::istream_iterator::istream_iteraor()에는 왼쪽 값 참조가 필요합니다. istringstream(foo)은 임시 gcc이므로 올바르게 임시 값을 lvalue 참조에 바인드 할 수 없다고 알려줍니다.

MSVC에서 작동하는 이유는 이전에 언급 한 임시 변수가 좌변 치 참조에 바인딩 될 수 있기 때문입니다. 이렇게하면 비표준 코드가 MSVC에서 작동합니다.

그래서

Is this an extension of that bug or should it be illegal for me to use an Rvalue istringstream here?

없음이 버그가 아닙니다하고 istream_iterator을 구성하기 위해 여기가 아닌 일시적 스트림을 필요로 대답 없습니다.