Topic: std:: istreambuf_iterator does not meet the requirements for
Author: Marc<marc.glisse@gmail.com>
Date: Wed, 7 Sep 2011 11:03:20 -0700 (PDT) Raw View
Krzysztof elechowski wrote:
> As of N3242, for an input iterator (i), the type of (*i) must be a reference
> ([iterator.iterators], Table 106). However, if (i) is an instance of std::
> istreambuf_iterator< char>, the type of (*i) is char, which is not a
> reference. Inconsistent?
"reference" in Table 106 refers to the iterator_traits typedef, not to
the reference concept.
Table 107 only says that reference is convertible to T for input
iterators. Output and forward iterators do require that reference be a
reference (possibly an rvalue reference for forward iterators).
> (As a practical manifestation, this is the reason why boost:: zip_iterator
> does not work with std:: istreambuf_iterator).
In my experience, the requirement that reference be a reference in
forward iterators is best ignored. Code that tries to finess (boost)
ends up breaking more stuff than it helps. What doesn't work with
zip_iterator and istreambuf_iterator?
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?UTF-8?B?RGFuaWVsIEtyw7xnbGVy?=<daniel.kruegler@googlemail.com>
Date: Wed, 7 Sep 2011 11:03:49 -0700 (PDT)
Raw View
Am 07.09.2011 18:54, schrieb Krzysztof elechowski:
> As of N3242, for an input iterator (i), the type of (*i) must be a reference
> ([iterator.iterators], Table 106). However, if (i) is an instance of std::
> istreambuf_iterator< char>, the type of (*i) is char, which is not a
> reference. Inconsistent?
No, you are misinterpreting Table 106. Table 106 just requires that the
result type of the expression *r shall be equal to reference (in code
font) and [iterator.requirements.general] p11 says:
"In the following sections, a and b denote values of type X or const X,
difference_type and reference refer to the types
iterator_traits<X>::difference_type and iterator_traits<X>::reference,
respectively, [..]"
So, the wording does not require that the result of an input iterator
must be a real reference type, it must only match that of the typename
reference. Note also, that Table 107, which *refines* Table 106, is more
specific in regard to the expression *a:
"*a convertible to T"
Further, [istreambuf.iterator] has fixed the former definition of the
typedef pointer to /unspecified/ and the typedef reference is still
charT as in C++03, which is now a conforming implementation in regard to
the input iterator requirements.
> (As a practical manifestation, this is the reason why boost:: zip_iterator
> does not work with std:: istreambuf_iterator).
This cannot be the reason.
HTH& Greetings from Bremen,
- Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Marc <marc.glisse@gmail.com>
Date: Thu, 8 Sep 2011 14:47:30 -0700 (PDT)
Raw View
Krzysztof elechowski wrote:
> (As a practical manifestation, this is the reason why boost:: zip_iterator
> does not work with std:: istreambuf_iterator).
Actually, the reason for this is LWG issue 445 :
iterator_traits<istreambuf_iterator<char>>::reference is char& in
C++98 and char in C++11, so your code should work better next year ;-)
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]