Compare commits

...

41 Commits

Author SHA1 Message Date
ed027c2cce Merge branch 'develop'
# Conflicts:
#	include/boost/iterator/reverse_iterator.hpp
2017-07-17 12:03:38 -04:00
4791425000 Merge pull request #27 from Lastique/advance_generic_distance
Use a separate template parameter for distance in advance().
2017-07-12 12:20:34 -04:00
b7e7e83a11 Merge pull request #28 from Lastique/patch-2
Avoid integer overflow on negating distance in reverse_iterator
2017-07-12 12:17:22 -04:00
c148962bd9 Avoid integer overflow on negating distance 2017-07-10 14:57:40 +03:00
5bfbfb7716 Use a separate template parameter for distance in advance().
This follows std::advance interface and also allows to use distance types
other than iterator's difference_type (if the iterator supports that).
2017-07-10 14:51:07 +03:00
af5f6e49e0 Merge pull request #26 from Lastique/patch-2
Remove dependency on boost::prior.
2017-07-09 11:59:18 -04:00
26ee5ba754 Remove dependency on boost::prior. 2017-07-09 18:31:06 +03:00
67a2336cf4 Merge pull request #25 from morinmorin/add_readable_iterator_tests
Add more ReabableIterator tests for advance/distance
2017-07-09 11:14:04 -04:00
029277f3ed Add more tests for ReabableIterator 2017-07-08 13:30:28 +09:00
847b2a1be3 Added Travis testing 2017-06-30 20:29:49 -04:00
18268069d9 Merge pull request #24 from morinmorin/add_advance_and_distance
Add boost::advance and boost::distance
2017-06-29 15:02:38 -04:00
bb54ee7900 Update Jamfile.v2 for new tests 2017-06-29 22:49:05 +09:00
d5b67c7fab Add tests for boost::advance/distance 2017-06-29 22:09:26 +09:00
663a30f659 Implement BoostIteratorTraversalConcepts-aware boost::advance/distance 2017-06-29 22:06:12 +09:00
177f719d15 Merge branch 'develop' 2017-04-24 12:24:21 -04:00
cccbd8c6aa Test needs both std::typle support and variadic template support. 2017-04-08 16:53:02 -04:00
d6cfed4b20 Merge pull request #23 from morinmorin/testcase_for_trac_12895
Testcase for PR #22 (trac ticket 12895)
2017-03-15 12:19:13 -04:00
514ac53326 Merge pull request #22 from Dani-Hub/develop
Bug fix for ticket #12895: Apply remove_reference before remove_cv
2017-03-15 12:12:12 -04:00
ca3b7505ce Add a testcase for trac ticket 12895 2017-03-15 20:41:24 +09:00
d7c8cccd64 Bug fix for ticket #12895: Apply remove_reference before remove_cv 2017-03-14 20:45:48 +01:00
7b627fa679 Merge branch 'develop' 2017-01-04 10:58:14 -05:00
760da84f9c Merge branch 'develop' of https://github.com/eldiener/iterator into nekko1119-support-lambda-expression 2016-12-17 19:34:48 -05:00
89d3ec7662 Add inclusion of config.hpp 2016-12-17 19:32:52 -05:00
c86db2ec8a Merge branch 'support-lambda-expression' of https://github.com/nekko1119/iterator into nekko1119-support-lambda-expression 2016-12-16 04:22:44 -05:00
0a18cfb255 Merge pull request #21 from Wilson-N/feature-bug-fix-8010
Remove incorrect documentation stating iterator_facade and iterator_a…
2016-12-01 08:53:05 -05:00
11e3715f37 Updated to use unique_ptr instead of auto_ptr when appropriate. Removed unnecessary structs. 2016-11-07 14:01:19 -05:00
f2d07f76b5 Add, and update, documentation build targets. 2016-10-10 11:39:50 -05:00
53e8ac401f Add, and update, documentation build targets. 2016-10-07 23:07:34 -05:00
434818cce7 Remove incorrect documentation stating iterator_facade and iterator_adapter had
been accepted into the TR1.

Fixes #8010
2016-01-27 22:22:55 -06:00
c09c8ca2b2 Support lambda expressions in function_input_iterator 2015-12-28 02:45:49 +09:00
22dd100dfd Revert "Remove unused deprecated includes"
This reverts commit b2b9ab1568.
2015-10-15 23:55:35 -04:00
2f72016049 Revert "Fix test compilation"
This reverts commit 443dfb9901.
2015-10-15 23:53:37 -04:00
5b26a8b3fc Merge branch 'develop' 2015-10-14 23:59:55 -04:00
711a0232f8 Merge pull request #19 from MarcelRaad/patch-1
Fix test compilation
2015-09-22 18:03:05 -07:00
443dfb9901 Fix test compilation
boost/iterator.hpp was implicitly dragged in via boost/operators.hpp, from which it was removed in cb6500161b. It's not needed anyway, all it does is map boost::iterator to std::iterator.
2015-09-22 00:33:50 +02:00
c734f3bfa3 Merge pull request #18 from MarcelRaad/remove-deprecated-includes
Remove deprecated includes
2015-09-14 12:06:20 -04:00
b2b9ab1568 Remove unused deprecated includes
A comment in boost/iterator.hpp and boost/detail/iterator.hpp mentions that
the files are obsolete and will be deprecated. All they do is pull some types
from namespace std into namespace boost.
2015-09-14 14:28:38 +02:00
8b23342969 Merge pull request #17 from boostorg/revert-16-remove-deprecated-includes
Revert "Remove unused deprecated includes"
2015-09-14 08:17:35 -04:00
ece225bbda Merge branch 'develop' 2015-07-18 22:08:52 -04:00
46f9e1753f Merge pull request #9 from boostorg/develop
Merge develop into master

Tested with gcc-4.2.1 on Darwin.
2014-09-06 11:18:28 -06:00
4283d20261 Merge remote-tracking branch 'origin/develop' 2014-06-26 11:53:43 +01:00
16 changed files with 431 additions and 43 deletions

40
.travis.yml Normal file
View File

@ -0,0 +1,40 @@
# Copyright 2016 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"
os:
- linux
- osx
branches:
only:
- master
- develop
install:
- cd ..
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init --depth 1 tools/build
- git submodule update --init --depth 1 libs/config
- git submodule update --init --depth 1 tools/boostdep
- cp -r $TRAVIS_BUILD_DIR/* libs/iterator
- python tools/boostdep/depinst/depinst.py iterator
- ./bootstrap.sh
- ./b2 headers
script:
- TOOLSET=gcc,clang
- if [ $TRAVIS_OS_NAME == osx ]; then TOOLSET=clang; fi
- ./b2 --verbose-test libs/config/test//config_info toolset=$TOOLSET || true
- ./b2 libs/iterator/test toolset=$TOOLSET
notifications:
email:
on_success: always

View File

@ -20,4 +20,8 @@ boostbook standalone
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/iterator/doc
;
###############################################################################
alias boostdoc ;
explicit boostdoc ;
alias boostrelease : standalone ;
explicit boostrelease ;

View File

@ -115,8 +115,8 @@ __ iterator_facade.pdf
__ iterator_adaptor.pdf
Both |facade| and |adaptor| as well as many of the `specialized
adaptors`_ mentioned below have been proposed for standardization,
and accepted into the first C++ technical report; see our
adaptors`_ mentioned below have been proposed for standardization;
see our
`Standard Proposal For Iterator Facade and Adaptor`__ (PDF__)

View 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

View 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

View File

@ -9,6 +9,7 @@
#ifndef BOOST_FUNCTION_INPUT_ITERATOR
#define BOOST_FUNCTION_INPUT_ITERATOR
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/mpl/if.hpp>
#include <boost/function_types/is_function_pointer.hpp>
@ -17,6 +18,7 @@
#include <boost/iterator/iterator_facade.hpp>
#include <boost/none.hpp>
#include <boost/optional/optional.hpp>
#include <boost/utility/result_of.hpp>
namespace boost {
@ -28,9 +30,9 @@ namespace iterators {
class function_input_iterator
: public iterator_facade<
function_input_iterator<Function, Input>,
typename Function::result_type,
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type,
single_pass_traversal_tag,
typename Function::result_type const &
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
>
{
public:
@ -46,7 +48,7 @@ namespace iterators {
++state;
}
typename Function::result_type const &
BOOST_DEDUCED_TYPENAME result_of<Function ()>::type const &
dereference() const {
return (value ? value : value = (*f)()).get();
}
@ -58,7 +60,7 @@ namespace iterators {
private:
Function * f;
Input state;
mutable optional<typename Function::result_type> value;
mutable optional<BOOST_DEDUCED_TYPENAME result_of<Function ()>::type> value;
};
template <class Function, class Input>

View File

@ -7,7 +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>
@ -40,14 +39,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>

View File

@ -84,7 +84,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;

View File

@ -55,4 +55,7 @@ test-suite iterator
[ run minimum_category.cpp ]
[ compile-fail minimum_category_compile_fail.cpp ]
[ run advance_test.cpp ]
[ run distance_test.cpp ]
;

91
test/advance_test.cpp Normal file
View 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();
}

View File

@ -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.data(), vs.data()));
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
View 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();
}

View File

@ -11,6 +11,7 @@
#include <iterator>
#include <vector>
#include <boost/config.hpp>
#include <boost/iterator/function_input_iterator.hpp>
namespace {
@ -96,6 +97,23 @@ int main(int argc, char * argv[])
assert(generated[i] == 42 + i);
cout << "function iterator test with stateful function object successful." << endl;
#if !defined(BOOST_NO_CXX11_LAMBDAS) && !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
// test the iterator with lambda expressions
int num = 42;
auto lambda_generator = [&num] { return num++; };
vector<int>().swap(generated);
copy(
boost::make_function_input_iterator(lambda_generator, 0),
boost::make_function_input_iterator(lambda_generator, 10),
back_inserter(generated)
);
assert(generated.size() == 10);
for(std::size_t i = 0; i != 10; ++i)
assert(generated[i] == 42 + i);
cout << "function iterator test with lambda expressions successful." << endl;
#endif // BOOST_NO_CXX11_LAMBDAS
return 0;
}

View File

@ -33,37 +33,6 @@
using boost::dummyT;
struct mult_functor {
typedef int result_type;
typedef int argument_type;
// Functors used with transform_iterator must be
// DefaultConstructible, as the transform_iterator must be
// DefaultConstructible to satisfy the requirements for
// TrivialIterator.
mult_functor() { }
mult_functor(int aa) : a(aa) { }
int operator()(int b) const { return a * b; }
int a;
};
template <class Pair>
struct select1st_
: public std::unary_function<Pair, typename Pair::first_type>
{
const typename Pair::first_type& operator()(const Pair& x) const {
return x.first;
}
typename Pair::first_type& operator()(Pair& x) const {
return x.first;
}
};
struct one_or_four {
bool operator()(dummyT x) const {
return x.foo() == 1 || x.foo() == 4;
}
};
typedef std::deque<int> storage;
typedef std::deque<int*> pointer_deque;
typedef std::set<storage::iterator> iterator_set;

View File

@ -56,12 +56,24 @@ int main()
STATIC_ASSERT_SAME(boost::pointee<X*>::type, X);
STATIC_ASSERT_SAME(boost::pointee<X const*>::type, X const);
#if defined(BOOST_NO_CXX11_SMART_PTR)
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int> >::type, int);
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X> >::type, X);
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<int const> >::type, int const);
STATIC_ASSERT_SAME(boost::pointee<std::auto_ptr<X const> >::type, X const);
#else
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<int> >::type, int);
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<X> >::type, X);
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<int const> >::type, int const);
STATIC_ASSERT_SAME(boost::pointee<std::unique_ptr<X const> >::type, X const);
#endif
STATIC_ASSERT_SAME(boost::pointee<std::list<int>::iterator >::type, int);
STATIC_ASSERT_SAME(boost::pointee<std::list<X>::iterator >::type, X);

View File

@ -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>