Re: Abi string class


Subject: Re: Abi string class
From: Sam TH (sam@uchicago.edu)
Date: Thu Feb 01 2001 - 03:27:27 CST


On Thu, Feb 01, 2001 at 07:50:44AM +0100, Mike Nordell wrote:
> This class is currently a very light wrapper around a plain char*, but I
> have tried to make it as efficient and exception safe as possible.
> Unfortunately there's a tradeof between semantics/syntax of its use, and a
> completely "safe" implementation. We want to be able to write
>
> UT_String s1("foo");
> or
> s1 = "bar";
>
> but to do this we would have to use exceptions to be "safe". Since we can't
> use exceptions this implementation is "somewhat" unsafe (it keeps a safe
> internal state, but in case of out-of-memory conditions it keeps its old
> value). To fix this we would have to forbid anything but the default
> constructor, and we would have to write assignment as
>
> if (!s1.assign("bar"))
>
> I traded safety for readability. If this turns out to be an issue of
> controversy I'll do it the "safe" way, but it would hurt readability much
> IMO.

This class looks excellent, but I have one question, which probably
stems from my lack of C++ experience:

If it would be possible to have a safer class by using
s1.assign("foo"), why can't we simply overload operator() to be
exactly the same function that assign would be?

There's probably something big I'm missing here.

Other than that, it looks cool.
           
        sam th
        sam@uchicago.edu
        http://www.abisource.com/~sam/
        GnuPG Key:
        http://www.abisource.com/~sam/key




This archive was generated by hypermail 2b25 : Thu Feb 01 2001 - 03:27:59 CST