Re: libpq++ and strings. - Mailing list pgsql-interfaces

From J. T. Vermeulen
Subject Re: libpq++ and strings.
Date
Msg-id 20010517145934.W14645@cistron.nl
Whole thread Raw
In response to libpq++ and strings.  (Carlos Moreno <moreno@mochima.com>)
List pgsql-interfaces
On Wed, 16 May 2001, Carlos Moreno wrote:

> I wonder why all the string parameters and return values 
> are expressed in the form of char * or const char * ? 

Performance would be one reason, I'd say.  const char * is easier to tune, and
of course the underlying library uses const char *'s anyway.  Also of course,
a string is easily constructed from a const char * but the other way needs an
explicit method call.

OTOH I do think you have a point w.r.t. the obvious mistakes to make, and the
lack of help from the compiler in spotting them.


> Why not just changing all the parameters and return 
> values to `const string &' and/or `string' ?

One possible tradeoff (and one I was leaning towards) is to take string 
parameters (so passing const char [] will still work) but return const char * 
in case you don't need the extras of a full C++ string.  Unfortunately this
doesn't help with the comparison-with-string-constant problem you cite.

I guess this one boils down to how important performance is.  One thing I'd
like to do about it in the upcoming version is to provide type-safe access to
the tuples.  There'd still be a GetValue() returning const char *, but you
wouldn't need to use it the way you showed in your example, because you'd be
able to read it simply as a native bool.


Jeroen



pgsql-interfaces by date:

Previous
From: Carlos Moreno
Date:
Subject: libpq++ and strings.
Next
From: Chris Hayner
Date:
Subject: Re: help with programming