Boost logo

Boost :

From: Powell, Gary (powellg_at_[hidden])
Date: 2004-03-04 11:56:22


> "Shannon Stewman" <stew_at_[hidden]> wrote in message
> news:20040304025205.GD832_at_uchicago.edu...
>
>>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++.
>>
>
>
> How about:
>
> unsigned long n = std::accumulate(
> xs.begin(), xs.end(), 0UL,
> auto(long lhs, const auto& rhs) // inline fn with no
> name.
> {
> return lhs + rhs.count;
> }
> );

> I would prefer also eliding the argument types:
>
> unsigned long n = std::accumulate(
> xs.begin(), xs.end(), 0UL,
> lambda(lhs, rhs)
> {
> return lhs + rhs.count;
> }
> );
>
> Most of the time, you also do not know the type of the
> arguments before hand.

> Joel de Guzman

There are still direct templates (even without implied ones.) The syntax would
be a bit verbose though.

      unsigned long n = std::accumulate(
            xs.begin(), xs.end(), 0UL,
                template<class T, class S)
                auto (T const &lhs, S const &rhs)
                {
                    return lhs + rhs.count;
                }
            );


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