[Effective C++ Style] Re: [Effective-cpp] Item 4: Standardlibrary member functions

Ric Parkin ric.parkin at ntlworld.com
Mon Nov 8 04:18:01 EST 2004


From: Terje Slettebø <tslettebo at broadpark.no>
> > Imagine the equivalent argument-less approach:
> >
> >    generate_n(out, count, int() { return rand() % 2; });
> >
> > The compiler is going to wonder why int(), which is a well-formed
> > expression resulting in 0, is following by a mystery block.

> Express your intent. You don't
> intend this to be a pointer to function, so why use that notation? It's an
> "inline function". Thus, I used the notation for function declaration (which
> you also agree to below was what you had in mind, as well, but which may
> make this ambiguous).

Idea suggested by your use of the phrase "inline function":

generate_n(out, count, inline int() { return rand() % 2; });
 
Downside is that it's a slightly different use of the word "inline" than normal, although it seems a surprisingly natural syntax...

Ric

-----------------------------------------
Email provided by http://www.ntlhome.com/





More information about the Effective-cpp mailing list