Subject: Re: [boost] AlRangeExandrescu?
From: David Abrahams (dave_at_[hidden])
Date: 2009-07-27 12:55:45
on Mon Jul 27 2009, Maxim Yanchenko <maximyanchenko-AT-yandex.ru> wrote:
> David Abrahams <dave <at> boostpro.com> writes:
>> >>> Then how would you safely implement
>> >>> find[_f-1,_e]( range, x );
>> >> At first glance, you can't. Is there a known use case for that? If not,
> it's moot.
>> > Who knows. Maybe you want the element before the found one to be there for
> some reason.
>> "Maybe, for some reason" arguments don't hold much water with me,
>> especially in a library design context.
> Say I have an array of prices active now on exchange.
> In my algorithm, I come up with some price, and now I want to place my orders 5
> levels above and 5 levels below the price I need.
> With iterators (omitting boundary cases) this would be:
> it = find( prices.begin(), prices.end(), desired_price );
> desired_levels = boost::range( it-5, it+5 );
> place_orders( desired_levels );
> With the syntax above, what I need is find[_f-5, _f+5](range, x).
> There can be more examples if this kind, say fancy smoothing an image, when you
> need to find a pixel and then smooth it over neighbor pixels.
> Same in numerical calculations on grids - you often take neighbors of what you
> found into account.
My point is not that there are no use cases, it's that there may be
reasonably simple ways of expressing these less-common use cases that
don't intrude on the interface of find itself, but instead combine find
with some orthogonal components.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk