P
__PPS__
Hello everybody, I'm not sure but I thought that sometime ago I had
class with two overloaded methods:
void func(const char*);
and
template<int N>func(const char (&arr)[N]);
so, that whenever I call func("some text") then size of the text will
be known at compile time instead of doing strlen()
I'm sure that long time ago I got it working somehow, but now when I
needed and implemented a similar solution I see that it doesn't work.
(stepping with debugger shows that pointer version is used in all
cases)
I'm using vs2005...
about that working code that I had a couple years ago ... I remember
that I used boost enable if and typetraits/mpl libraries heavily and
possibly I made it working thanks to that libraries (probably, instead
of const char * version I had enable_if(not-array<>) or something like
this). Also, it's possible that I was using g++ and that's why it was
working.
Now, I can't use boost, so I tried to convert const char* version to
SFINAE-like template that would instantiate only in const char * case,
but in this case I got error that two of the functions could be used!!
(kind of, in case when const char* version wasn't templated array
version wasn't ambiguous)... wtf??
So, I'm quite surprised now that if I func("some text") then const
char * version is called instead of templated array-ref version. As
far as I'm concerner typeof("some text") is const char[X] it it's
convertible to const char *...
Can anybody comment on this problem?
thanks
class with two overloaded methods:
void func(const char*);
and
template<int N>func(const char (&arr)[N]);
so, that whenever I call func("some text") then size of the text will
be known at compile time instead of doing strlen()
I'm sure that long time ago I got it working somehow, but now when I
needed and implemented a similar solution I see that it doesn't work.
(stepping with debugger shows that pointer version is used in all
cases)
I'm using vs2005...
about that working code that I had a couple years ago ... I remember
that I used boost enable if and typetraits/mpl libraries heavily and
possibly I made it working thanks to that libraries (probably, instead
of const char * version I had enable_if(not-array<>) or something like
this). Also, it's possible that I was using g++ and that's why it was
working.
Now, I can't use boost, so I tried to convert const char* version to
SFINAE-like template that would instantiate only in const char * case,
but in this case I got error that two of the functions could be used!!
(kind of, in case when const char* version wasn't templated array
version wasn't ambiguous)... wtf??
So, I'm quite surprised now that if I func("some text") then const
char * version is called instead of templated array-ref version. As
far as I'm concerner typeof("some text") is const char[X] it it's
convertible to const char *...
Can anybody comment on this problem?
thanks