Topic: 21.1.1 not_eof is confusing
Author: krixel@qed.pl ("Christopher Yeleighton")
Date: Tue, 26 Jul 2005 18:33:05 GMT Raw View
The name of the function, not_eof, is confusing beacuse it suggests being a
test. It is not a test and the proper usage pattern is
if(traits_type::not_eof(c) == c)
instead of
if(traits_type::not_eof(c))
It is a mistake easy to commit and it can cause runtime errors.
Chris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: Tue, 26 Jul 2005 15:46:35 CST Raw View
Christopher Yeleighton wrote:
> It is not a test and the proper usage pattern is
>
> if(traits_type::not_eof(c) == c)
Nope. If you want to use 'not_eof()' to test for "EOF" you would do
it like this:
if (traits_type::eq_int_type(traits_type::not_eof(c), c))
...
However, this is not the intention of 'not_eof()'. The use of this
function is to signal success on return, i.e. it is used like this:
int_type overflow(int_type c)
{
// whatever overfow() has to do
return traits_type::not_eof(c);
}
That is, 'not_eof()' is intended to conjure up a character, i.e. an
'int_type' value different from 'traits_type::eof()', even if the
argument 'c' is actually 'traits_type::eof()'. If you want to test
for "EOF" you would use
if (traits_type::eq_int_type(traits_type::eof(), c))
...
. or a corresponding negation of the above expression.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]