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