BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

toupper
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Fraser Ross
Guest





PostPosted: Tue Aug 30, 2005 2:14 pm    Post subject: toupper Reply with quote



I don't have access to toupper in locale.h in the std namespace but its in
the global namespace. Is this a stlport bug with bcb6? This applies to the
similar functions too.

Fraser.


Back to top
Chris Uzdavinis (TeamB)
Guest





PostPosted: Tue Aug 30, 2005 2:39 pm    Post subject: Re: toupper Reply with quote



"Fraser Ross" <fraserATmembers.v21.co.unitedkingdom> writes:

Quote:
I don't have access to toupper in locale.h in the std namespace but its in
the global namespace. Is this a stlport bug with bcb6? This applies to the
similar functions too.

You shouln't include locale.h, but instead include <locale>. Perhaps
that puts it in the proper namespace?

--
Chris (TeamB);

Back to top
liz
Guest





PostPosted: Tue Aug 30, 2005 2:40 pm    Post subject: Re: toupper Reply with quote



On Tue, 30 Aug 2005 15:14:51 +0100, Fraser Ross wrote:

Quote:
I don't have access to toupper in locale.h in the std namespace but its in
the global namespace. Is this a stlport bug with bcb6? This applies to the
similar functions too.

#include <locale>
--
liz

Back to top
Fraser Ross
Guest





PostPosted: Tue Aug 30, 2005 2:42 pm    Post subject: Re: toupper Reply with quote


"Chris Uzdavinis (TeamB)"
Quote:
You shouln't include locale.h, but instead include <locale>. Perhaps
that puts it in the proper namespace?

Thats what I have included.

Fraser.



Back to top
Darko Miletic
Guest





PostPosted: Tue Aug 30, 2005 2:47 pm    Post subject: Re: toupper Reply with quote

Fraser Ross wrote:
Quote:
I don't have access to toupper in locale.h in the std namespace but its in
the global namespace. Is this a stlport bug with bcb6? This applies to the
similar functions too.

Fraser.


BCB 6 sp4 - This code compiles and executes as expected. What exactly

does not work in your case?
Please show the minimal code sample that reproduces the problem you
describe.

#include <iostream>
#include <locale>

int main(int argc, char* argv[])
{
std::cout << static_cast << std::endl;
return 0;
}

Darko

Back to top
Fraser Ross
Guest





PostPosted: Tue Aug 30, 2005 2:56 pm    Post subject: Re: toupper Reply with quote


"Darko Miletic"
Quote:
#include <iostream
#include
int main(int argc, char* argv[])
{
std::cout << static_cast std::endl;
return 0;
}

Are you sure you are not calling the C library function with the same name?
Try this: std::toupper('a', std::locale::classic());

Fraser.



Back to top
Chris Uzdavinis (TeamB)
Guest





PostPosted: Tue Aug 30, 2005 3:14 pm    Post subject: Re: toupper Reply with quote

"Fraser Ross" <fraserATmembers.v21.co.unitedkingdom> writes:

Quote:
"Chris Uzdavinis (TeamB)"
You shouln't include locale.h, but instead include <locale>. Perhaps
that puts it in the proper namespace?

Thats what I have included.

Well, then it sounds like a bug in the RTL somewhere. Borland's
strange way of promoting things into the global namespace depending on
if you use the .h in the header name or not sometimes causes strange
problems.

Some standard headers use the whole std namespace, so if you include
them with the .h, you get a LOT of stuff pulled in. Other files,
however, individually use the items that are to be exposed from that
header. I like this approach better, though pulling things into
global namespace at all seems a hack that causes more problems than it
solves. (I just wish it'd go away, and people had to use the proper
namespace, and the langauge dictates they should be using.)

But definately, if BCB *only* exposes a standard name in the global
namespace, that's a problem.

--
Chris (TeamB);

Back to top
Darko Miletic
Guest





PostPosted: Tue Aug 30, 2005 3:34 pm    Post subject: Re: toupper Reply with quote

Fraser Ross wrote:
Quote:
Are you sure you are not calling the C library function with the same name?
Try this: std::toupper('a', std::locale::classic());

Yes you are right. The bug is located in ctype.h header at line 159:

#if defined( __USELOCALES__ )
..
..
//Here are toupper and tolower defined as inline functions that call C
RTL functions.
//That was done I guess because of some thing inside RW STL
#endif //__USELOCALES__

To fix this just change the line 159 to look like this:

#if defined( __USELOCALES__ ) && defined(_USE_OLD_RW_STL)


After this change this code compiles fine both with STLport and RW STL

#include <iostream>
#include <locale>

int main(int argc, char* argv[])
{
std::cout << static_cast std::locale::classic()))
<< std::endl;
return 0;
}

Back to top
Fraser Ross
Guest





PostPosted: Tue Aug 30, 2005 4:26 pm    Post subject: Re: toupper Reply with quote

Thanks. I've only just seen your message becuase I had trouble with my ISP.

Fraser.


Back to top
Fraser Ross
Guest





PostPosted: Tue Aug 30, 2005 6:18 pm    Post subject: Re: toupper Reply with quote

Is it necessary to include locale before ctype to have access to all the
functions or vice versa or either first? When I do this I get the error
towlower is not a member of std at end of the ctype.h file and also
similarly with towupper.

Also there is a problem with using tolower in locale with a const char.

Making your change, including locale before ctype and commenting out 2 lines
in ctype.h gets one of my units compiling.

Fraser.


Back to top
Darko Miletic
Guest





PostPosted: Tue Aug 30, 2005 9:57 pm    Post subject: Re: toupper Reply with quote

Fraser Ross wrote:
Quote:
Is it necessary to include locale before ctype to have access to all the
functions or vice versa or either first? When I do this I get the error
towlower is not a member of std at end of the ctype.h file and also
similarly with towupper.

These two functions are part of C RTL. They are not defined in locale
header.
And that is because the std::tolower/toupper is template function that
looks like this:

template <class charT>
charT toupper (charT c, const locale& loc) const;

So to use equivalent of C RTL towupper use function like this:
std::toupper<wchar_t> ('a',std::locale::classic());

Quote:
Also there is a problem with using tolower in locale with a const char.

What problem?

Quote:
Making your change, including locale before ctype and commenting out 2 lines
in ctype.h gets one of my units compiling.

There is no need to include ctype.h use instead new header cctype .
#include <cctype>


This program compiles and executes OK:

#include <iostream>
#include <locale>

int main(int argc, char* argv[])
{
std::cout << std::toupper('a', std::locale::classic())
<< std::endl;
std::cout << std::tolower('A', std::locale::classic())
<< std::endl;
return 0;
}

Note: You can not test directly wcout since STLport has a bug that
prevents wide char streams from working.

Darko

Back to top
Fraser Ross
Guest





PostPosted: Wed Aug 31, 2005 11:03 am    Post subject: Re: toupper Reply with quote


"Darko Miletic"
Quote:
Also there is a problem with using tolower in locale with a const char.

What problem?

template <class _CharT>
inline _CharT toupper(_CharT c, const locale& loc) {
return (use_facet<ctype<_CharT> >(loc)).toupper(c);
}

The error here is toupper is not a member of ctype<const char>.


Fraser.



Back to top
Darko Miletic
Guest





PostPosted: Wed Aug 31, 2005 12:42 pm    Post subject: Re: toupper Reply with quote

Fraser Ross wrote:
Quote:
"Darko Miletic"

Also there is a problem with using tolower in locale with a const char.

What problem?


template <class _CharT
inline _CharT toupper(_CharT c, const locale& loc) {
return (use_facet(loc)).toupper(c);
}

The error here is toupper is not a member of ctype<const char>.


Well, in STLport ctype class is implemented in a bit strange way. There
is only explicit instantiation for type char and wchar_t, not for const
char or const wchar_t. It looks like this simplified(taken form
<BCBfolder>includestl_ctype.h):

// ctype<> template

template <class charT> class ctype {};
template <class charT> class ctype_byname {};

//ctype specializations

_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC ctype<char> : public locale::facet, public
ctype_base
//... implementation for char

_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet,
public ctype_base
//... implementation for wchar_t

For anything other than char/wchar_t ctype is just an empty class, at
least for borland compiler.

So in order to tweak around this issue you will have to explicitly say
which type instatiation to use for tolower/toupper like in this example:

#include <iostream>
#include <string>
#include <locale>


int main() {

const char cchUpp = 'A';
const char cchDown = 'a';
char chUpp = 'A';
char chDown = 'a';

//const char (will not compile on bcb6)
std::cout << std::toupper(cchDown,std::locale::classic()) << std::endl;
std::cout << std::tolower(cchUpp,std::locale::classic()) << std::endl;

//just char
std::cout << std::toupper(chDown,std::locale::classic()) << std::endl;
std::cout << std::tolower(chUpp,std::locale::classic()) << std::endl;

//const char (this one will)
std::cout << std::toupper std::endl;
std::cout << std::tolower std::endl;

return 0;
}

It is a bit ugly but that is bcb/STLport pair. Here are the test results
for other compilers:
- MSVC 7.1 w. dinkumware STL compiles OK
- gcc 3.3.4 with libstdc++ compiles OK
- gcc 3.3.4 with STLPort 5.0 compiles OK

Darko

Back to top
Fraser Ross
Guest





PostPosted: Wed Aug 31, 2005 1:39 pm    Post subject: Re: toupper Reply with quote

I still have trouble calling std::toupper('a'); I can call these functions:
std::toupper('a', std::locale::classic());
std::tolower('a');
std::tolower('a', std::locale::classic());

I get the error:
E2285 Could not find a match for '_STL::toupper<_CharT>(char)'

I have had to comment out these lines at the end of ctype.h:
//using std::tolower; // FR
//using std::toupper; // FR
//using std::towlower; // FR
//using std::towupper; // FR

Fraser.


Back to top
Duane Hebert
Guest





PostPosted: Wed Aug 31, 2005 1:56 pm    Post subject: Re: toupper Reply with quote


"Fraser Ross" <fraserATmembers.v21.co.unitedkingdom> wrote

Quote:
I still have trouble calling std::toupper('a'); I can call these
functions:
std::toupper('a', std::locale::classic());
std::tolower('a');
std::tolower('a', std::locale::classic());

I get the error:
E2285 Could not find a match for '_STL::toupper<_CharT>(char)'

I had pretty much the same problem. I had some code using
std::toupper() with a const char* and no locale. It was working
until I include boost/format.hpp. Then it failed to compile
(same error) unless I gave it a default locale. There was
a thread about this in this group. It looked like ctype was
getting pulled in from somewhere and toupper() was
getting confused with std::toupper though I'm not
sure.

I "fixed" it like this:

std::locale(loc);
for(size_t i = 0, len = str.size(); i < len; ++i)
str[i] = std::toupper(str[i],loc);
}

In my MSVC code, the default loc works but
in my Borland code, I have to give it a locale
arg.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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.