Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-28 19:07:42


David Abrahams wrote:

> That's not really accurately phrased. C++ /can/ pass the type on to the LHS
> of an assignment using a templated assignment operator. What it won't do is
> let you declare a variable of deduced type.

        Thats the famous STL type inference trick.

[auto for type inference]

> That was my suggestion.

        Too scared to propose a new keyword? <g>
        BTW: your extension introduces a silent change from C.

        auto x = 1.2; // x is type 'int' in C due to 'implicit int'

>Andy Koenig has an interesting idea which is even
> more flexible. Ask him about it sometime...

        Let me guess: Andy knows SML. So the obvious
extension is general pattern matching. Felix has pattern matching. :-)

        The current syntax is ugly :-(

        match (1,2) {
                case (x,y) as z:; // types of x,y deduced as int
                                // z has type int * int (tuple type)
                case ....
        }

The SML syntax is cleaner:

        match (1,2) with
        | (x,y) as z -> ...
        | ....

but less familiar (and forces parens sometime when nesting:
the Felix syntax comes with {} .. but can only be used
for statements)

-- 
John (Max) Skaller, mailto:skaller_at_[hidden]
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net

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