Boost logo

Boost :

From: joel de guzman (djowel_at_[hidden])
Date: 2002-02-18 12:23:33


----- Original Message -----
From: "Daniel Frey" :

joel de guzman wrote:
>
> Next to typeof(x), I'd love to see Dave (Abraham's) "auto" for type deduction.
>
> auto v = an_arbitrarily_complex_expression;

I'm reading all those pro-'auto' comments with a little fear. Why it
'auto' really needed if we have a good typeof? Example:

[snip]

IMHO, typeof() is really necessary, but auto is just eye-candy. I cannot
see something that an 'auto'-type can do you couldn't do with typeof()
and the current language. Instead, it weakens the strong-type-checking
for which I like C++. (I know my english is horrible, but I hope you get
what I mean :). If I missed something about 'auto', please let me know.

--------------------------------------------------------------------------
Hi,

You have a point. typeof is the bare mimimum. auto (or let, var) is more
like eye candy. But when you have a very complex RHS, it gets too
redundant to supply the expression in the typeof as well as the actual
RHS. Here's an example of a rule (in the C grammar) using the Spirit
inline parser for example:

    relational_expression
        = shift_expression >>
            *(
                 LT_OP >> shift_expression
            | GT_OP >> shift_expression
            | LE_OP >> shift_expression
            | GE_OP >> shift_expression
            )
         ;

Now imagine the same declaration using only typeof(expr). You
will have to duplicate the expression in the type and the rhs:

     typeof(blah_blah) relational_expression = blah_blah;

Complex expressions much much more complex than this are
prevalent in functional style programming where binary, unary
operators and functions evaluates to higher order functions.

Regards,
--Joel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk