Re: Where to place a constant?

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 02/16/04


Date: Mon, 16 Feb 2004 13:27:29 +0100


"Lasse Skyum" <no spam> wrote:

>> >Suggestions anyone?
>>
>> You'd be much better off using std::string.
>
> Okay... maybe so, but I don't really se why? CBL_String helps me in
> manny different ways and has never been the source of any bugs in my
> programs.
>
> Does std::string have a shared empty string or maybe it uses NULL as
> an empty string?

I'd say that's implementation specific. Anyway, why do you think you
need such a shared ... ehm, nothing? I mean, an empty string has no
data to share. Its size is 0, so there is nothing to read from it, so
why would you need to share that 'nothing' between empty strings? Btw:
Do you actually have that many empty strings in real programs?

> If std::string also allocated an empty string if not initialized, then
> I see no reason what so ever to use it...
>
> BTW, I've also written my own CBL_ArrayList as an equivalent to
> vector... ony differenceis the ability to automatically shrink if a
> flag is set.

If you're happy with your own containers and strings, it's IMHO ok to
use them. Of course, you'll limit code reusability somewhat.

> For some odd reason it also outperformes vector in my
> insert/remove benchmarks, probably just a bunch of settings or
> something.

That again depends on the implementation you use, not only on settings.

> I'm sure all this is also in Boost (or whatever C++ extentions there
> might be) but I've learned so much be writing it my self.

That's of course a very good reason to write your own ones, but it is
not a reason to use them in real code :-)

> Anyway... I just wanted to have an initialized constant :-) Might
> also be relevant for other things!

If you want to be sure that your constant is initialized before other
static objects, you might want to use the singleton pattern.



Relevant Pages

  • Re: Unable to connect a website using LWP
    ... shouldn't have any reason to. ... Hmm. ... inequality operations (testing if the status code returned is>= 200 ... you compare an empty string to a number using the == operator, ...
    (comp.lang.perl.modules)
  • VBS gets empty string
    ... the VBS gets empty string from COM. ... Dim mystring ... MsgBox' in some reason, ...
    (microsoft.public.vc.atl)
  • Re: coredump in df_readascii
    ... OS: AS3 ... Reason: df_commentschars is null. ... Strange. ... You can set it to an empty string, ...
    (comp.graphics.apps.gnuplot)
  • Re: Where to place a constant?
    ... > Okay... ... > no reason what so ever to use it... ... Learning is always a good reason to re-write certain standard classes. ...
    (comp.lang.cpp)