* B.D.:
Can anyone explain way the transformation to upper case doesn't work
correctly in the following code if PROBLEM is defined but works correctly if
it's not defined? I'm using VC 7.1
#include <locale>
#include <string>
#include <algorithm>
#define PROBLEM
struct ToUpper
{
ToUpper(std::locale const& locale) : mLocale(locale) {}
char operator() (char c) const { return std::toupper(c,mLocale); }
std::locale const& mLocale;
};
#ifdef PROBLEM
std::locale my_locale( "Swedish" );
#endif
int main ()
{
#ifndef PROBLEM
std::locale my_locale( "Swedish" );
#endif
std::string s("abc едц");
std::transform( s.begin(), s.end(), s.begin(), ToUpper(my_locale) );
return 0;
}
I could reproduce your problem with Visual C++ 7.1, where if PROBLEM is
defined (global instance of 'my_local') the local name is reported as
"Swedish_Sweden.1252", but the transformed string as "ABC едц".
The problem could not be reproduced using g++ 3.4.4, since that compiler
doesn't support the "Swedish" locale, at least not without doing
something special.
Note: the standard only mandates support for the "C" and "" locales, and
is self-contradictory on what other locale names can be (only
standard C locale names, whatever they are, or implementation defined
names).
So really the code should have a try-catch.
The problem with Visual C++ 7.1 likely to be a library implementation
bug due to order-of-initialization of globals.
--
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?