Re: char_traits link problem
Re: char_traits link problem
- Subject: Re: char_traits link problem
- From: Sandy Martel <email@hidden>
- Date: Fri, 7 May 2004 08:52:15 -0400
Le 04-05-06, ` 22:39, Jim Crafton a icrit :
Hi,
I have just recently gotten 10.3.3 installed as well as the latest and
greatest XCode build from the dev downloads site. However I am having
problems linking when building under GCC 3.3. I have code that uses
std::basic_string<unsigned short>. Everything compiles fine, but the
framework cannot be linked as GCC complains about missing definitions
for stuff like std::char_traits<unsigned short>::copy(), etc.
I googled around and found this link
http://gcc.gnu.org/ml/libstdc++/2003-07/msg00279.html from Matt
Austern, who (as of Jul 2003) worked at Apple. There was talk
acknowledging the problem, as well as a patch submitted by Matt.
However I am at a loss as to how to proceed with any sort of fix. Has
anyone else encountered this? How do you work around/fix it?
Many thanks,
In Stroustrup's "C++ Programming Language" chapter 20.2.1, it is said
that you need to provide your own specialization of std::char_traits<>.
Here is my definition of unsigned short strings:
/*
* UniCharString.h
*
*
* Created by Sandy Martel on Fri Jan 02 2004.
* Copyright (c) 2004 __MyCompanyName__. All rights reserved.
*
*/
#ifndef _H_UNICHARSTRING
#define _H_UNICHARSTRING
#include <Carbon/Carbon.h>
#include <string>
namespace std
{
template<> struct char_traits<UniChar>
{
typedef UniChar char_type;
typedef wint_t int_type;
typedef streamoff off_type;
typedef wstreampos pos_type;
typedef mbstate_t state_type;
static void assign( char_type &c1, const char_type &c2 )
{
c1 = c2;
}
static bool eq( const char_type &c1, const char_type &c2 )
{
return c1 == c2;
}
static bool lt( const char_type &c1, const char_type &c2 )
{
return c1 < c2;
}
static int compare( const char_type *s1, const char_type *s2, size_t n
)
{
size_t i = 0;
while ( i < n and *s1 == *s2 )
{
++i;
++s1;
++s2;
}
return i >= n ? 0 : *s1 - *s2;
}
static size_t length( const char_type *s )
{
const char_type *p = s;
while ( *p != 0 )
++p;
return p - s;
}
static const char_type *find( const char_type *s, size_t n, const
char_type &a )
{
size_t i = 0;
while ( i < n and a != *s )
{
++i;
++s;
}
return i >= n ? 0 : s;
}
static char_type *move( char_type *s1, const char_type *s2, int_type n
)
{
return (char_type *)memmove( s1, s2, n * sizeof( char_type ) );
}
static char_type *copy( char_type *s1, const char_type *s2, size_t n )
{
return (char_type *)memcpy( s1, s2, n * sizeof( char_type ) );
}
static char_type *assign( char_type *s, size_t n, char_type a )
{
size_t i = 0;
char_type *p = s;
while ( i < n )
{
*p = a;
++i;
++p;
}
return s;
}
static char_type to_char_type( const int_type &c )
{
return char_type( c );
}
static int_type to_int_type( const char_type &c )
{
return int_type( c );
}
static bool eq_int_type( const int_type &c1, const int_type &c2 )
{
return c1 == c2;
}
static int_type eof()
{
return static_cast<int_type>(EOF);
}
static int_type not_eof( const int_type &c )
{
return eq_int_type( c, eof() ) ? 0 : c;
}
};
}
typedef std::basic_string<UniChar> UniCharString;
#endif
Sandy.
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.