Boost logo

Boost :

From: Jason House (jhouse_at_[hidden])
Date: 2003-03-05 10:51:13

James Curran wrote:
> Jason House wrote:
> > Another quesion:
> >
> > if
> > template <const char *S> SomeClass { ...};
> > extern const char* MyParam_1 = "MyParam";
> > extern const char* MyParam_2 = "MyParam";
> >
> > then would
> > typeof(SomeClass<MyParam_1>) == typeof(SomeClass<MyParam_2>)
> > be true?
> I guess the correct answer here is "Not Necessarily". Remember that
> the template is using the char*, not the text literal, as it's parameter. A
> compiler may pool the identical text literals and have both MyParam_1 and
> MyParam_2 point to the same address (inwhich case that expresion would be
> true), but it's not required to.

Well, that's what I expected to hear.

That makes me favor the static_string stuff posted earlier...
It would be nice to have a usable form of it though.

Would it be unreasonable to have a "text literal" be converted to
static_string when a type is needed instead of a specific const char*
value? That would basically make the following 2 invalid lines of code
valid via conversion to static_string:

SomeClass<"YourParam"> x;
typedef YourParam "YourParam";

  This has a lot of appeal to me anyway... I like being able to provide
a text literal as a template parameter much better... It removes one
degree of abstraction from what you're doing... No extern constant to
ensure is used everywhere... effectively no better than typedefining an
empty structure. It also eliminates the issue of possibly having two
"identical" classes being considered different.

Boost list run by bdawes at, gregod at, cpdaniel at, john at