This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: basic_ios::fill() question
- From: Martin Sebor <sebor at roguewave dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 03 Nov 2003 16:05:05 -0700
- Subject: Re: basic_ios::fill() question
- References: <E1AGCkk-0005iK-00@tiamat>
Jerry Quinn wrote:
I was just looking at this lazy eval and wondering about whether it's actually
valid. The spec says the postconditions of basic_ios::init() are that fill()
return widen(' '). But when ctype is not present, is the exception required
to be thrown at the time fill() is called or can it occur as part of init()?
FWIW, these are interesting questions. Let me try to answer some of
them (we do something similar to libstdc++ when it comes to fill()).
My reading is that given this lazy evaluation the exception (bad_cast)
would be required to be thrown as soon (or as late) as the first call
to fill(), but that the function is not necessarily required to be
called from init(). In other words, either init() or fill() may throw
in this case.
I'm partly thinking that we could set the value during init if a ctype facet
is present, and throw if no ctype exists.
In our implementation (and I assume in yours as well) fill() is not set
in init() to make it possible to construct an object of basic_ios
specialized on a user defined charT (the object must be constructed
before it can be imbued with a locale that contains the specialization
of ctype on the same charT).
Note that there are other exceptions that can be thrown during the call
to fill() even if the facet exists (widen() calls the virtual do_widen()
which can throw if overridden).
If that doesn't work, can we specialize the basic_ios::fill function for char and
wchar_t, since we know ctype has to exist in this case?
BTW, is it possible to construct a locale with a user-defined facet in place
of ctype<char>?
Yes, as long as the facet is derived from ctype<char> (i.e., has the
same id).
Regards
Martin