9 Commits

Author SHA1 Message Date
Andrey Semashev
2722fdcda3 Use std::iterator_traits to detect iterators, when possible.
This allows next/prior to detect user's iterators that do not
define iterator_category nested type but specialize
std::iterator_traits instead.
2017-07-23 20:29:25 +03:00
Andrey Semashev
e25d85446e Use Boost.Iterator to advance iterators.
By using Boost.Iterator we rely on the separate traversal category instead of
the standard iterator category to advance iterators efficiently. For instance,
this allows to advance transform iterators over a random access sequence
in constant time, despite that they are formally input iterators.

Also, std::reverse_iterator formally requires at least bidirectional iterator
as the underlying iterator type. Transform iterators from the example above
don't qualify, so potentially std::reverse_iterator could fail to compile.
2017-07-12 21:15:20 +03:00
Andrey Semashev
5bc9e47688 Changed iterator_category nested type detection to work with MSVC and different versions of gcc. 2017-07-12 20:14:48 +03:00
Andrey Semashev
6cf9c22cf1 Reworked iterator handling in next/prior helpers.
The new implementation tries to detect if the incremented/decremented type
is an iterator first and if not falls back to operator probing. This way
iterators that are not SFINAE-friendly (i.e. unconditionally define
arithmetic operators regardless of the iterator category) are still treated
as iterators through std::advance and do not fail the compilation.

The iterator detection is based on probing for the nested iterator_category
type that is expected to be present in class-type iterators. This heuristic
is not flawless since iterators are not required to defined this type.
User-defined iterators may not have it and instead specialize
std::iterator_traits. This use case is not covered by the current implementation
and will likely fail to compile. With C++17 SFINAE-friendly std::iterator_traits
this can be fixed, but currently Boost.Config lacks the macro to detect
availability of this feature. Support for it can be added by a later commit.

Also simplified boost::prior for iterators, removing the possibility of
integer overflow caused by negation of the distance value.
2017-07-09 03:10:01 +03:00
Andrey Semashev
651a869d4f Reworked next() and prior() taking the distance arguments.
The new version should provide the expected behavior in the case (prior(v.end(), v.size()) == v.begin()). It should also work with integers now, as was originally intended by David Abrahams. Added tests to verify these new use cases.
2014-06-24 01:05:32 +04:00
John Maddock
acd2e6ef2b Added Daryle Walker's copyrights as requested.
[SVN r24481]
2004-08-15 10:13:49 +00:00
John Maddock
d8b0ff2d7e Removed Boost.org copyrights and replaced with originating authors copyright instead.
[SVN r24372]
2004-08-10 12:53:34 +00:00
Dave Abrahams
dfc320124f Extended next/prior using patch from Daniel Walker (Daniel.Walker-at-bowneglobal.com)
[SVN r21382]
2003-12-23 14:59:59 +00:00
Aleksey Gurtovoy
80df1d8f12 split utility.hpp header
[SVN r17472]
2003-02-17 06:20:57 +00:00