Marcel Mueller
2024-05-17 15:25:24 UTC
Assuming I have a function
void assign(const char* str);
void assign(const char* str, size_t len);
If this is called with a string literal, always the string length has to
be examined at runtime.
With
template<size_t N>
void assign(const char (&str)[N]);
I can capture the string length (including \0) at compile time.
But this overload is never used because the first overload still fits to
the literal due to the implicit conversion from array to pointer.
How to force the last overload with fixed size char arrays?
Marcel
void assign(const char* str);
void assign(const char* str, size_t len);
If this is called with a string literal, always the string length has to
be examined at runtime.
With
template<size_t N>
void assign(const char (&str)[N]);
I can capture the string length (including \0) at compile time.
But this overload is never used because the first overload still fits to
the literal due to the implicit conversion from array to pointer.
How to force the last overload with fixed size char arrays?
Marcel