|
Boost : |
Subject: Re: [boost] Boost.Algorithm design question
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-10-29 15:25:13
on Sat Oct 29 2011, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
> Dave Abrahams wrote:
>
>> Here's another reason why the first formulation might not be such a hot
>> idea: it rules out some obvious implementations that really ought to be
>> OK. For example,
>>
>> template <class InputIterator, class T>
>> InputIterator find(InputIterator i, InputIterator j, T value)
>> {
>> while (i != j && !(*i == value))
>> ++i;
>> return i;
>> }
>
> Yes, but this formulation doesn't need *i and value to be of the same
> type or operator== to be an equivalence relation. It just needs
> operator== to return something bool-ish.
Actually it needs a bit more than that: applying ! to your bool-ish
thing needs to be unambiguously &&-able with the result of i != j, which
might not itself be bool. These are the kinds of problems that crop up
when you start checking constraints on valid expressions.
-- 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