C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why is tellg not const?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Alf P. Steinbach
Guest





PostPosted: Tue Sep 13, 2005 8:23 pm    Post subject: Why is tellg not const? Reply with quote



Why is tellg not const?

(This is the third attempted posting of this question: it can't be rejected
for ever, can it?)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

---
[ 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 ]

Back to top
Howard Hinnant
Guest





PostPosted: Tue Sep 13, 2005 9:45 pm    Post subject: Re: Why is tellg not const? Reply with quote



In article <432665de.186071859 (AT) news (DOT) individual.net>,
[email]alfps (AT) start (DOT) no[/email] (Alf P. Steinbach) wrote:

Quote:
Why is tellg not const?

Consider:

#include <streambuf>
#include <istream>
#include <cassert>

struct my_stream_buf
: public std::streambuf
{
typedef std::streambuf base;
protected:
virtual base::pos_type seekoff(base::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode which =
std::ios_base::in |
std::ios_base::out)
{throw 0; return base::pos_type(-1);}
};

int main()
{
my_stream_buf sb;
std::istream in(&sb);
assert(in.good());
in.tellg();
assert(in.good());
}

The second assert fires. tellg() has changed the observable state of
the istream in this example.

That being said, I can sympathize with your intent. tellg does seem
like a non-modifying function and a seekoff that throws while seeking to
the current position is pathological. If we were redesigning the I/O
classes today I would look for a way to avoid this contradiction
(perhaps a const interface in the streambuf to report current position
which could not throw).

-Howard

---
[ 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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.