mirror of
https://github.com/boostorg/iterator.git
synced 2025-06-30 22:41:10 +02:00
Compare commits
106 Commits
boost-1.64
...
feature/mo
Author | SHA1 | Date | |
---|---|---|---|
0013c5c4f0 | |||
386dbf1054 | |||
486721bbfe | |||
5ad48c4d14 | |||
adecfd94f3 | |||
affe7e6d84 | |||
91b392a478 | |||
84227ea6ba | |||
67ac957273 | |||
f86cd29f52 | |||
fff85e7db9 | |||
d6c6f0ce16 | |||
81faa161cf | |||
7e5a32b3ea | |||
1b388c2496 | |||
30b93d7428 | |||
28b8cc8c9c | |||
992a314211 | |||
422ad12716 | |||
b2585dda6a | |||
8b5e92a0c4 | |||
a36ed0f35d | |||
0a08203107 | |||
38ef552209 | |||
a85dfaa7f2 | |||
2af60e066d | |||
7442334ce1 | |||
8577675c85 | |||
685b3fe855 | |||
a653a39cf4 | |||
c338572735 | |||
07afd26ca2 | |||
d058933767 | |||
e2f81e9b48 | |||
379200dfd1 | |||
a26314dfb9 | |||
e61592c553 | |||
a3751006db | |||
40da532a4d | |||
7ce9f87954 | |||
553b9713ac | |||
ba32745e80 | |||
282b28e51f | |||
479898d9d5 | |||
c1a375284d | |||
24d2f58f98 | |||
25a91d5981 | |||
9b78dc1006 | |||
89ca2fd1ae | |||
79277b78d2 | |||
eb90ad7a99 | |||
de07014e9a | |||
25dc5c6c9c | |||
048c3dfa72 | |||
f7dfc36a9c | |||
c529399fb1 | |||
6faa3a942b | |||
0c6b09ef6a | |||
83220e7aea | |||
991ea534ee | |||
210633c08c | |||
3275ee3c82 | |||
a72deda3ac | |||
2b6b6bf8ad | |||
0107df44ab | |||
011288c2c8 | |||
eaf1a48583 | |||
52fbe950ec | |||
6a672cecbd | |||
577203bee8 | |||
5f6ac9c020 | |||
a48de6a8b8 | |||
5f6fd2dec6 | |||
e3577e7687 | |||
5ba36b063e | |||
bab02bb82e | |||
d251a6f515 | |||
9d054b25ce | |||
d1b22ac8e8 | |||
abe77db3e0 | |||
398819237e | |||
a4bacb5077 | |||
5ba5f2c2d4 | |||
6c1b356be1 | |||
bfcf52ace6 | |||
e2c927628c | |||
ed027c2cce | |||
4791425000 | |||
b7e7e83a11 | |||
c148962bd9 | |||
5bfbfb7716 | |||
af5f6e49e0 | |||
26ee5ba754 | |||
67a2336cf4 | |||
029277f3ed | |||
847b2a1be3 | |||
18268069d9 | |||
bb54ee7900 | |||
d5b67c7fab | |||
663a30f659 | |||
177f719d15 | |||
cccbd8c6aa | |||
d6cfed4b20 | |||
514ac53326 | |||
ca3b7505ce | |||
d7c8cccd64 |
87
.travis.yml
Normal file
87
.travis.yml
Normal file
@ -0,0 +1,87 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
python: "2.7"
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /feature\/.*/
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
|
||||
include:
|
||||
- os: linux
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc CXXSTD=03,11
|
||||
|
||||
- os: linux
|
||||
compiler: g++-5
|
||||
env: TOOLSET=gcc-5 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-6
|
||||
env: TOOLSET=gcc-6 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc-7 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang CXXSTD=03,11,14,1z
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang CXXSTD=03,11,14,1z
|
||||
|
||||
install:
|
||||
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
||||
- cd ..
|
||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init tools/boostdep
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/iterator
|
||||
- python tools/boostdep/depinst/depinst.py iterator
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- ./b2 -j3 libs/iterator/test toolset=$TOOLSET cxxstd=$CXXSTD
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
43
appveyor.yml
Normal file
43
appveyor.yml
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright 2017 Edward Diener
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /feature\/.*/
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
TOOLSET: msvc-14.0
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17
|
||||
|
||||
install:
|
||||
- set BOOST_BRANCH=develop
|
||||
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
|
||||
- cd ..
|
||||
- git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init tools/boostdep
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\iterator
|
||||
- python tools/boostdep/depinst/depinst.py iterator
|
||||
- cmd /c bootstrap
|
||||
- b2 -d0 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- b2 -j3 libs/iterator/test toolset=%TOOLSET% %CXXSTD%
|
@ -16,7 +16,7 @@ boostbook standalone
|
||||
<xsl:param>boost.root=../../../..
|
||||
<xsl:param>toc.max.depth=3
|
||||
<xsl:param>toc.section.depth=3
|
||||
<xsl:param>chunk.section.depth=4
|
||||
<xsl:param>chunk.section.depth=2
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/iterator/doc
|
||||
;
|
||||
|
||||
|
75
doc/advance.rst
Normal file
75
doc/advance.rst
Normal file
@ -0,0 +1,75 @@
|
||||
.. Copyright (C) 2017 Michel Morin.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
=======
|
||||
advance
|
||||
=======
|
||||
|
||||
``boost::iterators::advance`` is an adapted version of ``std::advance`` for
|
||||
the Boost iterator traversal concepts.
|
||||
|
||||
|
||||
Header
|
||||
------
|
||||
|
||||
``<boost/iterator/advance.hpp>``
|
||||
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
template <typename Iterator, typename Distance>
|
||||
constexpr void advance(Iterator& it, Distance n);
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
Moves ``it`` forward by ``n`` increments
|
||||
(or backward by ``|n|`` decrements if ``n`` is negative).
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
``Iterator`` should model Incrementable Iterator.
|
||||
|
||||
|
||||
Preconditions
|
||||
-------------
|
||||
|
||||
Let ``it``\ :sub:`i` be the iterator obtained by incrementing
|
||||
(or decrementing if ``n`` is negative) ``it`` by *i*. All the iterators
|
||||
``it``\ :sub:`i` for *i* = 0, 1, 2, ..., ``|n|`` should be valid.
|
||||
|
||||
If ``Iterator`` does not model Bidirectional Traversal Iterator,
|
||||
``n`` should be non-negative.
|
||||
|
||||
|
||||
Complexity
|
||||
----------
|
||||
|
||||
If ``Iterator`` models Random Access Traversal Iterator, it takes constant time;
|
||||
otherwise it takes linear time.
|
||||
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
- This function is not a customization point and is protected against
|
||||
being found by argument-dependent lookup (ADL).
|
||||
- This function is ``constexpr`` only in C++14 or later.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
| Author: Michel Morin
|
||||
| Copyright |C| 2017 Michel Morin
|
||||
| Distributed under the `Boost Software License, Version 1.0
|
||||
<http://www.boost.org/LICENSE_1_0.txt>`_.
|
||||
|
||||
.. |C| unicode:: U+00A9 .. COPYRIGHT SIGN
|
72
doc/distance.rst
Normal file
72
doc/distance.rst
Normal file
@ -0,0 +1,72 @@
|
||||
.. Copyright (C) 2017 Michel Morin.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
========
|
||||
distance
|
||||
========
|
||||
|
||||
``boost::iterators::distance`` is an adapted version of ``std::distance`` for
|
||||
the Boost iterator traversal concepts.
|
||||
|
||||
|
||||
Header
|
||||
------
|
||||
|
||||
``<boost/iterator/distance.hpp>``
|
||||
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
template <typename Iterator>
|
||||
constexpr typename iterator_difference<Iterator>::type
|
||||
distance(Iterator first, Iterator last);
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
Computes the (signed) distance from ``first`` to ``last``.
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
``Iterator`` should model Single Pass Iterator.
|
||||
|
||||
|
||||
Preconditions
|
||||
-------------
|
||||
|
||||
If ``Iterator`` models Random Access Traversal Iterator,
|
||||
``[first, last)`` or ``[last, first)`` should be valid;
|
||||
otherwise ``[first, last)`` should be valid.
|
||||
|
||||
|
||||
Complexity
|
||||
----------
|
||||
|
||||
If ``Iterator`` models Random Access Traversal Iterator, it takes constant time;
|
||||
otherwise it takes linear time.
|
||||
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
- This function is not a customization point and is protected against
|
||||
being found by argument-dependent lookup (ADL).
|
||||
- This function is ``constexpr`` only in C++14 or later.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
| Author: Michel Morin
|
||||
| Copyright |C| 2017 Michel Morin
|
||||
| Distributed under the `Boost Software License, Version 1.0
|
||||
<http://www.boost.org/LICENSE_1_0.txt>`_.
|
||||
|
||||
.. |C| unicode:: U+00A9 .. COPYRIGHT SIGN
|
@ -131,6 +131,9 @@ is called to get the value to return.</li>
|
||||
<li><a class="reference external" href="function_output_iterator.html"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt></a> (<a class="reference external" href="function_output_iterator.pdf">PDF</a>): an output iterator wrapping a unary function
|
||||
object; each time an element is written into the dereferenced
|
||||
iterator, it is passed as a parameter to the function object.</li>
|
||||
<li><a class="reference external" href="generator_iterator.htm"><tt class="docutils literal"><span class="pre">generator_iterator</span></tt></a>: an input iterator wrapping a reference to a generator (nullary function object);
|
||||
each time the iterator is dereferenced, the function object
|
||||
is called to get the value to return. This is a more outdated analogue of <tt class="docutils literal"><span class="pre">function_input_iterator</span></tt>.</li>
|
||||
<li><a class="reference external" href="indirect_iterator.html"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt></a> (<a class="reference external" href="indirect_iterator.pdf">PDF</a>): an iterator over the objects <em>pointed-to</em> by the
|
||||
elements of some sequence.</li>
|
||||
<li><a class="reference external" href="permutation_iterator.html"><tt class="docutils literal"><span class="pre">permutation_iterator</span></tt></a> (<a class="reference external" href="permutation_iterator.pdf">PDF</a>): an iterator over the elements of some random-access
|
||||
|
@ -146,6 +146,10 @@ iterator templates based on the Boost `iterator facade and adaptor`_.
|
||||
object; each time an element is written into the dereferenced
|
||||
iterator, it is passed as a parameter to the function object.
|
||||
|
||||
* |generator|_: an input iterator wrapping a generator (nullary
|
||||
function object); each time the iterator is dereferenced, the function object
|
||||
is called to get the value to return. This is an outdated analogue of |function_input|_.
|
||||
|
||||
* |indirect|_ (PDF__): an iterator over the objects *pointed-to* by the
|
||||
elements of some sequence.
|
||||
|
||||
@ -183,6 +187,9 @@ __ function_input_iterator.pdf
|
||||
.. _function_output: function_output_iterator.html
|
||||
__ function_output_iterator.pdf
|
||||
|
||||
.. |generator| replace:: ``generator_iterator``
|
||||
.. _generator: generator_iterator.htm
|
||||
|
||||
.. |indirect| replace:: ``indirect_iterator``
|
||||
.. _indirect: indirect_iterator.html
|
||||
__ indirect_iterator.pdf
|
||||
@ -213,6 +220,23 @@ __ zip_iterator.pdf
|
||||
Iterator Utilities
|
||||
====================
|
||||
|
||||
Operations
|
||||
----------
|
||||
|
||||
The standard library does not handle new-style iterators properly,
|
||||
because it knows nothing about the iterator traversal concepts.
|
||||
The Boost.Iterator library provides implementations that fully understand
|
||||
the new concepts for the two basic operations:
|
||||
|
||||
- |advance|_
|
||||
- |distance|_
|
||||
|
||||
.. |advance| replace:: ``advance``
|
||||
.. _advance: advance.html
|
||||
|
||||
.. |distance| replace:: ``distance``
|
||||
.. _distance: distance.html
|
||||
|
||||
Traits
|
||||
------
|
||||
|
||||
|
149
doc/quickbook/algorithms.qbk
Normal file
149
doc/quickbook/algorithms.qbk
Normal file
@ -0,0 +1,149 @@
|
||||
[section:algorithms Algorithms]
|
||||
|
||||
[section:advance Function template `advance()`]
|
||||
|
||||
The `boost::iterators::advance` function template is an adapted version of `std::advance` for the Boost iterator [link iterator.concepts.traversal traversal concepts].
|
||||
|
||||
[heading Header]
|
||||
|
||||
<boost/iterator/advance.hpp>
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
template <typename Iterator, typename Distance>
|
||||
constexpr void advance(Iterator& it, Distance n);
|
||||
|
||||
|
||||
[heading Description]
|
||||
|
||||
Moves `it` forward by `n` increments (or backward by `|n|` decrements if `n` is negative).
|
||||
|
||||
[heading Requirements]
|
||||
|
||||
`Iterator` should model Incrementable Iterator.
|
||||
|
||||
[heading Preconditions]
|
||||
|
||||
Let `it`[sub `i`] be the iterator obtained by incrementing (or decrementing if `n` is negative) `it` by `i`. All the iterators `it`[sub `i`] for `i` = 0, 1, 2, ..., `|n|` should be valid.
|
||||
|
||||
If `Iterator` does not model [link iterator.concepts.traversal.bidirectional Bidirectional Traversal Iterator], `n` should be non-negative.
|
||||
|
||||
[heading Complexity]
|
||||
|
||||
If `Iterator` models [link iterator.concepts.traversal.random_access Random Access Traversal Iterator], it takes constant time; otherwise it takes linear time.
|
||||
|
||||
[heading Notes]
|
||||
|
||||
* This function is not a customization point and is protected against being found by argument-dependent lookup (ADL).
|
||||
* This function is `constexpr` only in C++14 or later.
|
||||
|
||||
[heading Acknowledgements]
|
||||
|
||||
Contributed by Michel Morin.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:distance Function template `distance()`]
|
||||
|
||||
The `boost::iterators::distance` function template is an adapted version of `std::distance` for the Boost iterator [link iterator.concepts.traversal traversal concepts].
|
||||
|
||||
[heading Header]
|
||||
|
||||
<boost/iterator/distance.hpp>
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
template <typename Iterator>
|
||||
constexpr typename iterator_difference<Iterator>::type
|
||||
distance(Iterator first, Iterator last);
|
||||
|
||||
[heading Description]
|
||||
|
||||
Computes the (signed) distance from `first` to `last`.
|
||||
|
||||
[heading Requirements]
|
||||
|
||||
`Iterator` should model [link iterator.concepts.traversal.single_pass Single Pass Iterator].
|
||||
|
||||
[heading Preconditions]
|
||||
|
||||
If `Iterator` models [link iterator.concepts.traversal.random_access Random Access Traversal Iterator], `[first, last)` or `[last, first)` should be valid; otherwise `[first, last)` should be valid.
|
||||
|
||||
[heading Complexity]
|
||||
|
||||
If `Iterator` models [link iterator.concepts.traversal.random_access Random Access Traversal Iterator], it takes constant time; otherwise it takes linear time.
|
||||
|
||||
[heading Notes]
|
||||
|
||||
* This function is not a customization point and is protected against being found by argument-dependent lookup (ADL).
|
||||
* This function is `constexpr` only in C++14 or later.
|
||||
|
||||
[heading Acknowledgements]
|
||||
|
||||
Contributed by Michel Morin.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:next_prior Function templates `next()` and `prior()`]
|
||||
|
||||
Certain data types, such as the C++ Standard Library's forward and bidirectional iterators, do not provide addition and subtraction via `operator+()` or `operator-()`. This means that non-modifying computation of the next or prior value requires a temporary, even though `operator++()` or `operator--()` is provided. It also means that writing code like `itr+1` inside a template restricts the iterator category to random access iterators.
|
||||
|
||||
The `next()` and `prior()` functions defined in `boost/next_prior.hpp` provide a simple way around these problems.
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
template <class T>
|
||||
T next(T x)
|
||||
{
|
||||
return ++x;
|
||||
}
|
||||
|
||||
template <class T, class Distance>
|
||||
T next(T x, Distance n)
|
||||
{
|
||||
std::advance(x, n);
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T prior(T x)
|
||||
{
|
||||
return --x;
|
||||
}
|
||||
|
||||
template <class T, class Distance>
|
||||
T prior(T x, Distance n)
|
||||
{
|
||||
std::advance(x, -n);
|
||||
return x;
|
||||
}
|
||||
|
||||
[note Function implementations above are given for exposition only. The actual implementation has the same effect for iterators, but has different properties, as documented later.]
|
||||
|
||||
[heading Usage]
|
||||
|
||||
Usage is simple:
|
||||
|
||||
const std::list<T>::iterator p = get_some_iterator();
|
||||
const std::list<T>::iterator prev = boost::prior(p);
|
||||
const std::list<T>::iterator next = boost::next(prev, 2);
|
||||
|
||||
The distance from the given iterator should be supplied as an absolute value. For example, the iterator four iterators prior to the given iterator `p` may be obtained by `prior(p, 4)`.
|
||||
|
||||
With C++11, the Standard Library provides `std::next()` and `std::prev()` function templates, which serve the same purpose. However, there are advantages to `boost::next()` and `boost::prior()`.
|
||||
|
||||
First, `boost::next()` and `boost::prior()` are compatible not only with iterators but with any type that provides arithmetic operators `operator++()`, `operator--()`, `operator+()`, `operator-()`, `operator+=()` or `operator-=()`. For example, this is possible:
|
||||
|
||||
int x = 10;
|
||||
int y = boost::next(x, 5);
|
||||
assert(y == 15);
|
||||
|
||||
Second, `boost::next()` and `boost::prior()` use [link iterator.concepts.traversal traversal categories] to select the most efficient implementation. For some kinds of iterators, such as [link iterator.specialized.transform transform iterators], the standard iterator category does not reflect the traversal category correctly and therefore `std::next()` and `std::prev()` will fall back to linear complexity.
|
||||
|
||||
[heading Acknowledgements]
|
||||
|
||||
Contributed by [@http://www.boost.org/people/dave_abrahams.htm Dave Abrahams]. Two-argument versions by Daniel Walker.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
@ -4,7 +4,7 @@ The iterator concept checking classes provide a mechanism for a
|
||||
template to report better error messages when a user instantiates the
|
||||
template with a type that does not meet the requirements of the
|
||||
template. For an introduction to using concept checking classes, see
|
||||
the documentation for the boost::concept_check library.
|
||||
the documentation for the _concept_check_ library.
|
||||
|
||||
[h2 `iterator_concepts.hpp` Synopsis]
|
||||
|
||||
@ -51,4 +51,4 @@ the documentation for the boost::concept_check library.
|
||||
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
@ -1,9 +1,9 @@
|
||||
|
||||
[section:concepts Iterator Concepts]
|
||||
|
||||
[section:concepts_access Access]
|
||||
[section:access Access]
|
||||
|
||||
[h2 Readable Iterator Concept]
|
||||
[section:readable Readable Iterator Concept]
|
||||
|
||||
A class or built-in type `X` models the *Readable Iterator* concept
|
||||
for value type `T` if, in addition to `X` being Assignable and
|
||||
@ -32,17 +32,18 @@ type `T`.
|
||||
[`U&`]
|
||||
[pre: `(*a).m` is well-defined. Equivalent to `(*a).m`.]
|
||||
]
|
||||
]
|
||||
|
||||
[h2 Writable Iterator Concept ]
|
||||
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:writable Writable Iterator Concept]
|
||||
|
||||
A class or built-in type `X` models the *Writable Iterator* concept
|
||||
if, in addition to `X` being Copy Constructible, the following
|
||||
expressions are valid and respect the stated semantics. Writable
|
||||
Iterators have an associated *set of value types*.
|
||||
|
||||
[table Writable Iterator Requirements (in addition to Copy Constructible)
|
||||
[table Writable Iterator Requirements (in addition to Copy Constructible)
|
||||
[
|
||||
[Expression]
|
||||
[Return Type]
|
||||
@ -55,13 +56,15 @@ Iterators have an associated *set of value types*.
|
||||
]
|
||||
]
|
||||
|
||||
[h2 Swappable Iterator Concept]
|
||||
[endsect]
|
||||
|
||||
[section:swappable Swappable Iterator Concept]
|
||||
|
||||
A class or built-in type `X` models the *Swappable Iterator* concept
|
||||
if, in addition to `X` being Copy Constructible, the following
|
||||
expressions are valid and respect the stated semantics.
|
||||
|
||||
[table Swappable Iterator Requirements (in addition to Copy Constructible)
|
||||
[table Swappable Iterator Requirements (in addition to Copy Constructible)
|
||||
[
|
||||
[Expression]
|
||||
[Return Type]
|
||||
@ -77,7 +80,9 @@ expressions are valid and respect the stated semantics.
|
||||
[blurb *Note:* An iterator that is a model of the *Readable* and *Writable Iterator* concepts
|
||||
is also a model of *Swappable Iterator*. *--end note*]
|
||||
|
||||
[h2 Lvalue Iterator Concept]
|
||||
[endsect]
|
||||
|
||||
[section:lvalue Lvalue Iterator Concept]
|
||||
|
||||
The *Lvalue Iterator* concept adds the requirement that the return
|
||||
type of `operator*` type be a reference to the value type of the
|
||||
@ -101,17 +106,17 @@ iterator.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:concepts_traversal Traversal]
|
||||
[endsect]
|
||||
|
||||
[h2 Incrementable Iterator Concept]
|
||||
[section:traversal Traversal]
|
||||
|
||||
[section:incrementable Incrementable Iterator Concept]
|
||||
|
||||
A class or built-in type `X` models the *Incrementable Iterator*
|
||||
concept if, in addition to `X` being Assignable and Copy
|
||||
Constructible, the following expressions are valid and respect the
|
||||
stated semantics.
|
||||
|
||||
|
||||
[table Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible)
|
||||
[
|
||||
[Expression ]
|
||||
@ -129,7 +134,7 @@ stated semantics.
|
||||
[``
|
||||
{
|
||||
X tmp = r;
|
||||
++r;
|
||||
++r;
|
||||
return tmp;
|
||||
}
|
||||
``]
|
||||
@ -141,7 +146,9 @@ stated semantics.
|
||||
]
|
||||
]
|
||||
|
||||
[h2 Single Pass Iterator Concept]
|
||||
[endsect]
|
||||
|
||||
[section:single_pass Single Pass Iterator Concept]
|
||||
|
||||
A class or built-in type `X` models the *Single Pass Iterator*
|
||||
concept if the following expressions are valid and respect the stated
|
||||
@ -168,6 +175,11 @@ semantics.
|
||||
[convertible to `bool`]
|
||||
[`!(a == b)`]
|
||||
]
|
||||
[
|
||||
[`iterator_traits<X>::difference_type`]
|
||||
[A signed integral type representing the distance between iterators]
|
||||
[]
|
||||
]
|
||||
[
|
||||
[`iterator_traversal<X>::type`]
|
||||
[Convertible to`single_pass_traversal_tag`]
|
||||
@ -175,8 +187,9 @@ semantics.
|
||||
]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[h2 Forward Traversal Concept]
|
||||
[section:forward Forward Traversal Concept]
|
||||
|
||||
A class or built-in type `X` models the *Forward Traversal*
|
||||
concept if, in addition to `X` meeting the requirements of Default
|
||||
@ -199,11 +212,6 @@ valid and respect the stated semantics.
|
||||
[`X&`]
|
||||
[`r == s` and `r` is dereferenceable implies `++r == ++s.`]
|
||||
]
|
||||
[
|
||||
[`iterator_traits<X>::difference_type`]
|
||||
[A signed integral type representing the distance between iterators]
|
||||
[]
|
||||
]
|
||||
[
|
||||
[`iterator_traversal<X>::type`]
|
||||
[Convertible to `forward_traversal_tag`]
|
||||
@ -211,7 +219,9 @@ valid and respect the stated semantics.
|
||||
]
|
||||
]
|
||||
|
||||
[h2 Bidirectional Traversal Concept]
|
||||
[endsect]
|
||||
|
||||
[section:bidirectional Bidirectional Traversal Concept]
|
||||
|
||||
A class or built-in type `X` models the *Bidirectional Traversal*
|
||||
concept if, in addition to `X` meeting the requirements of Forward
|
||||
@ -223,7 +233,7 @@ the stated semantics.
|
||||
[Expression]
|
||||
[Return Type]
|
||||
[Assertion/Semantics/Pre-/Post-condition]
|
||||
]
|
||||
]
|
||||
[
|
||||
[`--r`]
|
||||
[`X&`]
|
||||
@ -247,7 +257,9 @@ the stated semantics.
|
||||
]
|
||||
]
|
||||
|
||||
[h2 Random Access Traversal Concept]
|
||||
[endsect]
|
||||
|
||||
[section:random_access Random Access Traversal Concept]
|
||||
|
||||
A class or built-in type `X` models the *Random Access Traversal*
|
||||
concept if the following expressions are valid and respect the stated
|
||||
@ -255,8 +267,8 @@ semantics. In the table below, `Distance` is
|
||||
`iterator_traits<X>::difference_type` and `n` represents a
|
||||
constant object of type `Distance`.
|
||||
|
||||
[table Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal)
|
||||
[
|
||||
[table Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal)
|
||||
[
|
||||
[Expression]
|
||||
[Return Type]
|
||||
[Operational Semantics]
|
||||
@ -266,10 +278,10 @@ constant object of type `Distance`.
|
||||
[`r += n`]
|
||||
[ `X&`]
|
||||
[``
|
||||
{
|
||||
{
|
||||
Distance m = n;
|
||||
if (m >= 0)
|
||||
while (m--)
|
||||
while (m--)
|
||||
++r;
|
||||
else
|
||||
while (m++)
|
||||
@ -279,18 +291,18 @@ constant object of type `Distance`.
|
||||
``]
|
||||
[ ]
|
||||
]
|
||||
[
|
||||
[
|
||||
[`a + n`, `n + a`]
|
||||
[`X`]
|
||||
[``
|
||||
{
|
||||
{
|
||||
X tmp = a;
|
||||
return tmp+= n;
|
||||
}
|
||||
``]
|
||||
[]
|
||||
]
|
||||
[
|
||||
[
|
||||
[`r -= n`]
|
||||
[`X&`]
|
||||
[`return r += -n`]
|
||||
@ -300,9 +312,9 @@ constant object of type `Distance`.
|
||||
[`a - n`]
|
||||
[`X`]
|
||||
[``
|
||||
{
|
||||
{
|
||||
X tmp = a;
|
||||
return tmp-= n;
|
||||
return tmp-= n;
|
||||
}
|
||||
``]
|
||||
[]
|
||||
@ -320,7 +332,7 @@ constant object of type `Distance`.
|
||||
[pre: a is a *Readable Iterator*]
|
||||
]
|
||||
[
|
||||
[`a\[n\] = v`]
|
||||
[`a\[n\] = v`]
|
||||
[convertible to T]
|
||||
[`*(a + n) = v`]
|
||||
[pre: a is a *Writable iterator*]
|
||||
@ -359,4 +371,6 @@ constant object of type `Distance`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
@ -141,7 +141,7 @@ standardize the gateway protocol. Note that even if
|
||||
open a safety loophole, as every core member function preserves the
|
||||
invariants of the iterator.
|
||||
|
||||
[h2 `operator\[\]`]
|
||||
[h2 `operator[]`]
|
||||
|
||||
The indexing operator for a generalized iterator presents special
|
||||
challenges. A random access iterator's `operator[]` is only
|
||||
@ -289,7 +289,7 @@ The `iterator_category` member of `iterator_facade` is
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
*iterator-category*\ (CategoryOrTraversal, value_type, reference)
|
||||
*iterator-category*\ (CategoryOrTraversal, reference, value_type)
|
||||
|
||||
where *iterator-category* is defined as follows:
|
||||
|
||||
@ -297,10 +297,10 @@ where *iterator-category* is defined as follows:
|
||||
|
||||
The `enable_if_interoperable` template used above is for exposition
|
||||
purposes. The member operators should only be in an overload set
|
||||
provided the derived types `Dr1` and `Dr2` are interoperable,
|
||||
provided the derived types `Dr1` and `Dr2` are interoperable,
|
||||
meaning that at least one of the types is convertible to the other. The
|
||||
`enable_if_interoperable` approach uses SFINAE to take the operators
|
||||
out of the overload set when the types are not interoperable.
|
||||
out of the overload set when the types are not interoperable.
|
||||
The operators should behave *as-if* `enable_if_interoperable`
|
||||
were defined to be:
|
||||
|
||||
@ -400,7 +400,7 @@ through member functions of class `iterator_core_access`.
|
||||
__ `operator arrow`_
|
||||
|
||||
[*Returns:] If `reference` is a reference type, an object of type `pointer` equal to: `&static_cast<Derived const*>(this)->dereference()`
|
||||
Otherwise returns an object of unspecified type such that,
|
||||
Otherwise returns an object of unspecified type such that,
|
||||
`(*static_cast<Derived const*>(this))->m` is equivalent to `(w = **static_cast<Derived const*>(this),
|
||||
w.m)` for some temporary object `w` of type `value_type`.
|
||||
|
||||
@ -417,7 +417,7 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
|
||||
Derived& operator++();
|
||||
|
||||
[*Effects:]
|
||||
[*Effects:]
|
||||
|
||||
static_cast<Derived*>(this)->increment();
|
||||
return *static_cast<Derived*>(this);
|
||||
@ -457,7 +457,7 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
Derived& operator-=(difference_type n);
|
||||
|
||||
[*Effects:]
|
||||
|
||||
|
||||
static_cast<Derived*>(this)->advance(-n);
|
||||
return *static_cast<Derived*>(this);
|
||||
|
||||
@ -493,10 +493,10 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`((Dr1 const&)lhs).equal((Dr2 const&)rhs)`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`((Dr2 const&)rhs).equal((Dr1 const&)lhs)`.
|
||||
]
|
||||
|
||||
@ -508,14 +508,14 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
|
||||
|
||||
[*Returns:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`!((Dr1 const&)lhs).equal((Dr2 const&)rhs)`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`!((Dr2 const&)rhs).equal((Dr1 const&)lhs)`.
|
||||
]
|
||||
|
||||
@ -527,14 +527,14 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
|
||||
|
||||
[*Returns:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) < 0`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) > 0`.
|
||||
]
|
||||
|
||||
@ -546,14 +546,14 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
|
||||
|
||||
[*Returns:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) <= 0`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) >= 0`.
|
||||
]
|
||||
|
||||
@ -565,14 +565,14 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
|
||||
|
||||
[*Returns:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) > 0`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) < 0`.
|
||||
]
|
||||
|
||||
@ -584,14 +584,14 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
|
||||
|
||||
[*Returns:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`((Dr1 const&)lhs).distance_to((Dr2 const&)rhs) >= 0`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`((Dr2 const&)rhs).distance_to((Dr1 const&)lhs) <= 0`.
|
||||
]
|
||||
|
||||
@ -605,27 +605,27 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
|
||||
|
||||
[*Return Type:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`difference` shall be
|
||||
`iterator_traits<Dr1>::difference_type`.
|
||||
|
||||
Otherwise
|
||||
Otherwise
|
||||
`difference` shall be `iterator_traits<Dr2>::difference_type`
|
||||
]
|
||||
|
||||
[*Returns:]
|
||||
|
||||
|
||||
[pre
|
||||
if `is_convertible<Dr2,Dr1>::value`
|
||||
|
||||
then
|
||||
then
|
||||
`-((Dr1 const&)lhs).distance_to((Dr2 const&)rhs)`.
|
||||
|
||||
Otherwise,
|
||||
Otherwise,
|
||||
`((Dr2 const&)rhs).distance_to((Dr1 const&)lhs)`.
|
||||
]
|
||||
|
||||
@ -634,4 +634,4 @@ w.m)` for some temporary object `w` of type `value_type`.
|
||||
|
||||
[include facade_tutorial.qbk]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
@ -285,7 +285,7 @@ changes:
|
||||
|
||||
class const_node_iterator
|
||||
: public boost::iterator_facade<
|
||||
node_iterator
|
||||
const_node_iterator
|
||||
, node_base **const**
|
||||
, boost::forward_traversal_tag
|
||||
>
|
||||
|
@ -35,7 +35,7 @@ proxy object.
|
||||
|
||||
std::string s = "";
|
||||
std::copy(x.begin(), x.end(),
|
||||
boost::make_function_output_iterator(string_appender(s)));
|
||||
boost::make_function_output_iterator(string_appender(s)));
|
||||
|
||||
std::cout << s << std::endl;
|
||||
|
||||
@ -97,4 +97,4 @@ Incrementable Iterator concepts.
|
||||
|
||||
[*Returns: ] `*this`.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
@ -29,7 +29,10 @@
|
||||
|
||||
[/ Links ]
|
||||
|
||||
[def _iterator_ [@../../libs/iterator/doc/index.html Boost.Iterator]]
|
||||
[def _iterator_ [@../../../iterator/doc/index.html Boost.Iterator]]
|
||||
[def _concept_check_ [@../../../concept_check/index.html Boost.ConceptCheck]]
|
||||
|
||||
[template sub[x]'''<subscript>'''[x]'''</subscript>''']
|
||||
|
||||
[section:intro Introduction]
|
||||
|
||||
@ -71,19 +74,23 @@ and a _GOTW_50_. New-style iterators go well beyond
|
||||
patching up `vector<bool>`, though: there are lots of other
|
||||
iterators already in use which can't be adequately represented by
|
||||
the existing concepts. For details about the new iterator
|
||||
concepts, see our [@./new-iter-concepts.html Standard Proposal for New-Style Iterators].
|
||||
concepts, see our [@../new-iter-concepts.html Standard Proposal for New-Style Iterators].
|
||||
|
||||
[h2 Iterator Facade and Adaptor]
|
||||
|
||||
[def _facade_ [@./iterator_facade.html facade]]
|
||||
[def _adaptor_ [@./iterator_adaptor.html adaptor]]
|
||||
[/
|
||||
[def _facade_ [link iterator.generic.facade facade]]
|
||||
[def _adaptor_ [link iterator.generic.adaptor adaptor]]
|
||||
]
|
||||
[def _facade_ [@../iterator_facade.html facade]]
|
||||
[def _adaptor_ [@../iterator_adaptor.html adaptor]]
|
||||
|
||||
Writing standard-conforming iterators is tricky, but the need comes
|
||||
up often. In order to ease the implementation of new iterators,
|
||||
the Boost.Iterator library provides the _facade_ class template,
|
||||
which implements many useful defaults and compile-time checks
|
||||
designed to help the iterator author ensure that his iterator is
|
||||
correct.
|
||||
correct.
|
||||
|
||||
It is also common to define a new iterator that is similar to some
|
||||
underlying iterator or iterator-like type, but that modifies some
|
||||
@ -92,9 +99,9 @@ library supplies the _adaptor_ class template, which is specially
|
||||
designed to take advantage of as much of the underlying type's
|
||||
behavior as possible.
|
||||
|
||||
Both _facade_ and _adaptor_ as well as many of the `specialized
|
||||
adaptors`_ mentioned below have been proposed for standardization
|
||||
([@./facade-and-adaptor.html Standard Proposal For Iterator Facade and Adaptor]).
|
||||
Both _facade_ and _adaptor_ as well as many of the [link iterator.specialized specialized
|
||||
adaptors] mentioned below have been proposed for standardization
|
||||
([@../facade-and-adaptor.html Standard Proposal For Iterator Facade and Adaptor]).
|
||||
|
||||
[h2 Specialized Adaptors]
|
||||
|
||||
@ -103,15 +110,17 @@ iterator templates based on the Boost [link
|
||||
iterator.intro.iterator_facade_and_adaptor iterator facade and adaptor]
|
||||
templates.
|
||||
|
||||
[def _counting_ [@./counting_iterator.html `counting_iterator`]]
|
||||
[def _filter_ [@./filter_iterator.html `filter_iterator`]]
|
||||
[def _function_ [@./function_output_iterator.html `function_output_iterator`]]
|
||||
[def _indirect_ [@./indirect_iterator.html `indirect_iterator`]]
|
||||
[def _permutation_ [@./permutation_iterator.html `permutation_iterator`]]
|
||||
[def _reverse_ [@./reverse_iterator.html `reverse_iterator`]]
|
||||
[def _shared_ [@./shared_container_iterator.html `shared_container_iterator`]]
|
||||
[def _transform_ [@./transform_iterator.html `transform_iterator`]]
|
||||
[def _zip_ [@./zip_iterator.html `zip_iterator`]]
|
||||
[def _counting_ [link iterator.specialized.counting `counting_iterator`]]
|
||||
[def _filter_ [link iterator.specialized.filter `filter_iterator`]]
|
||||
[def _function_input_ [@../function_input_iterator.html `function_input_iterator`]]
|
||||
[def _function_output_ [link iterator.specialized.function_output `function_output_iterator`]]
|
||||
[def _generator_ [@../generator_iterator.htm `generator_iterator`]]
|
||||
[def _indirect_ [link iterator.specialized.indirect `indirect_iterator`]]
|
||||
[def _permutation_ [link iterator.specialized.permutation `permutation_iterator`]]
|
||||
[def _reverse_ [link iterator.specialized.reverse `reverse_iterator`]]
|
||||
[def _shared_ [link iterator.specialized.shared_container `shared_container_iterator`]]
|
||||
[def _transform_ [link iterator.specialized.transform `transform_iterator`]]
|
||||
[def _zip_ [link iterator.specialized.zip `zip_iterator`]]
|
||||
|
||||
[def _shared_ptr_ [@../../smart_ptr/shared_ptr.htm `shared_ptr`]]
|
||||
|
||||
@ -121,10 +130,18 @@ templates.
|
||||
* _filter_: an iterator over the subset of elements of some
|
||||
sequence which satisfy a given predicate
|
||||
|
||||
* _function_: an output iterator wrapping a unary function
|
||||
* _function_input_: an input iterator wrapping a generator (nullary
|
||||
function object); each time the iterator is dereferenced, the function object
|
||||
is called to get the value to return.
|
||||
|
||||
* _function_output_: an output iterator wrapping a unary function
|
||||
object; each time an element is written into the dereferenced
|
||||
iterator, it is passed as a parameter to the function object.
|
||||
|
||||
* _generator_: an input iterator wrapping a generator (nullary
|
||||
function object); each time the iterator is dereferenced, the function object
|
||||
is called to get the value to return. An outdated analogue of _function_input_.
|
||||
|
||||
* _indirect_: an iterator over the objects *pointed-to* by the
|
||||
elements of some sequence.
|
||||
|
||||
@ -133,7 +150,7 @@ templates.
|
||||
|
||||
* _reverse_: an iterator which traverses the elements of some
|
||||
bidirectional sequence in reverse. Corrects many of the
|
||||
shortcomings of C++98's ``std::reverse_iterator``.
|
||||
shortcomings of C++98's `std::reverse_iterator`.
|
||||
|
||||
* _shared_: an iterator over elements of a container whose
|
||||
lifetime is maintained by a _shared_ptr_ stored in the iterator.
|
||||
@ -141,7 +158,7 @@ templates.
|
||||
* _transform_: an iterator over elements which are the result of
|
||||
applying some functional transformation to the elements of an
|
||||
underlying sequence. This component also replaces the old
|
||||
``projection_iterator_adaptor``.
|
||||
`projection_iterator_adaptor`.
|
||||
|
||||
* _zip_: an iterator over tuples of the elements at corresponding
|
||||
positions of heterogeneous underlying iterators.
|
||||
@ -150,9 +167,9 @@ templates.
|
||||
|
||||
[h3 Traits]
|
||||
|
||||
[def _pointee_ [@./pointee.html `pointee.hpp`]]
|
||||
[def _iterator_traits_ [@./iterator_traits.html `iterator_traits.hpp`]]
|
||||
[def _interoperable_ [@./interoperable.html `interoperable.hpp`]]
|
||||
[def _pointee_ [link iterator.utilities.traits `pointee.hpp`]]
|
||||
[def _iterator_traits_ [link iterator.utilities.iterator_traits `iterator_traits.hpp`]]
|
||||
[def _interoperable_ [@../interoperable.html `interoperable.hpp`]]
|
||||
[def _MPL_ [@../../mpl/doc/index.html [*MPL]]]
|
||||
|
||||
* _pointee_: Provides the capability to deduce the referent types
|
||||
@ -163,19 +180,40 @@ templates.
|
||||
retrieve an iterator's traits. Also corrects for the deficiencies
|
||||
of broken implementations of `std::iterator_traits`.
|
||||
|
||||
[\ * |interoperable|_ (PDF__): Provides an _MPL_ compatible metafunction for
|
||||
testing iterator interoperability
|
||||
[/
|
||||
* _interoperable_: Provides an _MPL_ compatible metafunction for
|
||||
testing iterator interoperability
|
||||
]
|
||||
|
||||
[h3 Testing and Concept Checking]
|
||||
|
||||
[def _iterator_concepts_ [@./iterator_concepts.html `iterator_concepts.hpp`]]
|
||||
[def _iterator_archetypes_ [@./iterator_archetypes.html `iterator_archetypes.hpp`]]
|
||||
[def _iterator_concepts_ [link iterator.concepts `iterator_concepts.hpp`]]
|
||||
[def _iterator_archetypes_ [link iterator.utilities.archetypes `iterator_archetypes.hpp`]]
|
||||
|
||||
* _iterator_concepts_: Concept checking classes for the new iterator concepts.
|
||||
|
||||
* _iterator_archetypes_: Concept archetype classes for the new iterators concepts.
|
||||
|
||||
[h2 Iterator Algorithms]
|
||||
|
||||
The library provides a number of generic algorithms for use with iterators. These
|
||||
algorithms take advantage of the new concepts defined by the library to provide
|
||||
better performance and functionality.
|
||||
|
||||
[def _advance_ [link iterator.algorithms.advance `advance.hpp`]]
|
||||
[def _distance_ [link iterator.algorithms.distance `distance.hpp`]]
|
||||
[def _next_prior_ [link iterator.algorithms.next_prior `next_prior.hpp`]]
|
||||
|
||||
* _advance_: Provides `advance()` function for advancing an iterator a given number
|
||||
of positions forward or backward.
|
||||
|
||||
* _distance_: Provides `distance()` function for computing distance between two
|
||||
iterators.
|
||||
|
||||
* _next_prior_: Provides `next()` and `prior()` functions for obtaining
|
||||
next and prior iterators to a given iterator. The functions are also compatible
|
||||
with non-iterator types.
|
||||
|
||||
[endsect]
|
||||
|
||||
[include concepts.qbk]
|
||||
@ -196,12 +234,14 @@ templates.
|
||||
|
||||
[include concept_checking.qbk]
|
||||
|
||||
[include traits.qbk]
|
||||
[include iterator_traits.qbk]
|
||||
|
||||
[include utilities.qbk]
|
||||
[include type_traits.qbk]
|
||||
|
||||
[endsect]
|
||||
|
||||
[include algorithms.qbk]
|
||||
|
||||
[section:upgrading Upgrading from the old Boost Iterator Adaptor Library]
|
||||
|
||||
[def _type_generator_ [@http://www.boost.org/more/generic_programming.html#type_generator type generator]]
|
||||
@ -266,4 +306,3 @@ library you see today.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
[section:traits Iterator Traits]
|
||||
[section:iterator_traits Iterator Traits]
|
||||
|
||||
`std::iterator_traits` provides access to five associated types
|
||||
of any iterator: its `value_type`, `reference`, `pointer`,
|
||||
@ -15,15 +15,15 @@ Header `<boost/iterator/iterator_traits.hpp>`:
|
||||
template <class Iterator>
|
||||
struct iterator_value
|
||||
{
|
||||
typedef typename
|
||||
std::iterator_traits<Iterator>::value_type
|
||||
typedef typename
|
||||
std::iterator_traits<Iterator>::value_type
|
||||
type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_reference
|
||||
{
|
||||
typedef typename
|
||||
typedef typename
|
||||
std::iterator_traits<Iterator>::reference
|
||||
type;
|
||||
};
|
||||
@ -31,8 +31,8 @@ Header `<boost/iterator/iterator_traits.hpp>`:
|
||||
template <class Iterator>
|
||||
struct iterator_pointer
|
||||
{
|
||||
typedef typename
|
||||
std::iterator_traits<Iterator>::pointer
|
||||
typedef typename
|
||||
std::iterator_traits<Iterator>::pointer
|
||||
type;
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ original shared pointer `ints` ceases to exist after `set_range()`
|
||||
returns, the `shared_counter_iterator` objects maintain references to
|
||||
the underlying vector and thereby extend the container's lifetime.
|
||||
|
||||
[@../../../libs/utility/shared_iterator_example1.cpp `shared_iterator_example1.cpp`]:
|
||||
[@../../example/shared_iterator_example1.cpp `shared_iterator_example1.cpp`]:
|
||||
|
||||
#include "shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
@ -139,7 +139,7 @@ explicitly specifying its type.
|
||||
This example, similar to the previous,
|
||||
uses `make_shared_container_iterator()` to create the iterators.
|
||||
|
||||
[@../../../libs/utility/shared_iterator_example2.cpp `shared_iterator_example2.cpp`]:
|
||||
[@../../example/shared_iterator_example2.cpp `shared_iterator_example2.cpp`]:
|
||||
|
||||
#include "shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
@ -200,7 +200,7 @@ named. The output from this example is the same as the previous.
|
||||
|
||||
In the following example, a range of values is returned as a pair of shared_container_iterator objects.
|
||||
|
||||
[@../../../libs/utility/shared_iterator_example3.cpp `shared_iterator_example3.cpp`]:
|
||||
[@../../example/shared_iterator_example3.cpp `shared_iterator_example3.cpp`]:
|
||||
|
||||
#include "shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
|
@ -86,7 +86,7 @@ The source code for this example can be found
|
||||
|
||||
If `Reference` is `use_default` then the `reference` member of
|
||||
`transform_iterator` is[br]
|
||||
`result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type`.
|
||||
`result_of<const UnaryFunction(iterator_traits<Iterator>::reference)>::type`.
|
||||
Otherwise, `reference` is `Reference`.
|
||||
|
||||
|
||||
@ -110,10 +110,10 @@ convertible to `input_iterator_tag`.
|
||||
|
||||
|
||||
The type `UnaryFunction` must be Assignable, Copy Constructible, and
|
||||
the expression `f(*i)` must be valid where `f` is an object of
|
||||
the expression `f(*i)` must be valid where `f` is a const object of
|
||||
type `UnaryFunction`, `i` is an object of type `Iterator`, and
|
||||
where the type of `f(*i)` must be
|
||||
`result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type`.
|
||||
`result_of<const UnaryFunction(iterator_traits<Iterator>::reference)>::type`.
|
||||
|
||||
|
||||
The argument `Iterator` shall model Readable Iterator.
|
||||
|
@ -1,7 +1,4 @@
|
||||
|
||||
[section:utilities Iterator Utilities]
|
||||
|
||||
[section:utilities_traits Traits]
|
||||
[section:traits Type Traits]
|
||||
|
||||
[h2 Overview]
|
||||
|
||||
@ -212,113 +209,3 @@ Otherwise, `type` is defined to the closest iterator traversal tag matching `C`.
|
||||
[*Requires:] `Iterator` shall be an iterator.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:utilities_testing Testing and Concept Checking]
|
||||
|
||||
The iterator concept checking classes provide a mechanism for a
|
||||
template to report better error messages when a user instantiates
|
||||
the template with a type that does not meet the requirements of the
|
||||
template.
|
||||
|
||||
For an introduction to using concept checking classes, see
|
||||
the documentation for the
|
||||
[@../../concept_check/index.html `boost::concept_check`] library.
|
||||
|
||||
|
||||
[h2 Reference]
|
||||
|
||||
[h3 Iterator Access Concepts]
|
||||
|
||||
* |Readable|_
|
||||
* |Writable|_
|
||||
* |Swappable|_
|
||||
* |Lvalue|_
|
||||
|
||||
[/ .. |Readable| replace:: *Readable Iterator* ]
|
||||
[/ .. _Readable: ReadableIterator.html ]
|
||||
[/ ]
|
||||
[/ .. |Writable| replace:: *Writable Iterator* ]
|
||||
[/ .. _Writable: WritableIterator.html ]
|
||||
[/ ]
|
||||
[/ .. |Swappable| replace:: *Swappable Iterator* ]
|
||||
[/ .. _Swappable: SwappableIterator.html ]
|
||||
[/ ]
|
||||
[/ .. |Lvalue| replace:: *Lvalue Iterator* ]
|
||||
[/ .. _Lvalue: LvalueIterator.html ]
|
||||
|
||||
|
||||
Iterator Traversal Concepts
|
||||
...........................
|
||||
|
||||
* |Incrementable|_
|
||||
* |SinglePass|_
|
||||
* |Forward|_
|
||||
* |Bidir|_
|
||||
* |Random|_
|
||||
|
||||
|
||||
[/ .. |Incrementable| replace:: *Incrementable Iterator* ]
|
||||
[/ .. _Incrementable: IncrementableIterator.html ]
|
||||
[/ ]
|
||||
[/ .. |SinglePass| replace:: *Single Pass Iterator* ]
|
||||
[/ .. _SinglePass: SinglePassIterator.html ]
|
||||
[/ ]
|
||||
[/ .. |Forward| replace:: *Forward Traversal* ]
|
||||
[/ .. _Forward: ForwardTraversal.html ]
|
||||
[/ ]
|
||||
[/ .. |Bidir| replace:: *Bidirectional Traversal* ]
|
||||
[/ .. _Bidir: BidirectionalTraversal.html ]
|
||||
[/ ]
|
||||
[/ .. |Random| replace:: *Random Access Traversal* ]
|
||||
[/ .. _Random: RandomAccessTraversal.html ]
|
||||
|
||||
|
||||
|
||||
[h3 `iterator_concepts.hpp` Synopsis]
|
||||
|
||||
namespace boost_concepts {
|
||||
|
||||
// Iterator Access Concepts
|
||||
|
||||
template <typename Iterator>
|
||||
class ReadableIteratorConcept;
|
||||
|
||||
template <
|
||||
typename Iterator
|
||||
, typename ValueType = std::iterator_traits<Iterator>::value_type
|
||||
>
|
||||
class WritableIteratorConcept;
|
||||
|
||||
template <typename Iterator>
|
||||
class SwappableIteratorConcept;
|
||||
|
||||
template <typename Iterator>
|
||||
class LvalueIteratorConcept;
|
||||
|
||||
// Iterator Traversal Concepts
|
||||
|
||||
template <typename Iterator>
|
||||
class IncrementableIteratorConcept;
|
||||
|
||||
template <typename Iterator>
|
||||
class SinglePassIteratorConcept;
|
||||
|
||||
template <typename Iterator>
|
||||
class ForwardTraversalConcept;
|
||||
|
||||
template <typename Iterator>
|
||||
class BidirectionalTraversalConcept;
|
||||
|
||||
template <typename Iterator>
|
||||
class RandomAccessTraversalConcept;
|
||||
|
||||
// Interoperability
|
||||
|
||||
template <typename Iterator, typename ConstIterator>
|
||||
class InteroperableIteratorConcept;
|
||||
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
@ -45,8 +45,7 @@ A non-generic implementation of ``zip_func`` could look as follows:
|
||||
::
|
||||
|
||||
|
||||
struct zip_func :
|
||||
public std::unary_function<const boost::tuple<const double&, const int&>&, void>
|
||||
struct zip_func
|
||||
{
|
||||
void operator()(const boost::tuple<const double&, const int&>& t) const
|
||||
{
|
||||
|
@ -11,7 +11,17 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<node<int> > nodes(new node<int>(42));
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<node<int> > nodes(new node<int>(42));
|
||||
|
||||
#endif
|
||||
|
||||
nodes->append(new node<std::string>(" is greater than "));
|
||||
nodes->append(new node<int>(13));
|
||||
|
||||
|
@ -12,7 +12,17 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<node<int> > nodes(new node<int>(42));
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<node<int> > nodes(new node<int>(42));
|
||||
|
||||
#endif
|
||||
|
||||
nodes->append(new node<std::string>(" is greater than "));
|
||||
nodes->append(new node<int>(13));
|
||||
|
||||
|
@ -12,7 +12,17 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
#if defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
std::auto_ptr<node<int> > nodes(new node<int>(42));
|
||||
|
||||
#else
|
||||
|
||||
std::unique_ptr<node<int> > nodes(new node<int>(42));
|
||||
|
||||
#endif
|
||||
|
||||
nodes->append(new node<std::string>(" is greater than "));
|
||||
nodes->append(new node<int>(13));
|
||||
|
||||
|
42
example/shared_iterator_example1.cpp
Normal file
42
example/shared_iterator_example1.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
typedef boost::shared_container_iterator< std::vector<int> > iterator;
|
||||
|
||||
|
||||
void set_range(iterator& i, iterator& end) {
|
||||
|
||||
boost::shared_ptr< std::vector<int> > ints(new std::vector<int>());
|
||||
|
||||
ints->push_back(0);
|
||||
ints->push_back(1);
|
||||
ints->push_back(2);
|
||||
ints->push_back(3);
|
||||
ints->push_back(4);
|
||||
ints->push_back(5);
|
||||
|
||||
i = iterator(ints->begin(),ints);
|
||||
end = iterator(ints->end(),ints);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
iterator i,end;
|
||||
|
||||
set_range(i,end);
|
||||
|
||||
std::copy(i,end,std::ostream_iterator<int>(std::cout,","));
|
||||
std::cout.put('\n');
|
||||
|
||||
return 0;
|
||||
}
|
43
example/shared_iterator_example2.cpp
Normal file
43
example/shared_iterator_example2.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
template <typename Iterator>
|
||||
void print_range_nl (Iterator begin, Iterator end) {
|
||||
typedef typename std::iterator_traits<Iterator>::value_type val;
|
||||
std::copy(begin,end,std::ostream_iterator<val>(std::cout,","));
|
||||
std::cout.put('\n');
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
typedef boost::shared_ptr< std::vector<int> > ints_t;
|
||||
{
|
||||
ints_t ints(new std::vector<int>());
|
||||
|
||||
ints->push_back(0);
|
||||
ints->push_back(1);
|
||||
ints->push_back(2);
|
||||
ints->push_back(3);
|
||||
ints->push_back(4);
|
||||
ints->push_back(5);
|
||||
|
||||
print_range_nl(boost::make_shared_container_iterator(ints->begin(),ints),
|
||||
boost::make_shared_container_iterator(ints->end(),ints));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
41
example/shared_iterator_example3.cpp
Normal file
41
example/shared_iterator_example3.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include "boost/tuple/tuple.hpp" // for boost::tie
|
||||
#include <algorithm> // for std::copy
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
typedef boost::shared_container_iterator< std::vector<int> > iterator;
|
||||
|
||||
std::pair<iterator,iterator>
|
||||
return_range() {
|
||||
boost::shared_ptr< std::vector<int> > range(new std::vector<int>());
|
||||
range->push_back(0);
|
||||
range->push_back(1);
|
||||
range->push_back(2);
|
||||
range->push_back(3);
|
||||
range->push_back(4);
|
||||
range->push_back(5);
|
||||
return boost::make_shared_container_range(range);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
iterator i,end;
|
||||
|
||||
boost::tie(i,end) = return_range();
|
||||
|
||||
std::copy(i,end,std::ostream_iterator<int>(std::cout,","));
|
||||
std::cout.put('\n');
|
||||
|
||||
return 0;
|
||||
}
|
@ -16,9 +16,10 @@
|
||||
namespace boost {
|
||||
|
||||
template <class Operation>
|
||||
class binder1st
|
||||
: public std::unary_function<typename Operation::second_argument_type,
|
||||
typename Operation::result_type> {
|
||||
class binder1st {
|
||||
public:
|
||||
typedef typename Operation::result_type result_type;
|
||||
typedef typename Operation::second_argument_type argument_type;
|
||||
protected:
|
||||
Operation op;
|
||||
typename Operation::first_argument_type value;
|
||||
@ -29,7 +30,7 @@ namespace boost {
|
||||
: op(x), value(y) {}
|
||||
typename Operation::result_type
|
||||
operator()(const typename Operation::second_argument_type& x) const {
|
||||
return op(value, x);
|
||||
return op(value, x);
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,5 +73,3 @@ main(int, char*[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,62 +1,14 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Andrey Semashev 2017.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Revision History:
|
||||
|
||||
// 27 Feb 2001 Jeremy Siek
|
||||
// Initial checkin.
|
||||
|
||||
#ifndef BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
#define BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
// This is a deprecated header left for backward compatibility.
|
||||
// Use boost/iterator/function_output_iterator.hpp instead.
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
template <class UnaryFunction>
|
||||
class function_output_iterator {
|
||||
typedef function_output_iterator self;
|
||||
public:
|
||||
typedef std::output_iterator_tag iterator_category;
|
||||
typedef void value_type;
|
||||
typedef void difference_type;
|
||||
typedef void pointer;
|
||||
typedef void reference;
|
||||
|
||||
explicit function_output_iterator() {}
|
||||
|
||||
explicit function_output_iterator(const UnaryFunction& f)
|
||||
: m_f(f) {}
|
||||
|
||||
struct output_proxy {
|
||||
output_proxy(UnaryFunction& f) : m_f(f) { }
|
||||
template <class T> output_proxy& operator=(const T& value) {
|
||||
m_f(value);
|
||||
return *this;
|
||||
}
|
||||
UnaryFunction& m_f;
|
||||
};
|
||||
output_proxy operator*() { return output_proxy(m_f); }
|
||||
self& operator++() { return *this; }
|
||||
self& operator++(int) { return *this; }
|
||||
private:
|
||||
UnaryFunction m_f;
|
||||
};
|
||||
|
||||
template <class UnaryFunction>
|
||||
inline function_output_iterator<UnaryFunction>
|
||||
make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) {
|
||||
return function_output_iterator<UnaryFunction>(f);
|
||||
}
|
||||
|
||||
} // namespace iterators
|
||||
|
||||
using iterators::function_output_iterator;
|
||||
using iterators::make_function_output_iterator;
|
||||
|
||||
} // namespace boost
|
||||
#include <boost/iterator/function_output_iterator.hpp>
|
||||
|
||||
#endif // BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
|
84
include/boost/iterator/advance.hpp
Normal file
84
include/boost/iterator/advance.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
// Copyright (C) 2017 Michel Morin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_ITERATOR_ADVANCE_HPP
|
||||
#define BOOST_ITERATOR_ADVANCE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
namespace detail {
|
||||
template <typename InputIterator, typename Distance>
|
||||
inline BOOST_CXX14_CONSTEXPR void
|
||||
advance_impl(
|
||||
InputIterator& it
|
||||
, Distance n
|
||||
, incrementable_traversal_tag
|
||||
)
|
||||
{
|
||||
while (n > 0) {
|
||||
++it;
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BidirectionalIterator, typename Distance>
|
||||
inline BOOST_CXX14_CONSTEXPR void
|
||||
advance_impl(
|
||||
BidirectionalIterator& it
|
||||
, Distance n
|
||||
, bidirectional_traversal_tag
|
||||
)
|
||||
{
|
||||
if (n >= 0) {
|
||||
while (n > 0) {
|
||||
++it;
|
||||
--n;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (n < 0) {
|
||||
--it;
|
||||
++n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename RandomAccessIterator, typename Distance>
|
||||
inline BOOST_CXX14_CONSTEXPR void
|
||||
advance_impl(
|
||||
RandomAccessIterator& it
|
||||
, Distance n
|
||||
, random_access_traversal_tag
|
||||
)
|
||||
{
|
||||
it += n;
|
||||
}
|
||||
}
|
||||
|
||||
namespace advance_adl_barrier {
|
||||
template <typename InputIterator, typename Distance>
|
||||
inline BOOST_CXX14_CONSTEXPR void
|
||||
advance(InputIterator& it, Distance n)
|
||||
{
|
||||
detail::advance_impl(
|
||||
it, n, typename iterator_traversal<InputIterator>::type()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
using namespace advance_adl_barrier;
|
||||
|
||||
} // namespace iterators
|
||||
|
||||
using iterators::advance;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
65
include/boost/iterator/distance.hpp
Normal file
65
include/boost/iterator/distance.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (C) 2017 Michel Morin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_ITERATOR_DISTANCE_HPP
|
||||
#define BOOST_ITERATOR_DISTANCE_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
namespace detail {
|
||||
template <typename SinglePassIterator>
|
||||
inline BOOST_CXX14_CONSTEXPR typename iterator_difference<SinglePassIterator>::type
|
||||
distance_impl(
|
||||
SinglePassIterator first
|
||||
, SinglePassIterator last
|
||||
, single_pass_traversal_tag
|
||||
)
|
||||
{
|
||||
typename iterator_difference<SinglePassIterator>::type n = 0;
|
||||
while (first != last) {
|
||||
++first;
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
template <typename RandomAccessIterator>
|
||||
inline BOOST_CXX14_CONSTEXPR typename iterator_difference<RandomAccessIterator>::type
|
||||
distance_impl(
|
||||
RandomAccessIterator first
|
||||
, RandomAccessIterator last
|
||||
, random_access_traversal_tag
|
||||
)
|
||||
{
|
||||
return last - first;
|
||||
}
|
||||
}
|
||||
|
||||
namespace distance_adl_barrier {
|
||||
template <typename SinglePassIterator>
|
||||
inline BOOST_CXX14_CONSTEXPR typename iterator_difference<SinglePassIterator>::type
|
||||
distance(SinglePassIterator first, SinglePassIterator last)
|
||||
{
|
||||
return detail::distance_impl(
|
||||
first, last, typename iterator_traversal<SinglePassIterator>::type()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
using namespace distance_adl_barrier;
|
||||
|
||||
} // namespace iterators
|
||||
|
||||
using iterators::distance;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
@ -7,7 +7,6 @@
|
||||
#ifndef BOOST_FILTER_ITERATOR_23022003THW_HPP
|
||||
#define BOOST_FILTER_ITERATOR_23022003THW_HPP
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
|
||||
|
@ -11,34 +11,53 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/core/addressof.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/function_types/is_function_pointer.hpp>
|
||||
#include <boost/function_types/is_function_reference.hpp>
|
||||
#include <boost/function_types/result_type.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_TR1
|
||||
#include <boost/type_traits/is_function.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace iterators {
|
||||
|
||||
namespace impl {
|
||||
|
||||
// Computes the return type of an lvalue-call with an empty argument,
|
||||
// i.e. decltype(declval<F&>()()). F should be a nullary lvalue-callable
|
||||
// or function.
|
||||
template <class F>
|
||||
struct result_of_nullary_lvalue_call
|
||||
{
|
||||
typedef typename result_of<
|
||||
#ifdef BOOST_RESULT_OF_USE_TR1
|
||||
typename mpl::if_<is_function<F>, F&, F>::type()
|
||||
#else
|
||||
F&()
|
||||
#endif
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class Function, class Input>
|
||||
class function_input_iterator
|
||||
: public iterator_facade<
|
||||
function_input_iterator<Function, Input>,
|
||||
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type,
|
||||
typename result_of_nullary_lvalue_call<Function>::type,
|
||||
single_pass_traversal_tag,
|
||||
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
|
||||
typename result_of_nullary_lvalue_call<Function>::type const &
|
||||
>
|
||||
{
|
||||
public:
|
||||
function_input_iterator() {}
|
||||
function_input_iterator(Function & f_, Input state_ = Input())
|
||||
: f(&f_), state(state_) {}
|
||||
: f(boost::addressof(f_)), state(state_) {}
|
||||
|
||||
void increment() {
|
||||
if(value)
|
||||
@ -48,7 +67,7 @@ namespace iterators {
|
||||
++state;
|
||||
}
|
||||
|
||||
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
|
||||
typename result_of_nullary_lvalue_call<Function>::type const &
|
||||
dereference() const {
|
||||
return (value ? value : value = (*f)()).get();
|
||||
}
|
||||
@ -60,7 +79,7 @@ namespace iterators {
|
||||
private:
|
||||
Function * f;
|
||||
Input state;
|
||||
mutable optional<BOOST_DEDUCED_TYPENAME result_of<Function ()>::type> value;
|
||||
mutable optional<typename result_of_nullary_lvalue_call<Function>::type> value;
|
||||
};
|
||||
|
||||
template <class Function, class Input>
|
||||
@ -100,16 +119,6 @@ namespace iterators {
|
||||
mutable optional<typename function_types::result_type<Function>::type> value;
|
||||
};
|
||||
|
||||
template <class Function, class Input>
|
||||
class function_reference_input_iterator
|
||||
: public function_pointer_input_iterator<Function*,Input>
|
||||
{
|
||||
public:
|
||||
function_reference_input_iterator(Function & f_, Input state_ = Input())
|
||||
: function_pointer_input_iterator<Function*,Input>(&f_, state_)
|
||||
{}
|
||||
};
|
||||
|
||||
} // namespace impl
|
||||
|
||||
template <class Function, class Input>
|
||||
@ -117,21 +126,13 @@ namespace iterators {
|
||||
: public mpl::if_<
|
||||
function_types::is_function_pointer<Function>,
|
||||
impl::function_pointer_input_iterator<Function,Input>,
|
||||
typename mpl::if_<
|
||||
function_types::is_function_reference<Function>,
|
||||
impl::function_reference_input_iterator<Function,Input>,
|
||||
impl::function_input_iterator<Function,Input>
|
||||
>::type
|
||||
impl::function_input_iterator<Function,Input>
|
||||
>::type
|
||||
{
|
||||
typedef typename mpl::if_<
|
||||
function_types::is_function_pointer<Function>,
|
||||
impl::function_pointer_input_iterator<Function,Input>,
|
||||
typename mpl::if_<
|
||||
function_types::is_function_reference<Function>,
|
||||
impl::function_reference_input_iterator<Function,Input>,
|
||||
impl::function_input_iterator<Function,Input>
|
||||
>::type
|
||||
impl::function_input_iterator<Function,Input>
|
||||
>::type base_type;
|
||||
public:
|
||||
function_input_iterator(Function & f, Input i)
|
||||
|
62
include/boost/iterator/function_output_iterator.hpp
Normal file
62
include/boost/iterator/function_output_iterator.hpp
Normal file
@ -0,0 +1,62 @@
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Revision History:
|
||||
|
||||
// 27 Feb 2001 Jeremy Siek
|
||||
// Initial checkin.
|
||||
|
||||
#ifndef BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
#define BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
template <class UnaryFunction>
|
||||
class function_output_iterator {
|
||||
typedef function_output_iterator self;
|
||||
public:
|
||||
typedef std::output_iterator_tag iterator_category;
|
||||
typedef void value_type;
|
||||
typedef void difference_type;
|
||||
typedef void pointer;
|
||||
typedef void reference;
|
||||
|
||||
explicit function_output_iterator() {}
|
||||
|
||||
explicit function_output_iterator(const UnaryFunction& f)
|
||||
: m_f(f) {}
|
||||
|
||||
struct output_proxy {
|
||||
output_proxy(UnaryFunction& f) : m_f(f) { }
|
||||
template <class T> output_proxy& operator=(const T& value) {
|
||||
m_f(value);
|
||||
return *this;
|
||||
}
|
||||
UnaryFunction& m_f;
|
||||
};
|
||||
output_proxy operator*() { return output_proxy(m_f); }
|
||||
self& operator++() { return *this; }
|
||||
self& operator++(int) { return *this; }
|
||||
private:
|
||||
UnaryFunction m_f;
|
||||
};
|
||||
|
||||
template <class UnaryFunction>
|
||||
inline function_output_iterator<UnaryFunction>
|
||||
make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) {
|
||||
return function_output_iterator<UnaryFunction>(f);
|
||||
}
|
||||
|
||||
} // namespace iterators
|
||||
|
||||
using iterators::function_output_iterator;
|
||||
using iterators::make_function_output_iterator;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ITERATOR_FUNCTION_OUTPUT_ITERATOR_HPP
|
@ -7,12 +7,10 @@
|
||||
#ifndef BOOST_INDIRECT_ITERATOR_23022003THW_HPP
|
||||
#define BOOST_INDIRECT_ITERATOR_23022003THW_HPP
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
|
||||
#include <boost/pointee.hpp>
|
||||
#include <boost/indirect_reference.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/detail/indirect_traits.hpp>
|
||||
|
||||
@ -25,6 +23,8 @@
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#ifdef BOOST_MPL_CFG_NO_HAS_XXX
|
||||
# include <boost/shared_ptr.hpp>
|
||||
# include <boost/scoped_ptr.hpp>
|
||||
@ -45,7 +45,7 @@ namespace iterators {
|
||||
template <class Iter, class Value, class Category, class Reference, class Difference>
|
||||
struct indirect_base
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iter>::value_type dereferenceable;
|
||||
typedef typename std::iterator_traits<Iter>::value_type dereferenceable;
|
||||
|
||||
typedef iterator_adaptor<
|
||||
indirect_iterator<Iter, Value, Category, Reference, Difference>
|
||||
|
@ -4,16 +4,15 @@
|
||||
#ifndef IS_LVALUE_ITERATOR_DWA2003112_HPP
|
||||
# define IS_LVALUE_ITERATOR_DWA2003112_HPP
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/type_traits/add_lvalue_reference.hpp>
|
||||
#include <boost/iterator/detail/any_conversion_eater.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/aux_/lambda_support.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
// should be the last #includes
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
@ -125,14 +124,14 @@ namespace detail
|
||||
template <class It>
|
||||
struct is_readable_lvalue_iterator_impl
|
||||
: is_lvalue_iterator_impl<
|
||||
BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<It>::value_type const
|
||||
BOOST_DEDUCED_TYPENAME std::iterator_traits<It>::value_type const
|
||||
>::template rebind<It>
|
||||
{};
|
||||
|
||||
template <class It>
|
||||
struct is_non_const_lvalue_iterator_impl
|
||||
: is_lvalue_iterator_impl<
|
||||
BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<It>::value_type
|
||||
BOOST_DEDUCED_TYPENAME std::iterator_traits<It>::value_type
|
||||
>::template rebind<It>
|
||||
{};
|
||||
} // namespace detail
|
||||
|
@ -6,11 +6,12 @@
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/aux_/lambda_support.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/type_traits/add_lvalue_reference.hpp>
|
||||
|
||||
#include <boost/iterator/detail/any_conversion_eater.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
// should be the last #include
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
@ -93,7 +94,7 @@ namespace detail
|
||||
template <class It>
|
||||
struct is_readable_iterator_impl2
|
||||
: is_readable_iterator_impl<
|
||||
BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<It>::value_type const
|
||||
BOOST_DEDUCED_TYPENAME std::iterator_traits<It>::value_type const
|
||||
>::template rebind<It>
|
||||
{};
|
||||
} // namespace detail
|
||||
|
@ -8,8 +8,6 @@
|
||||
#define BOOST_ITERATOR_ADAPTOR_23022003THW_HPP
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/iterator.hpp>
|
||||
|
||||
#include <boost/iterator/detail/facade_iterator_category.hpp>
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
# define BOOST_ITERATOR_CATEGORIES_HPP
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/detail/iterator.hpp>
|
||||
# include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
# include <boost/detail/workaround.hpp>
|
||||
@ -21,6 +20,8 @@
|
||||
|
||||
# include <boost/static_assert.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
@ -116,7 +117,7 @@ struct iterator_category_to_traversal
|
||||
template <class Iterator = mpl::_1>
|
||||
struct iterator_traversal
|
||||
: iterator_category_to_traversal<
|
||||
typename boost::detail::iterator_traits<Iterator>::iterator_category
|
||||
typename std::iterator_traits<Iterator>::iterator_category
|
||||
>
|
||||
{};
|
||||
|
||||
|
@ -9,9 +9,6 @@
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
|
||||
// Use boost::detail::iterator_traits to work around some MSVC/Dinkumware problems.
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
|
||||
@ -27,6 +24,7 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/concept/detail/concept_def.hpp>
|
||||
|
||||
@ -44,8 +42,8 @@ namespace boost_concepts
|
||||
, boost::CopyConstructible<Iterator>
|
||||
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::reference reference;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::reference reference;
|
||||
|
||||
BOOST_CONCEPT_USAGE(ReadableIterator)
|
||||
{
|
||||
@ -59,7 +57,7 @@ namespace boost_concepts
|
||||
|
||||
template <
|
||||
typename Iterator
|
||||
, typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type
|
||||
, typename ValueType = BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::value_type
|
||||
>
|
||||
struct WritableIterator
|
||||
: boost::CopyConstructible<Iterator>
|
||||
@ -75,7 +73,7 @@ namespace boost_concepts
|
||||
|
||||
template <
|
||||
typename Iterator
|
||||
, typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type
|
||||
, typename ValueType = BOOST_DEDUCED_TYPENAME std::iterator_traits<Iterator>::value_type
|
||||
>
|
||||
struct WritableIteratorConcept : WritableIterator<Iterator,ValueType> {};
|
||||
|
||||
@ -92,7 +90,7 @@ namespace boost_concepts
|
||||
|
||||
BOOST_concept(LvalueIterator,(Iterator))
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
|
||||
BOOST_CONCEPT_USAGE(LvalueIterator)
|
||||
{
|
||||
@ -144,7 +142,7 @@ namespace boost_concepts
|
||||
: SinglePassIterator<Iterator>
|
||||
, boost::DefaultConstructible<Iterator>
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
|
||||
typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_integral<difference_type>));
|
||||
BOOST_MPL_ASSERT_RELATION(std::numeric_limits<difference_type>::is_signed, ==, true);
|
||||
@ -221,7 +219,7 @@ namespace boost_concepts
|
||||
boost::random_access_traversal_tag, boost::random_access_traversal_tag)
|
||||
{
|
||||
bool b;
|
||||
typename boost::detail::iterator_traits<Iterator2>::difference_type n;
|
||||
typename std::iterator_traits<Iterator2>::difference_type n;
|
||||
b = i1 < i2;
|
||||
b = i1 <= i2;
|
||||
b = i1 > i2;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#define BOOST_ITERATOR_FACADE_23022003THW_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/interoperable.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
@ -37,6 +36,8 @@
|
||||
#include <boost/mpl/apply.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <boost/iterator/detail/config_def.hpp> // this goes last
|
||||
|
||||
namespace boost {
|
||||
|
@ -5,9 +5,10 @@
|
||||
#ifndef ITERATOR_TRAITS_DWA200347_HPP
|
||||
# define ITERATOR_TRAITS_DWA200347_HPP
|
||||
|
||||
# include <boost/detail/iterator.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
@ -19,32 +20,32 @@ namespace iterators {
|
||||
template <class Iterator>
|
||||
struct iterator_value
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::value_type type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_reference
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::reference type;
|
||||
typedef typename std::iterator_traits<Iterator>::reference type;
|
||||
};
|
||||
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_pointer
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::pointer type;
|
||||
typedef typename std::iterator_traits<Iterator>::pointer type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_difference
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::difference_type type;
|
||||
typedef typename std::iterator_traits<Iterator>::difference_type type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_category
|
||||
{
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::iterator_category type;
|
||||
typedef typename std::iterator_traits<Iterator>::iterator_category type;
|
||||
};
|
||||
|
||||
} // namespace iterators
|
||||
|
@ -29,17 +29,18 @@
|
||||
// (David Abrahams)
|
||||
|
||||
# include <iterator>
|
||||
# include <boost/type_traits.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
|
||||
# include <boost/detail/iterator.hpp>
|
||||
# include <boost/pending/iterator_tests.hpp>
|
||||
# include <boost/iterator/is_readable_iterator.hpp>
|
||||
# include <boost/iterator/is_lvalue_iterator.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
# include <boost/mpl/and.hpp>
|
||||
|
||||
# include <boost/iterator/detail/config_def.hpp>
|
||||
# include <boost/detail/is_incrementable.hpp>
|
||||
# include <boost/detail/lightweight_test.hpp>
|
||||
# include <boost/core/lightweight_test.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -76,7 +77,7 @@ template <class Iterator, class T>
|
||||
void readable_iterator_test(const Iterator i1, T v)
|
||||
{
|
||||
Iterator i2(i1); // Copy Constructible
|
||||
typedef typename detail::iterator_traits<Iterator>::reference ref_t;
|
||||
typedef typename std::iterator_traits<Iterator>::reference ref_t;
|
||||
ref_t r1 = *i1;
|
||||
ref_t r2 = *i2;
|
||||
T v1 = r1;
|
||||
@ -112,9 +113,9 @@ template <class Iterator>
|
||||
void swappable_iterator_test(Iterator i, Iterator j)
|
||||
{
|
||||
Iterator i2(i), j2(j);
|
||||
typename detail::iterator_traits<Iterator>::value_type bi = *i, bj = *j;
|
||||
typename std::iterator_traits<Iterator>::value_type bi = *i, bj = *j;
|
||||
iter_swap(i2, j2);
|
||||
typename detail::iterator_traits<Iterator>::value_type ai = *i, aj = *j;
|
||||
typename std::iterator_traits<Iterator>::value_type ai = *i, aj = *j;
|
||||
BOOST_TEST(bi == aj && bj == ai);
|
||||
}
|
||||
|
||||
@ -122,8 +123,8 @@ template <class Iterator, class T>
|
||||
void constant_lvalue_iterator_test(Iterator i, T v1)
|
||||
{
|
||||
Iterator i2(i);
|
||||
typedef typename detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename detail::iterator_traits<Iterator>::reference reference;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||
BOOST_STATIC_ASSERT((is_same<const value_type&, reference>::value));
|
||||
const T& v2 = *i2;
|
||||
BOOST_TEST(v1 == v2);
|
||||
@ -137,8 +138,8 @@ template <class Iterator, class T>
|
||||
void non_const_lvalue_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
Iterator i2(i);
|
||||
typedef typename detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename detail::iterator_traits<Iterator>::reference reference;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||
BOOST_STATIC_ASSERT((is_same<value_type&, reference>::value));
|
||||
T& v3 = *i2;
|
||||
BOOST_TEST(v1 == v3);
|
||||
@ -229,7 +230,7 @@ void random_access_readable_iterator_test(Iterator i, int N, TrueVals vals)
|
||||
{
|
||||
BOOST_TEST(i == j + c);
|
||||
BOOST_TEST(*i == vals[c]);
|
||||
typename detail::iterator_traits<Iterator>::value_type x = j[c];
|
||||
typename std::iterator_traits<Iterator>::value_type x = j[c];
|
||||
BOOST_TEST(*i == x);
|
||||
BOOST_TEST(*i == *(j + c));
|
||||
BOOST_TEST(*i == *(c + j));
|
||||
@ -245,7 +246,7 @@ void random_access_readable_iterator_test(Iterator i, int N, TrueVals vals)
|
||||
{
|
||||
BOOST_TEST(i == k - c);
|
||||
BOOST_TEST(*i == vals[N - 1 - c]);
|
||||
typename detail::iterator_traits<Iterator>::value_type x = j[N - 1 - c];
|
||||
typename std::iterator_traits<Iterator>::value_type x = j[N - 1 - c];
|
||||
BOOST_TEST(*i == x);
|
||||
Iterator q = k - c;
|
||||
BOOST_TEST(*i == *q);
|
||||
|
@ -21,13 +21,13 @@ template< class ElementIterator
|
||||
class permutation_iterator
|
||||
: public iterator_adaptor<
|
||||
permutation_iterator<ElementIterator, IndexIterator>
|
||||
, IndexIterator, typename boost::detail::iterator_traits<ElementIterator>::value_type
|
||||
, use_default, typename boost::detail::iterator_traits<ElementIterator>::reference>
|
||||
, IndexIterator, typename std::iterator_traits<ElementIterator>::value_type
|
||||
, use_default, typename std::iterator_traits<ElementIterator>::reference>
|
||||
{
|
||||
typedef iterator_adaptor<
|
||||
permutation_iterator<ElementIterator, IndexIterator>
|
||||
, IndexIterator, typename boost::detail::iterator_traits<ElementIterator>::value_type
|
||||
, use_default, typename boost::detail::iterator_traits<ElementIterator>::reference> super_t;
|
||||
, IndexIterator, typename std::iterator_traits<ElementIterator>::value_type
|
||||
, use_default, typename std::iterator_traits<ElementIterator>::reference> super_t;
|
||||
|
||||
friend class iterator_core_access;
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
#ifndef BOOST_REVERSE_ITERATOR_23022003THW_HPP
|
||||
#define BOOST_REVERSE_ITERATOR_23022003THW_HPP
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
|
||||
namespace boost {
|
||||
@ -40,14 +38,19 @@ namespace iterators {
|
||||
{}
|
||||
|
||||
private:
|
||||
typename super_t::reference dereference() const { return *boost::prior(this->base()); }
|
||||
typename super_t::reference dereference() const
|
||||
{
|
||||
Iterator it = this->base_reference();
|
||||
--it;
|
||||
return *it;
|
||||
}
|
||||
|
||||
void increment() { --this->base_reference(); }
|
||||
void decrement() { ++this->base_reference(); }
|
||||
|
||||
void advance(typename super_t::difference_type n)
|
||||
{
|
||||
this->base_reference() += -n;
|
||||
this->base_reference() -= n;
|
||||
}
|
||||
|
||||
template <class OtherIterator>
|
||||
|
@ -7,7 +7,6 @@
|
||||
#ifndef BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
|
||||
#define BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/detail/enable_if.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
@ -22,11 +21,12 @@
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
|
||||
# include <boost/type_traits/is_base_and_derived.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
|
||||
@ -47,7 +47,11 @@ namespace iterators {
|
||||
// the function.
|
||||
typedef typename ia_dflt_help<
|
||||
Reference
|
||||
#ifdef BOOST_RESULT_OF_USE_TR1
|
||||
, result_of<const UnaryFunc(typename std::iterator_traits<Iterator>::reference)>
|
||||
#else
|
||||
, result_of<const UnaryFunc&(typename std::iterator_traits<Iterator>::reference)>
|
||||
#endif
|
||||
>::type reference;
|
||||
|
||||
// To get the default for Value: remove any reference on the
|
||||
|
@ -9,7 +9,6 @@
|
||||
# define BOOST_ZIP_ITERATOR_TMB_07_13_2003_HPP_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp> // for enable_if_convertible
|
||||
@ -84,7 +83,7 @@ namespace iterators {
|
||||
struct result<This(Iterator)>
|
||||
{
|
||||
typedef typename
|
||||
remove_reference<typename remove_cv<Iterator>::type>::type
|
||||
remove_cv<typename remove_reference<Iterator>::type>::type
|
||||
iterator;
|
||||
|
||||
typedef typename iterator_reference<iterator>::type type;
|
||||
|
195
include/boost/next_prior.hpp
Normal file
195
include/boost/next_prior.hpp
Normal file
@ -0,0 +1,195 @@
|
||||
// Boost next_prior.hpp header file ---------------------------------------//
|
||||
|
||||
// (C) Copyright Dave Abrahams and Daniel Walker 1999-2003.
|
||||
// Copyright (c) Andrey Semashev 2017
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/utility for documentation.
|
||||
|
||||
// Revision History
|
||||
// 13 Dec 2003 Added next(x, n) and prior(x, n) (Daniel Walker)
|
||||
|
||||
#ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED
|
||||
#define BOOST_NEXT_PRIOR_HPP_INCLUDED
|
||||
|
||||
#include <iterator>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/has_plus.hpp>
|
||||
#include <boost/type_traits/has_plus_assign.hpp>
|
||||
#include <boost/type_traits/has_minus.hpp>
|
||||
#include <boost/type_traits/has_minus_assign.hpp>
|
||||
#include <boost/iterator/advance.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// Helper functions for classes like bidirectional iterators not supporting
|
||||
// operator+ and operator-
|
||||
//
|
||||
// Usage:
|
||||
// const std::list<T>::iterator p = get_some_iterator();
|
||||
// const std::list<T>::iterator prev = boost::prior(p);
|
||||
// const std::list<T>::iterator next = boost::next(prev, 2);
|
||||
|
||||
// Contributed by Dave Abrahams
|
||||
|
||||
namespace next_prior_detail {
|
||||
|
||||
// The trait attempts to detect if the T type is an iterator. Class-type iterators are assumed
|
||||
// to have the nested type iterator_category. Strictly speaking, this is not required to be the
|
||||
// case (e.g. a user can specialize iterator_traits for T without defining T::iterator_category).
|
||||
// Still, this is a good heuristic in practice, and we can't do anything better anyway.
|
||||
// Since C++17 we can test for iterator_traits<T>::iterator_category presence instead as it is
|
||||
// required to be only present for iterators.
|
||||
template< typename T, typename Void = void >
|
||||
struct is_iterator_class
|
||||
{
|
||||
static BOOST_CONSTEXPR_OR_CONST bool value = false;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct is_iterator_class<
|
||||
T,
|
||||
typename enable_if_has_type<
|
||||
#if !defined(BOOST_NO_CXX17_ITERATOR_TRAITS)
|
||||
typename std::iterator_traits< T >::iterator_category
|
||||
#else
|
||||
typename T::iterator_category
|
||||
#endif
|
||||
>::type
|
||||
>
|
||||
{
|
||||
static BOOST_CONSTEXPR_OR_CONST bool value = true;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct is_iterator :
|
||||
public is_iterator_class< T >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct is_iterator< T* >
|
||||
{
|
||||
static BOOST_CONSTEXPR_OR_CONST bool value = true;
|
||||
};
|
||||
|
||||
|
||||
template< typename T, typename Distance, bool HasPlus = has_plus< T, Distance >::value >
|
||||
struct next_plus_impl;
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct next_plus_impl< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
return x + n;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, typename Distance, bool HasPlusAssign = has_plus_assign< T, Distance >::value >
|
||||
struct next_plus_assign_impl :
|
||||
public next_plus_impl< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct next_plus_assign_impl< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
x += n;
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, typename Distance, bool IsIterator = is_iterator< T >::value >
|
||||
struct next_advance_impl :
|
||||
public next_plus_assign_impl< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct next_advance_impl< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
boost::iterators::advance(x, n);
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< typename T, typename Distance, bool HasMinus = has_minus< T, Distance >::value >
|
||||
struct prior_minus_impl;
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct prior_minus_impl< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
return x - n;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, typename Distance, bool HasMinusAssign = has_minus_assign< T, Distance >::value >
|
||||
struct prior_minus_assign_impl :
|
||||
public prior_minus_impl< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct prior_minus_assign_impl< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
x -= n;
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, typename Distance, bool IsIterator = is_iterator< T >::value >
|
||||
struct prior_advance_impl :
|
||||
public prior_minus_assign_impl< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct prior_advance_impl< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
// Avoid negating n to sidestep possible integer overflow
|
||||
boost::iterators::reverse_iterator< T > rx(x);
|
||||
boost::iterators::advance(rx, n);
|
||||
return rx.base();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace next_prior_detail
|
||||
|
||||
template <class T>
|
||||
inline T next(T x) { return ++x; }
|
||||
|
||||
template <class T, class Distance>
|
||||
inline T next(T x, Distance n)
|
||||
{
|
||||
return next_prior_detail::next_advance_impl< T, Distance >::call(x, n);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T prior(T x) { return --x; }
|
||||
|
||||
template <class T, class Distance>
|
||||
inline T prior(T x, Distance n)
|
||||
{
|
||||
return next_prior_detail::prior_advance_impl< T, Distance >::call(x, n);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NEXT_PRIOR_HPP_INCLUDED
|
@ -6,11 +6,12 @@
|
||||
#ifndef BOOST_INT_ITERATOR_H
|
||||
#define BOOST_INT_ITERATOR_H
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#if !defined BOOST_MSVC
|
||||
#include <boost/operators.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <cstddef>
|
||||
//using namespace std;
|
||||
|
||||
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
|
@ -20,11 +20,14 @@
|
||||
// (David Abrahams)
|
||||
|
||||
# include <iterator>
|
||||
# include <assert.h>
|
||||
# include <boost/type_traits.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
|
||||
# include <boost/implicit_cast.hpp>
|
||||
# include <boost/core/ignore_unused.hpp>
|
||||
# include <boost/core/lightweight_test.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/type_traits/is_pointer.hpp>
|
||||
# include <boost/type_traits/is_reference.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -50,27 +53,29 @@ template <class Iterator, class T>
|
||||
void trivial_iterator_test(const Iterator i, const Iterator j, T val)
|
||||
{
|
||||
Iterator k;
|
||||
assert(i == i);
|
||||
assert(j == j);
|
||||
assert(i != j);
|
||||
BOOST_TEST(i == i);
|
||||
BOOST_TEST(j == j);
|
||||
BOOST_TEST(i != j);
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
T v = *i;
|
||||
#else
|
||||
typename std::iterator_traits<Iterator>::value_type v = *i;
|
||||
#endif
|
||||
assert(v == val);
|
||||
BOOST_TEST(v == val);
|
||||
boost::ignore_unused(v);
|
||||
#if 0
|
||||
// hmm, this will give a warning for transform_iterator... perhaps
|
||||
// this should be separated out into a stand-alone test since there
|
||||
// are several situations where it can't be used, like for
|
||||
// integer_range::iterator.
|
||||
assert(v == i->foo());
|
||||
BOOST_TEST(v == i->foo());
|
||||
#endif
|
||||
k = i;
|
||||
assert(k == k);
|
||||
assert(k == i);
|
||||
assert(k != j);
|
||||
assert(*k == val);
|
||||
BOOST_TEST(k == k);
|
||||
BOOST_TEST(k == i);
|
||||
BOOST_TEST(k != j);
|
||||
BOOST_TEST(*k == val);
|
||||
boost::ignore_unused(k);
|
||||
}
|
||||
|
||||
|
||||
@ -89,8 +94,8 @@ void input_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
Iterator i1(i);
|
||||
|
||||
assert(i == i1);
|
||||
assert(!(i != i1));
|
||||
BOOST_TEST(i == i1);
|
||||
BOOST_TEST(!(i != i1));
|
||||
|
||||
// I can see no generic way to create an input iterator
|
||||
// that is in the domain of== of i and != i.
|
||||
@ -99,23 +104,25 @@ void input_iterator_test(Iterator i, T v1, T v2)
|
||||
//
|
||||
// Iterator i2;
|
||||
//
|
||||
// assert(i != i2);
|
||||
// assert(!(i == i2));
|
||||
// BOOST_TEST(i != i2);
|
||||
// BOOST_TEST(!(i == i2));
|
||||
|
||||
assert(*i1 == v1);
|
||||
assert(*i == v1);
|
||||
BOOST_TEST(*i1 == v1);
|
||||
BOOST_TEST(*i == v1);
|
||||
|
||||
// we cannot test for equivalence of (void)++i & (void)i++
|
||||
// as i is only guaranteed to be single pass.
|
||||
assert(*i++ == v1);
|
||||
BOOST_TEST(*i++ == v1);
|
||||
boost::ignore_unused(i1);
|
||||
|
||||
i1 = i;
|
||||
|
||||
assert(i == i1);
|
||||
assert(!(i != i1));
|
||||
BOOST_TEST(i == i1);
|
||||
BOOST_TEST(!(i != i1));
|
||||
|
||||
assert(*i1 == v2);
|
||||
assert(*i == v2);
|
||||
BOOST_TEST(*i1 == v2);
|
||||
BOOST_TEST(*i == v2);
|
||||
boost::ignore_unused(i1);
|
||||
|
||||
// i is dereferencable, so it must be incrementable.
|
||||
++i;
|
||||
@ -157,15 +164,15 @@ void forward_iterator_test(Iterator i, T v1, T v2)
|
||||
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1++);
|
||||
assert(i != ++i2);
|
||||
BOOST_TEST(i == i1++);
|
||||
BOOST_TEST(i != ++i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
|
||||
++i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
BOOST_TEST(i == i1);
|
||||
BOOST_TEST(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
|
||||
@ -187,15 +194,15 @@ void bidirectional_iterator_test(Iterator i, T v1, T v2)
|
||||
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1--);
|
||||
assert(i != --i2);
|
||||
BOOST_TEST(i == i1--);
|
||||
BOOST_TEST(i != --i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, v2);
|
||||
|
||||
--i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
BOOST_TEST(i == i1);
|
||||
BOOST_TEST(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
|
||||
@ -215,32 +222,34 @@ void random_access_iterator_test(Iterator i, int N, TrueVals vals)
|
||||
const Iterator j = i;
|
||||
int c;
|
||||
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
boost::ignore_unused<value_type>();
|
||||
|
||||
for (c = 0; c < N-1; ++c) {
|
||||
assert(i == j + c);
|
||||
assert(*i == vals[c]);
|
||||
assert(*i == boost::implicit_cast<value_type>(j[c]));
|
||||
assert(*i == *(j + c));
|
||||
assert(*i == *(c + j));
|
||||
BOOST_TEST(i == j + c);
|
||||
BOOST_TEST(*i == vals[c]);
|
||||
BOOST_TEST(*i == boost::implicit_cast<value_type>(j[c]));
|
||||
BOOST_TEST(*i == *(j + c));
|
||||
BOOST_TEST(*i == *(c + j));
|
||||
++i;
|
||||
assert(i > j);
|
||||
assert(i >= j);
|
||||
assert(j <= i);
|
||||
assert(j < i);
|
||||
BOOST_TEST(i > j);
|
||||
BOOST_TEST(i >= j);
|
||||
BOOST_TEST(j <= i);
|
||||
BOOST_TEST(j < i);
|
||||
}
|
||||
|
||||
Iterator k = j + N - 1;
|
||||
for (c = 0; c < N-1; ++c) {
|
||||
assert(i == k - c);
|
||||
assert(*i == vals[N - 1 - c]);
|
||||
assert(*i == boost::implicit_cast<value_type>(j[N - 1 - c]));
|
||||
BOOST_TEST(i == k - c);
|
||||
BOOST_TEST(*i == vals[N - 1 - c]);
|
||||
BOOST_TEST(*i == boost::implicit_cast<value_type>(j[N - 1 - c]));
|
||||
Iterator q = k - c;
|
||||
assert(*i == *q);
|
||||
assert(i > j);
|
||||
assert(i >= j);
|
||||
assert(j <= i);
|
||||
assert(j < i);
|
||||
boost::ignore_unused(q);
|
||||
BOOST_TEST(*i == *q);
|
||||
BOOST_TEST(i > j);
|
||||
BOOST_TEST(i >= j);
|
||||
BOOST_TEST(j <= i);
|
||||
BOOST_TEST(j < i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
@ -249,16 +258,17 @@ void random_access_iterator_test(Iterator i, int N, TrueVals vals)
|
||||
template <class Iterator, class ConstIterator>
|
||||
void const_nonconst_iterator_test(Iterator i, ConstIterator j)
|
||||
{
|
||||
assert(i != j);
|
||||
assert(j != i);
|
||||
BOOST_TEST(i != j);
|
||||
BOOST_TEST(j != i);
|
||||
|
||||
ConstIterator k(i);
|
||||
assert(k == i);
|
||||
assert(i == k);
|
||||
BOOST_TEST(k == i);
|
||||
BOOST_TEST(i == k);
|
||||
|
||||
k = i;
|
||||
assert(k == i);
|
||||
assert(i == k);
|
||||
BOOST_TEST(k == i);
|
||||
BOOST_TEST(i == k);
|
||||
boost::ignore_unused(k);
|
||||
}
|
||||
|
||||
} // namespace iterators
|
||||
|
@ -20,6 +20,8 @@
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/eval_if.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail
|
||||
@ -33,7 +35,7 @@ namespace detail
|
||||
template <class Iterator>
|
||||
struct iterator_pointee
|
||||
{
|
||||
typedef typename iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||
|
||||
struct impl
|
||||
{
|
||||
|
@ -55,4 +55,10 @@ test-suite iterator
|
||||
|
||||
[ run minimum_category.cpp ]
|
||||
[ compile-fail minimum_category_compile_fail.cpp ]
|
||||
|
||||
[ run next_prior_test.cpp ]
|
||||
[ run advance_test.cpp ]
|
||||
[ run distance_test.cpp ]
|
||||
|
||||
[ run shared_iterator_test.cpp ]
|
||||
;
|
||||
|
91
test/advance_test.cpp
Normal file
91
test/advance_test.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
// Copyright (C) 2017 Michel Morin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <boost/container/slist.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/iterator/advance.hpp>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
int twice(int x) { return x + x; }
|
||||
|
||||
template <typename Iterator>
|
||||
void test_advance(Iterator it_from, Iterator it_to, int n)
|
||||
{
|
||||
boost::advance(it_from, n);
|
||||
BOOST_TEST(it_from == it_to);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int array[3] = {1, 2, 3};
|
||||
int* ptr1 = array;
|
||||
int* ptr2 = array + 3;
|
||||
|
||||
{
|
||||
test_advance(ptr1, ptr2, 3);
|
||||
test_advance(ptr2, ptr1, -3);
|
||||
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ptr1, twice)
|
||||
, boost::make_transform_iterator(ptr2, twice)
|
||||
, 3
|
||||
);
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ptr2, twice)
|
||||
, boost::make_transform_iterator(ptr1, twice)
|
||||
, -3
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<int> ints(ptr1, ptr2);
|
||||
test_advance(ints.begin(), ints.end(), 3);
|
||||
test_advance(ints.end(), ints.begin(), -3);
|
||||
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ints.begin(), twice)
|
||||
, boost::make_transform_iterator(ints.end(), twice)
|
||||
, 3
|
||||
);
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ints.end(), twice)
|
||||
, boost::make_transform_iterator(ints.begin(), twice)
|
||||
, -3
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
std::list<int> ints(ptr1, ptr2);
|
||||
test_advance(ints.begin(), ints.end(), 3);
|
||||
test_advance(ints.end(), ints.begin(), -3);
|
||||
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ints.begin(), twice)
|
||||
, boost::make_transform_iterator(ints.end(), twice)
|
||||
, 3
|
||||
);
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ints.end(), twice)
|
||||
, boost::make_transform_iterator(ints.begin(), twice)
|
||||
, -3
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
boost::container::slist<int> ints(ptr1, ptr2);
|
||||
test_advance(ints.begin(), ints.end(), 3);
|
||||
|
||||
test_advance(
|
||||
boost::make_transform_iterator(ints.begin(), twice)
|
||||
, boost::make_transform_iterator(ints.end(), twice)
|
||||
, 3
|
||||
);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -7,13 +7,16 @@
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <cstddef>
|
||||
|
||||
struct new_random_access
|
||||
: std::random_access_iterator_tag
|
||||
, boost::random_access_traversal_tag
|
||||
{};
|
||||
|
||||
struct new_iterator
|
||||
: public boost::iterator< new_random_access, int >
|
||||
: public std::iterator< new_random_access, int >
|
||||
{
|
||||
int& operator*() const { return *m_x; }
|
||||
new_iterator& operator++() { return *this; }
|
||||
@ -33,7 +36,7 @@ struct new_iterator
|
||||
new_iterator operator+(std::ptrdiff_t, new_iterator x) { return x; }
|
||||
|
||||
struct old_iterator
|
||||
: public boost::iterator<std::random_access_iterator_tag, int>
|
||||
: public std::iterator<std::random_access_iterator_tag, int>
|
||||
{
|
||||
int& operator*() const { return *m_x; }
|
||||
old_iterator& operator++() { return *this; }
|
||||
|
@ -153,7 +153,6 @@ template <class CountingIterator, class Value>
|
||||
void test_aux(CountingIterator start, CountingIterator finish, Value v1)
|
||||
{
|
||||
typedef typename CountingIterator::iterator_category category;
|
||||
typedef typename CountingIterator::value_type value_type;
|
||||
|
||||
// If it's a RandomAccessIterator we can do a few delicate tests
|
||||
category_test(start, finish, v1, category());
|
||||
|
@ -58,6 +58,18 @@ int main()
|
||||
BOOST_TEST(boost::fusion::at_c<1>(*(i + 1)) == "pyonpyon");
|
||||
}
|
||||
|
||||
{
|
||||
// Trac #12895
|
||||
boost::zip_iterator<
|
||||
TUPLE<int*, std::string*>
|
||||
> i(MAKE_TUPLE(&vi[0], &vs[0]));
|
||||
|
||||
BOOST_TEST(boost::fusion::at_c<0>(* i ) == 42);
|
||||
BOOST_TEST(boost::fusion::at_c<1>(* i ) == "kokoro");
|
||||
BOOST_TEST(boost::fusion::at_c<0>(*(i + 1)) == 72);
|
||||
BOOST_TEST(boost::fusion::at_c<1>(*(i + 1)) == "pyonpyon");
|
||||
}
|
||||
|
||||
{
|
||||
boost::zip_iterator<iterator_tuple> i1(MAKE_TUPLE(vi.begin(), vs.begin()));
|
||||
boost::zip_iterator<iterator_tuple> i2(MAKE_TUPLE(vi.end(), vs.end()));
|
||||
|
84
test/distance_test.cpp
Normal file
84
test/distance_test.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
// Copyright (C) 2017 Michel Morin.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <boost/container/slist.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/iterator/distance.hpp>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
int twice(int x) { return x + x; }
|
||||
|
||||
template <typename Iterator>
|
||||
void test_distance(Iterator it_from, Iterator it_to, int n)
|
||||
{
|
||||
BOOST_TEST(boost::distance(it_from, it_to) == n);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int array[3] = {1, 2, 3};
|
||||
int* ptr1 = array;
|
||||
int* ptr2 = array + 3;
|
||||
|
||||
{
|
||||
test_distance(ptr1, ptr2, 3);
|
||||
test_distance(ptr2, ptr1, -3);
|
||||
|
||||
test_distance(
|
||||
boost::make_transform_iterator(ptr1, twice)
|
||||
, boost::make_transform_iterator(ptr2, twice)
|
||||
, 3
|
||||
);
|
||||
test_distance(
|
||||
boost::make_transform_iterator(ptr2, twice)
|
||||
, boost::make_transform_iterator(ptr1, twice)
|
||||
, -3
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<int> ints(ptr1, ptr2);
|
||||
test_distance(ints.begin(), ints.end(), 3);
|
||||
test_distance(ints.end(), ints.begin(), -3);
|
||||
|
||||
test_distance(
|
||||
boost::make_transform_iterator(ints.begin(), twice)
|
||||
, boost::make_transform_iterator(ints.end(), twice)
|
||||
, 3
|
||||
);
|
||||
test_distance(
|
||||
boost::make_transform_iterator(ints.end(), twice)
|
||||
, boost::make_transform_iterator(ints.begin(), twice)
|
||||
, -3
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
std::list<int> ints(ptr1, ptr2);
|
||||
test_distance(ints.begin(), ints.end(), 3);
|
||||
|
||||
test_distance(
|
||||
boost::make_transform_iterator(ints.begin(), twice)
|
||||
, boost::make_transform_iterator(ints.end(), twice)
|
||||
, 3
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
boost::container::slist<int> ints(ptr1, ptr2);
|
||||
test_distance(ints.begin(), ints.end(), 3);
|
||||
|
||||
test_distance(
|
||||
boost::make_transform_iterator(ints.begin(), twice)
|
||||
, boost::make_transform_iterator(ints.end(), twice)
|
||||
, 3
|
||||
);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -3,15 +3,24 @@
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE)
|
||||
// Force boost::result_of use decltype, even on compilers that don't support N3276.
|
||||
// This enables this test to also verify if the iterator works with lambdas
|
||||
// on such compilers with this config macro. Note that without the macro result_of
|
||||
// (and consequently the iterator) is guaranteed to _not_ work, so this case is not
|
||||
// worth testing anyway.
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/iterator/function_input_iterator.hpp>
|
||||
|
||||
namespace {
|
||||
@ -40,7 +49,7 @@ struct counter {
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
int main()
|
||||
{
|
||||
// test the iterator with function objects
|
||||
ones ones_generator;
|
||||
@ -54,9 +63,7 @@ int main(int argc, char * argv[])
|
||||
back_inserter(generated)
|
||||
);
|
||||
|
||||
assert(values.size() == generated.size());
|
||||
assert(equal(values.begin(), values.end(), generated.begin()));
|
||||
cout << "function iterator test with function objects successful." << endl;
|
||||
BOOST_TEST_ALL_EQ(values.begin(), values.end(), generated.begin(), generated.end());
|
||||
|
||||
// test the iterator with normal functions
|
||||
vector<int>().swap(generated);
|
||||
@ -66,9 +73,7 @@ int main(int argc, char * argv[])
|
||||
back_inserter(generated)
|
||||
);
|
||||
|
||||
assert(values.size() == generated.size());
|
||||
assert(equal(values.begin(), values.end(), generated.begin()));
|
||||
cout << "function iterator test with pointer to function successful." << endl;
|
||||
BOOST_TEST_ALL_EQ(values.begin(), values.end(), generated.begin(), generated.end());
|
||||
|
||||
// test the iterator with a reference to a function
|
||||
vector<int>().swap(generated);
|
||||
@ -78,9 +83,7 @@ int main(int argc, char * argv[])
|
||||
back_inserter(generated)
|
||||
);
|
||||
|
||||
assert(values.size() == generated.size());
|
||||
assert(equal(values.begin(), values.end(), generated.begin()));
|
||||
cout << "function iterator test with reference to function successful." << endl;
|
||||
BOOST_TEST_ALL_EQ(values.begin(), values.end(), generated.begin(), generated.end());
|
||||
|
||||
// test the iterator with a stateful function object
|
||||
counter counter_generator(42);
|
||||
@ -91,13 +94,13 @@ int main(int argc, char * argv[])
|
||||
back_inserter(generated)
|
||||
);
|
||||
|
||||
assert(generated.size() == 10);
|
||||
assert(counter_generator.n == 42 + 10);
|
||||
BOOST_TEST_EQ(generated.size(), 10u);
|
||||
BOOST_TEST_EQ(counter_generator.n, 42 + 10);
|
||||
for(std::size_t i = 0; i != 10; ++i)
|
||||
assert(generated[i] == 42 + i);
|
||||
cout << "function iterator test with stateful function object successful." << endl;
|
||||
BOOST_TEST_EQ(generated[i], static_cast<int>(42 + i));
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
|
||||
#if !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) \
|
||||
&& defined(BOOST_RESULT_OF_USE_DECLTYPE)
|
||||
// test the iterator with lambda expressions
|
||||
int num = 42;
|
||||
auto lambda_generator = [&num] { return num++; };
|
||||
@ -108,12 +111,10 @@ int main(int argc, char * argv[])
|
||||
back_inserter(generated)
|
||||
);
|
||||
|
||||
assert(generated.size() == 10);
|
||||
BOOST_TEST_EQ(generated.size(), 10u);
|
||||
for(std::size_t i = 0; i != 10; ++i)
|
||||
assert(generated[i] == 42 + i);
|
||||
cout << "function iterator test with lambda expressions successful." << endl;
|
||||
BOOST_TEST_EQ(generated[i], static_cast<int>(42 + i));
|
||||
#endif // BOOST_NO_CXX11_LAMBDAS
|
||||
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
|
||||
@ -32,6 +33,7 @@
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <set>
|
||||
#include <iterator>
|
||||
|
||||
#if !defined(__SGI_STL_PORT) \
|
||||
&& (defined(BOOST_MSVC_STD_ITERATOR) \
|
||||
@ -164,7 +166,7 @@ main()
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
has_element_type<
|
||||
boost::detail::iterator_traits<shared_t::iterator>::value_type
|
||||
std::iterator_traits<shared_t::iterator>::value_type
|
||||
>::value
|
||||
);
|
||||
|
||||
|
@ -86,7 +86,7 @@ struct input_iter
|
||||
return value();
|
||||
}
|
||||
|
||||
bool equal(input_iter const& y) const
|
||||
bool equal(input_iter const&) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
112
test/next_prior_test.cpp
Normal file
112
test/next_prior_test.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
// Boost test program for next() and prior() utilities.
|
||||
|
||||
// Copyright 2003 Daniel Walker. Use, modification, and distribution
|
||||
// are subject to the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or a copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt.)
|
||||
|
||||
// See http://www.boost.org/libs/utility for documentation.
|
||||
|
||||
// Revision History 13 Dec 2003 Initial Version (Daniel Walker)
|
||||
|
||||
// next() and prior() are replacements for operator+ and operator- for
|
||||
// non-random-access iterators. The semantics of these operators are
|
||||
// such that after executing j = i + n, std::distance(i, j) equals
|
||||
// n. Tests are provided to ensure next() has the same
|
||||
// result. Parallel tests are provided for prior(). The tests call
|
||||
// next() and prior() several times. next() and prior() are very
|
||||
// simple functions, though, and it would be very strange if these
|
||||
// tests were to fail.
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
template<class RandomAccessIterator, class ForwardIterator>
|
||||
bool plus_one_test(RandomAccessIterator first, RandomAccessIterator last, ForwardIterator first2)
|
||||
{
|
||||
RandomAccessIterator i = first;
|
||||
ForwardIterator j = first2;
|
||||
while(i != last)
|
||||
i = i + 1, j = boost::next(j);
|
||||
return std::distance(first, i) == std::distance(first2, j);
|
||||
}
|
||||
|
||||
template<class RandomAccessIterator, class ForwardIterator>
|
||||
bool plus_n_test(RandomAccessIterator first, RandomAccessIterator last, ForwardIterator first2)
|
||||
{
|
||||
RandomAccessIterator i = first;
|
||||
ForwardIterator j = first2;
|
||||
for(int n = 0; i != last; ++n)
|
||||
i = first + n, j = boost::next(first2, n);
|
||||
return std::distance(first, i) == std::distance(first2, j);
|
||||
}
|
||||
|
||||
template<class RandomAccessIterator, class BidirectionalIterator>
|
||||
bool minus_one_test(RandomAccessIterator first, RandomAccessIterator last, BidirectionalIterator last2)
|
||||
{
|
||||
RandomAccessIterator i = last;
|
||||
BidirectionalIterator j = last2;
|
||||
while(i != first)
|
||||
i = i - 1, j = boost::prior(j);
|
||||
return std::distance(i, last) == std::distance(j, last2);
|
||||
}
|
||||
|
||||
template<class RandomAccessIterator, class BidirectionalIterator>
|
||||
bool minus_n_test(RandomAccessIterator first, RandomAccessIterator last, BidirectionalIterator last2)
|
||||
{
|
||||
RandomAccessIterator i = last;
|
||||
BidirectionalIterator j = last2;
|
||||
for(int n = 0; i != first; ++n)
|
||||
i = last - n, j = boost::prior(last2, n);
|
||||
return std::distance(i, last) == std::distance(j, last2);
|
||||
}
|
||||
|
||||
template<class Iterator, class Distance>
|
||||
bool minus_n_unsigned_test(Iterator first, Iterator last, Distance size)
|
||||
{
|
||||
Iterator i = boost::prior(last, size);
|
||||
return i == first;
|
||||
}
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
std::vector<int> x(8);
|
||||
std::list<int> y(x.begin(), x.end());
|
||||
|
||||
// Tests with iterators
|
||||
BOOST_TEST(plus_one_test(x.begin(), x.end(), y.begin()));
|
||||
BOOST_TEST(plus_n_test(x.begin(), x.end(), y.begin()));
|
||||
BOOST_TEST(minus_one_test(x.begin(), x.end(), y.end()));
|
||||
BOOST_TEST(minus_n_test(x.begin(), x.end(), y.end()));
|
||||
BOOST_TEST(minus_n_unsigned_test(x.begin(), x.end(), x.size()));
|
||||
BOOST_TEST(minus_n_unsigned_test(y.begin(), y.end(), y.size()));
|
||||
|
||||
BOOST_TEST(plus_one_test(x.rbegin(), x.rend(), y.begin()));
|
||||
BOOST_TEST(plus_n_test(x.rbegin(), x.rend(), y.begin()));
|
||||
BOOST_TEST(minus_one_test(x.rbegin(), x.rend(), y.end()));
|
||||
BOOST_TEST(minus_n_test(x.rbegin(), x.rend(), y.end()));
|
||||
BOOST_TEST(minus_n_unsigned_test(x.rbegin(), x.rend(), x.size()));
|
||||
BOOST_TEST(minus_n_unsigned_test(x.rbegin(), x.rend(), y.size()));
|
||||
|
||||
// Test with pointers
|
||||
std::vector<int> z(x.size());
|
||||
int* p = &z[0];
|
||||
BOOST_TEST(plus_one_test(x.begin(), x.end(), p));
|
||||
BOOST_TEST(plus_n_test(x.begin(), x.end(), p));
|
||||
BOOST_TEST(minus_one_test(x.begin(), x.end(), p + z.size()));
|
||||
BOOST_TEST(minus_n_test(x.begin(), x.end(), p + z.size()));
|
||||
BOOST_TEST(minus_n_unsigned_test(p, p + z.size(), z.size()));
|
||||
|
||||
// Tests with integers
|
||||
BOOST_TEST(boost::next(5) == 6);
|
||||
BOOST_TEST(boost::next(5, 7) == 12);
|
||||
BOOST_TEST(boost::prior(5) == 4);
|
||||
BOOST_TEST(boost::prior(5, 7) == -2);
|
||||
BOOST_TEST(boost::prior(5, 7u) == -2);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
64
test/shared_iterator_test.cpp
Normal file
64
test/shared_iterator_test.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Shared container iterator adaptor
|
||||
// Author: Ronald Garcia
|
||||
// See http://boost.org/libs/utility/shared_container_iterator.html
|
||||
// for documentation.
|
||||
|
||||
//
|
||||
// shared_iterator_test.cpp - Regression tests for shared_container_iterator.
|
||||
//
|
||||
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <vector>
|
||||
|
||||
struct resource {
|
||||
static int count;
|
||||
resource() { ++count; }
|
||||
resource(resource const&) { ++count; }
|
||||
~resource() { --count; }
|
||||
};
|
||||
int resource::count = 0;
|
||||
|
||||
typedef std::vector<resource> resources_t;
|
||||
|
||||
typedef boost::shared_container_iterator< resources_t > iterator;
|
||||
|
||||
|
||||
void set_range(iterator& i, iterator& end) {
|
||||
|
||||
boost::shared_ptr< resources_t > objs(new resources_t());
|
||||
|
||||
for (int j = 0; j != 6; ++j)
|
||||
objs->push_back(resource());
|
||||
|
||||
i = iterator(objs->begin(),objs);
|
||||
end = iterator(objs->end(),objs);
|
||||
BOOST_TEST_EQ(resource::count, 6);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
BOOST_TEST_EQ(resource::count, 0);
|
||||
|
||||
{
|
||||
iterator i;
|
||||
{
|
||||
iterator end;
|
||||
set_range(i,end);
|
||||
BOOST_TEST_EQ(resource::count, 6);
|
||||
}
|
||||
BOOST_TEST_EQ(resource::count, 6);
|
||||
}
|
||||
BOOST_TEST_EQ(resource::count, 0);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
#include <tuple>
|
||||
#include <boost/fusion/adapted/std_tuple.hpp>
|
||||
|
@ -6,6 +6,22 @@
|
||||
//
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test on msvc-9.0 and below")
|
||||
int main() {}
|
||||
|
||||
#elif defined(BOOST_GCC) && __cplusplus < 201100
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Skipping test on g++ in C++03 mode")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <utility>
|
||||
#include <boost/fusion/adapted/std_pair.hpp>
|
||||
|
||||
@ -14,3 +30,4 @@
|
||||
|
||||
#include "detail/zip_iterator_test.ipp"
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user