Home

On Sep 9, 12:56 pm, "Alf P. Steinbach" <al...@start.no> wrote:

> (I'm wondering whether SharedArray should provide indexing, and/or
> perhaps keep track of the length of the array: perplexingly and almost
> paradoxically, it hasn't been needed. I'm also wondering whether there
> is some better way to steer constructor selection (in StringValue and
> StringValueOrNull) the Right Way, currently using boost::disable_if?)

One idea to help prevent StringValue's constructor from being passed a
const char array when a string literal is expected, would be to offer
a "StringLiteral" (or STRING_LITERAL) macro that clients could use to
designate the string literal initializer explicitly. (This suggestion
is based on a similar macro in Apple's CFString class.)

#define StringLiteral(a) StringValue(""a)

The double-quotes will cause a compile-time error - unless the
initializer "a" is a string literal (that is, it has double-quotes
surrounding it):

StringValue f()
{
const char s[] = "some text";

return StringLiteral(s); // Error: expected primary-expression
before '('

return StringLiteral("some text"); // OK
}

and alternately:

StringValue sv( StringLiteral("a string literal"));

Although I am not a big fan of macros, I will admit that they
occassionally have their uses.

Greg

previous
next

Re: How to use std::cout to output a char as a number?
Re: What version control can I use with VC++6?
Re: Interface Programming the basics
trim start and trailing space chars from string
Re: which language allows you to change an argument's value?
Pajacyk
Krwinka
Fundacja Avalon
Mimo Wszystko
Niechciane i Zapomniane