Commit Graph

10 Commits

Author SHA1 Message Date
Andrey Semashev
0c6b09ef6a Workaround MSVC 14.1 problem with template specialization partial ordering that caused compilation failure when next/prior is used with pointers. Added a test. 2017-08-27 17:31:34 +03:00
Andrey Semashev
5f6fd2dec6 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-08-26 15:23:36 +03:00
Andrey Semashev
e3577e7687 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-08-26 15:23:36 +03:00
Andrey Semashev
5ba36b063e Changed iterator_category nested type detection to work with MSVC and different versions of gcc. 2017-08-26 15:23:36 +03:00
Andrey Semashev
d251a6f515 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-08-26 15:23:36 +03:00
Andrey Semashev
9d054b25ce 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.
2017-08-26 15:23:36 +03:00
John Maddock
abe77db3e0 Added Daryle Walker's copyrights as requested.
[SVN r24481]
2017-08-26 15:23:36 +03:00
John Maddock
398819237e Removed Boost.org copyrights and replaced with originating authors copyright instead.
[SVN r24372]
2017-08-26 15:23:36 +03:00
Dave Abrahams
a4bacb5077 Extended next/prior using patch from Daniel Walker (Daniel.Walker-at-bowneglobal.com)
[SVN r21382]
2017-08-26 15:23:36 +03:00
Aleksey Gurtovoy
5ba5f2c2d4 split utility.hpp header
[SVN r17472]
2017-08-26 15:23:36 +03:00