Subject: Re: [boost] Boost.Algorithm design question
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-10-06 03:52:34
Den 06-10-2011 00:53, Stephan T. Lavavej skrev:
> [Marshall Clow]
>> So, what do people prefer (and why?):
>> template<typename InputIterator, typename V> bool none_of_equal (
>> InputIterator first, InputIterator last, V const&val )
>> template<typename InputIterator,> bool none_of_equal (
>> InputIterator first, InputIterator last,
>> iterator_traits<InputIterator>::value_type const&val )
>> In the first case, I think there's (possible) conversion from V to
>> iterator_traits<InputIterator>::value_type each time through the
>> loop. In the second case, there is not.
> #1 is better. It follows the STL's conventions (e.g. look at
> std::find()) and permits heterogeneous comparisons.
> Consider vector<string> and val being "meow". string is directly
> comparable to const char *, without any conversions or temporaries.
> Even better, consider vector<const char *> and val being a string.
> Here, the element type is still directly comparable to val's type,
> but val's type is not implicitly convertible to the element type.
Even better, don't use vector<const char*>. What o you need that for?
> Heterogeneous comparisons are surprisingly popular, and the STL is
> moving to support them better. For example, std::lower_bound() didn't
> support them in C++03, and does in C++11. std::map still doesn't, and
> users complain about it from time to time.
Well, option number two has the distinct advantage that it generates
less code. Option number one would generate code for each length of a
To avoid such mess, the implementation can try to decay the value
an then forward to the real implementation. Or the user can use
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk