21 Jun 2012 18:58
Patch for review: enhancement to __builtin_strlen
Hi,
I would like to offer a patch for review that extends the use of the
compile-time evaluation of __builtin_strlen to include immutable
null-terminated const char arrays, i.e. beyond just standard string
literals. (It will still fall back to runtime use of library strlen, if
compile-time evaluation is not possible/required -- this side of the
functionality is not changed).
This is not a bug fix but a feature enhancement, which I believe may have
broader appeal to those developing with C++11 and, in particular, with
user-defined literals.
The target use for this would be in generating transparent wrapper classes
for user-defined literals, so that these may be used in situations wherever
normal strings may be used.
Let's say we have the following simplified setup:
template <char... String>
struct Literal {
private:
typedef const char type[sizeof...(String)+1];
static constexpr type string = { String..., 0 };
public:
constexpr operator const type&() const { return string; }
// room for more implementation, such as operator[] and
// also string manipulation, such as operator+, and so on.
(Continue reading)
RSS Feed