
20 Dec
2010
20 Dec
'10
12:43 a.m.
On 12/19/2010 3:21 PM, Jochen Wilhelmy wrote:
Hi!
is there a (possibly boost powered) way of distinguishing between const char* and const char[N]?
e.g.
const char* foo = "foo"; bar(foo); bar("foo");
The second call to bar should extract the length at compile time, e.g.
template <size_t length> void bar(const char (&data)[length]) {...}
The problem is that in the presence of the first variant (void bar(const char*)) the second variant does not get called.
-Jochen
In addition to Dave's solution, it looks like if your overloads look like void bar(char const *&); // note the & template< std::size_t N > void bar(char const (&)[N]); then the latter will be selected when passed a string literal. Seems to work on MSVC9 anyway... - Jeff