Allow use of c_str() when <charT> != char http://gcc.gnu.org/ml/libstdc++-prs/2000-q4/msg00004.html This allows use on std::wstring, and others.
Diff
legacy/gcc/libstdc++/std/bastring.h | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
@@ -38,6 +38,10 @@
#include <alloc.h>
#ifdef __HAIKU__
# include <config/types.h>
#endif
extern "C++" {
class istream; class ostream;
@@ -61,12 +65,10 @@
#endif
#if defined(__BEOS__) || defined(__HAIKU__)
typedef long int32;
typedef volatile long vint32;
extern "C" int32 atomic_add(vint32* value, int32 addvalue);
#endif
#ifdef __HAIKU__
extern "C" __haiku_int32 atomic_add(volatile __haiku_int32* value,
__haiku_int32 addvalue);
#endif
template <class charT, class traits = string_char_traits<charT>,
class Allocator = alloc >
@@ -79,9 +81,9 @@
charT* data () { return reinterpret_cast<charT *>(this + 1); }
charT& operator[] (size_t s) { return data () [s]; }
#if defined(__BEOS__) || defined(__HAIKU__)
charT* grab () { if (selfish) return clone (); atomic_add((vint32*) &ref, 1); return data (); }
void release() { if (atomic_add((int32*) &ref, -1) == 1) delete this; }
#ifdef __HAIKU__
charT* grab () { if (selfish) return clone (); atomic_add((volatile __haiku_int32*) &ref, 1); return data (); }
void release() { if (atomic_add((__haiku_int32*) &ref, -1) == 1) delete this; }
#else
charT* grab () { if (selfish) return clone (); ++ref; return data (); }
#if defined __i486__ || defined __i586__ || defined __i686__
@@ -119,7 +121,7 @@
#else
void release () { if (--ref == 0) delete this; }
#endif
#endif
#endif
inline static void * operator new (size_t, size_t);
inline static void operator delete (void *);
inline static Rep* create (size_t);
@@ -348,7 +350,10 @@
public:
const charT* c_str () const
{ if (length () == 0) return ""; terminate (); return data (); }
{
static const charT null_str[1] = {0};
if (length () == 0) return null_str; terminate (); return data ();
}
void resize (size_type n, charT c);
void resize (size_type n)
{ resize (n, eos ()); }
@@ -405,7 +410,13 @@
int compare (const basic_string& str, size_type pos = 0, size_type n = npos) const;
int compare (const charT* s, size_type pos, size_type n) const;
int compare (size_type pos, size_type n, const charT* s) const
{ return compare(s, pos, n); }
int compare (const charT* s, size_type pos = 0) const
{ return compare (s, pos, traits::length (s)); }