Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2004-03-03 22:26:44


Shannon Stewman wrote:

> On Wed, Mar 03, 2004 at 01:34:50PM -0800, Powell, Gary wrote:
>
>
>>unsigned long n = std::accumulate(
>> xs.begin(), xs.end(), 0UL,
>> long (long lhs, X const &rhs) // inline fn with no name.
>> {
>> return lhs + rhs.count;
>> }
>> );
>
>
> This seems to cast out the type inference present in BLL. I think
> that's one of the nicer concepts in the lambda library, and a real
> boon to programming. In my limited experience with SML/OCaml, type
> inference seems a better, safer, and more convenient way to program,
> albeit requiring a lot more compiler intelligence. As BLL shows, though,
> this is quite possible, though perhaps limited, with existing C++.

I agree. In many cases, type inference is a necessity since
you do not know the type of the arguments before hand. Take
a simple Spirit parser, for example:

     std::string s;
     identifier = (+alpha_p)
         [ ref(s) = construct_<std::string>(arg1, arg2) ]
         ;

At grammar declaration time, we don't (can't) know the
exact type of arg1 and arg2. We simply know that they are
iterators.

Cheers,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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