Sunday, 15 September 2013

Is there a way to determine if a parameter is a literal string?

Is there a way to determine if a parameter is a literal string?

My question is:
Is there a way to determine whether a parameter is a literal string or not?
template<class T>
bool IsLiteral(T arg)
{
// How to implement?
}
or
template<class T>
struct IsLiteral { enum { value = ??? }; };
So that we can write the following code:
char* p = "Hello";
assert(IsLiteral(p)); // fail.
assert(IsLiteral("Hello")); // never fail.

No comments:

Post a Comment