|
Boost : |
From: Shannon Stewman (stew_at_[hidden])
Date: 2004-03-03 21:52:05
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++.
Something like:
unsigned long n = std::accumulate(
xs.begin(), xs.end(), 0UL,
lambda( lhs, rhs ) { return lhs + rhs.count; } );
(Replace 'lambda' with 'function' if you have an aversion to FP
nomenclature.)
This just reads more easily to me, and you haven't sacrificed type safety.
If you need to resolve type ambiguity, that's one thing, but requiring
unnecessary type information seems like a loss in functionality from BLL.
Cheers!
-- Shannon Stewman | Let us walk through the waning night, Caught in a whirlpool, | As dawn-rays tickle our toes, the dew soothes A quartering act: | Our blistered soles, and damp bones stir Solitude or society? | As crimson cracks under the blue-grey sky.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk