Re: recursion and global variables
On 13 Feb., 21:00, "Daniel K. O."
<danie...@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.co.m>
wrote:
James Kanze escreveu:
And here's the first instance of undefined behavior. In modern
C++, I'd pick up the ctype facet at the start of the function,
with something like:
typedef std::ctype< char >
CType ;
CType const& ctype = std::use_facet< CType
( std::locale() ) ;
and then write this loop :
...
while ( ... && ctype.is( CType::space, ch ) )
Interesting. I would use:
while (... && isspace(ch, cin.getloc()) )
Which seems to give the same result with less typing (well, if you use
std::locale() instead of cin.getloc() anyways).
Yes, that will give the same results, because 22.1.3.1 p. 1
explicitely
says:
"Each of these functions isF returns the result of the expression:
use_facet< ctype<charT> >(loc ).is(ctype_base::F, c )".
and isspace is mentioned in its previous list.
But "less typing" is not the only criterion for a programmatic
choice,
notably not in iteration situations as in this case. James Kanze's
choice is very reasonable here, because it separates the facet
aquisition
(needed only once) from its usage (needed for each iteration step).
Now I'm wondering, is there any reason for not using the overloaded
is*() functions from <locale>, or did you just forgot them?
There is no general reason for not using the mentioned functions,
but they are just convenience function (as the title of the leading
section "22.1.3 Convenience interfaces" suggests) and there are times
where it makes more sense to use this wrapped functionality in an
explicit, unwrapped manner - And I doubt very strongly that James
Kanze
did forgot them.
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]