[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] Two new lists to get commit logs

From: Florian Weimer
Subject: Re: [Monotone-devel] Two new lists to get commit logs
Date: Mon, 18 Apr 2005 12:24:57 +0200

* Nathan Myers:

> Who would use a null-terminated string for anything in a C++ program?
> Here's a handy idiom:
>   template <unsigned N>
>     int f(const char (&a)[N])
>       { return ::write(1, a, N-1); }
>   int main() { return f("abc\n"); }
> The template engine deduces the size of the literal string and binds N
> to that value, so you don't need to search for any dumb terminator.
> Better yet, if you call f with a pointer, the compiler rejects it.

Thanks for sharing this trick.  I've been looking for something like
this for quite some time.  It also helps if you want to prevent stupid
mistakes like passing

  ("SELECT * FROM users WHERE id = '" + id + '\'').c_str() 

to some SQL database access function.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]