4 Jul 18:08
Finding algorithms returning ranges?
From: Mathias Gaunard <mathias.gaunard <at> ens-lyon.org>
Subject: Finding algorithms returning ranges?
Newsgroups: gmane.comp.lib.boost.devel
Date: 2008-07-04 16:09:57 GMT
Subject: Finding algorithms returning ranges?
Newsgroups: gmane.comp.lib.boost.devel
Date: 2008-07-04 16:09:57 GMT
Finding algorithms (find, find_if, max_element, and others) usually
return an iterator to the found position, or the past-the-end iterator.
While enough, it can be quite annoying when used with range adaptors and
the like.
Imagine something like this:
auto r = some_range | some adapters...;
auto it = max_element(r, comparison_function);
if(it != end(r))
{
do_something;
}
Without auto, it is simply unusable.
If such algorithms returned the range [found, end), we would be able to
write:
if(!empty(max_element(some_range | some adapters..., comparison_function))
{
do_something;
}
Particularly, I find it practical to use it with a function like that:
optional<typename range_value<Range>::type>
deref_opt(const Range& r)
{
typedef typename range_value<Range>::type T;
(Continue reading)
RSS Feed