forked from boostorg/iterator
Compare commits
1 Commits
svn-branch
...
boost-1.20
Author | SHA1 | Date | |
---|---|---|---|
7684db9bbc |
58
include/boost/iterator.hpp
Normal file
58
include/boost/iterator.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
// integer.hpp workarounds for non-conforming standard libraries -----------//
|
||||
|
||||
// (C) Copyright Boost.org 2000. Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 28 Jun 00 Workarounds to deal with known MSVC bugs (David Abrahams)
|
||||
// 26 Jun 00 Initial version (Jeremy Siek)
|
||||
|
||||
#ifndef BOOST_ITERATOR_HPP
|
||||
#define BOOST_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
# ifdef BOOST_NO_STD_ITERATOR
|
||||
template <class Category, class T,
|
||||
class Distance = std::ptrdiff_t,
|
||||
class Pointer = T*, class Reference = T&>
|
||||
struct iterator
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Distance difference_type;
|
||||
typedef Pointer pointer;
|
||||
typedef Reference reference;
|
||||
typedef Category iterator_category;
|
||||
};
|
||||
# else
|
||||
|
||||
// declare iterator_base in namespace detail to work around MSVC bugs which
|
||||
// prevent derivation from an identically-named class in a different namespace.
|
||||
namespace detail {
|
||||
template <class Category, class T, class Distance, class Pointer, class Reference>
|
||||
# if !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
struct iterator_base : std::iterator<Category, T, Distance, Pointer, Reference> {};
|
||||
# else
|
||||
struct iterator_base : std::iterator<Category, T, Distance>
|
||||
{
|
||||
typedef Reference reference;
|
||||
typedef Pointer pointer;
|
||||
typedef Distance difference_type;
|
||||
};
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class Category, class T, class Distance = std::ptrdiff_t,
|
||||
class Pointer = T*, class Reference = T&>
|
||||
struct iterator : detail::iterator_base<Category, T, Distance, Pointer, Reference> {};
|
||||
# endif
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ITERATOR_HPP
|
@ -1,353 +0,0 @@
|
||||
// (C) Copyright David Abrahams and Thomas Becker 2000. Permission to
|
||||
// copy, use, modify, sell and distribute this software is granted
|
||||
// provided this copyright notice appears in all copies. This software
|
||||
// is provided "as is" without express or implied warranty, and with
|
||||
// no claim as to its suitability for any purpose.
|
||||
//
|
||||
// Compilers Tested:
|
||||
// =================
|
||||
// Metrowerks Codewarrior Pro 7.2, 8.3
|
||||
// gcc 2.95.3
|
||||
// gcc 3.2
|
||||
// Microsoft VC 6sp5 (test fails due to some compiler bug)
|
||||
// Microsoft VC 7 (works)
|
||||
// Microsoft VC 7.1
|
||||
// Intel 5
|
||||
// Intel 6
|
||||
// Intel 7.1
|
||||
// Intel 8
|
||||
// Borland 5.5.1 (broken due to lack of support from Boost.Tuples)
|
||||
|
||||
#ifndef BOOST_ZIP_ITERATOR_TMB_07_13_2003_HPP_
|
||||
# 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
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
#include <boost/iterator/detail/minimum_category.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/apply.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/mpl/lambda.hpp>
|
||||
#include <boost/mpl/placeholders.hpp>
|
||||
#include <boost/mpl/aux_/lambda_support.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/fold.hpp>
|
||||
#include <boost/mpl/transform.hpp>
|
||||
|
||||
#include <boost/spirit/fusion/algorithm/transform.hpp>
|
||||
#include <boost/spirit/fusion/algorithm/for_each.hpp>
|
||||
#include <boost/spirit/fusion/algorithm/fold.hpp>
|
||||
#include <boost/spirit/fusion/sequence/generate.hpp>
|
||||
#include <boost/spirit/fusion/sequence/begin.hpp>
|
||||
#include <boost/spirit/fusion/algorithm/push_front.hpp>
|
||||
#include <boost/spirit/fusion/sequence/equal_to.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// Zip iterator forward declaration for zip_iterator_base
|
||||
template<typename IteratorTuple>
|
||||
class zip_iterator;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Functors to be used with tuple algorithms
|
||||
//
|
||||
template<typename DiffType>
|
||||
class advance_iterator
|
||||
{
|
||||
public:
|
||||
advance_iterator(DiffType step) : m_step(step) {}
|
||||
|
||||
template<typename Iterator>
|
||||
void operator()(Iterator& it) const
|
||||
{ it += m_step; }
|
||||
|
||||
private:
|
||||
DiffType m_step;
|
||||
};
|
||||
//
|
||||
struct increment_iterator
|
||||
{
|
||||
template<typename Iterator>
|
||||
void operator()(Iterator& it) const
|
||||
{ ++it; }
|
||||
};
|
||||
//
|
||||
struct decrement_iterator
|
||||
{
|
||||
template<typename Iterator>
|
||||
void operator()(Iterator& it) const
|
||||
{ --it; }
|
||||
};
|
||||
//
|
||||
struct dereference_iterator
|
||||
{
|
||||
template<typename Iterator>
|
||||
struct apply : iterator_reference<Iterator>
|
||||
{};
|
||||
|
||||
template<typename Iterator>
|
||||
typename apply<Iterator>::type
|
||||
operator()(Iterator const& it) const
|
||||
{ return *it; }
|
||||
};
|
||||
|
||||
struct dereference
|
||||
{
|
||||
template <class Iterator>
|
||||
struct apply
|
||||
: boost::iterator_reference<Iterator>
|
||||
{};
|
||||
|
||||
template <class Iterator>
|
||||
typename apply<Iterator>::type operator()(Iterator const& x) const
|
||||
{
|
||||
return *x;
|
||||
}
|
||||
};
|
||||
|
||||
// Metafunction to obtain the type of the tuple whose element types
|
||||
// are the reference types of an iterator tuple.
|
||||
//
|
||||
template<typename IteratorTuple>
|
||||
struct tuple_of_references
|
||||
: mpl::transform<IteratorTuple, dereference::apply<mpl::_1> >
|
||||
{};
|
||||
|
||||
// Metafunction to obtain the minimal traversal tag in a tuple
|
||||
// of iterators.
|
||||
//
|
||||
template<typename IteratorTuple>
|
||||
struct minimum_traversal_category_in_iterator_tuple
|
||||
: mpl::fold<
|
||||
typename mpl::transform<
|
||||
IteratorTuple, iterator_traversal<>
|
||||
>::type
|
||||
, random_access_traversal_tag
|
||||
, minimum_category<>
|
||||
>
|
||||
{};
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) // ETI workaround
|
||||
template <>
|
||||
struct minimum_traversal_category_in_iterator_tuple<int>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
#endif
|
||||
|
||||
// We need to call tuple_meta_accumulate with mpl::and_ as the
|
||||
// accumulating functor. To this end, we need to wrap it into
|
||||
// a struct that has exactly two arguments (that is, template
|
||||
// parameters) and not five, like mpl::and_ does.
|
||||
//
|
||||
template<typename Arg1, typename Arg2>
|
||||
struct and_with_two_args
|
||||
: mpl::and_<Arg1, Arg2>
|
||||
{
|
||||
};
|
||||
|
||||
# ifdef BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
|
||||
// Hack because BOOST_MPL_AUX_LAMBDA_SUPPORT doesn't seem to work
|
||||
// out well. In this case I think it's an MPL bug
|
||||
template<>
|
||||
struct and_with_two_args<mpl::_1,mpl::_2>
|
||||
{
|
||||
template <class A1, class A2>
|
||||
struct apply : mpl::and_<A1,A2>
|
||||
{};
|
||||
};
|
||||
# endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Class zip_iterator_base
|
||||
//
|
||||
// Builds and exposes the iterator facade type from which the zip
|
||||
// iterator will be derived.
|
||||
//
|
||||
template<typename IteratorTuple>
|
||||
struct zip_iterator_base
|
||||
{
|
||||
private:
|
||||
// Reference type is the type of the tuple obtained from the
|
||||
// iterators' reference types.
|
||||
typedef typename
|
||||
detail::tuple_of_references<IteratorTuple>::type reference;
|
||||
|
||||
// Value type is the same as reference type.
|
||||
typedef reference value_type;
|
||||
|
||||
// Difference type is the first iterator's difference type
|
||||
typedef typename iterator_traits<
|
||||
typename mpl::front<IteratorTuple>::type
|
||||
>::difference_type difference_type;
|
||||
|
||||
// Traversal catetgory is the minimum traversal category in the
|
||||
// iterator tuple.
|
||||
typedef typename
|
||||
detail::minimum_traversal_category_in_iterator_tuple<
|
||||
IteratorTuple
|
||||
>::type traversal_category;
|
||||
public:
|
||||
|
||||
// The iterator facade type from which the zip iterator will
|
||||
// be derived.
|
||||
typedef iterator_facade<
|
||||
zip_iterator<IteratorTuple>,
|
||||
value_type,
|
||||
traversal_category,
|
||||
reference,
|
||||
difference_type
|
||||
> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct zip_iterator_base<int>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// zip_iterator class definition
|
||||
//
|
||||
template<typename IteratorTuple>
|
||||
class zip_iterator :
|
||||
public detail::zip_iterator_base<IteratorTuple>::type
|
||||
{
|
||||
|
||||
// Typedef super_t as our base class.
|
||||
typedef typename
|
||||
detail::zip_iterator_base<IteratorTuple>::type super_t;
|
||||
|
||||
// iterator_core_access is the iterator's best friend.
|
||||
friend class iterator_core_access;
|
||||
|
||||
public:
|
||||
|
||||
// Construction
|
||||
// ============
|
||||
|
||||
// Default constructor
|
||||
zip_iterator() { }
|
||||
|
||||
// Constructor from iterator tuple
|
||||
zip_iterator(IteratorTuple iterator_tuple)
|
||||
: m_iterator_tuple(iterator_tuple)
|
||||
{ }
|
||||
|
||||
// Copy constructor
|
||||
template<typename OtherIteratorTuple>
|
||||
zip_iterator(
|
||||
const zip_iterator<OtherIteratorTuple>& other,
|
||||
typename enable_if_convertible<
|
||||
OtherIteratorTuple,
|
||||
IteratorTuple
|
||||
>::type* = 0
|
||||
) : m_iterator_tuple(other.get_iterator_tuple())
|
||||
{}
|
||||
|
||||
// Get method for the iterator tuple.
|
||||
const IteratorTuple& get_iterator_tuple() const
|
||||
{ return m_iterator_tuple; }
|
||||
|
||||
private:
|
||||
|
||||
// Implementation of Iterator Operations
|
||||
// =====================================
|
||||
|
||||
// Dereferencing returns a tuple built from the dereferenced
|
||||
// iterators in the iterator tuple.
|
||||
typename super_t::reference dereference() const
|
||||
{
|
||||
return fusion::generate(fusion::transform(
|
||||
get_iterator_tuple(),
|
||||
detail::dereference_iterator()
|
||||
));
|
||||
}
|
||||
|
||||
// Two zip iterators are equal if all iterators in the iterator
|
||||
// tuple are equal. NOTE: It should be possible to implement this
|
||||
// as
|
||||
//
|
||||
// return get_iterator_tuple() == other.get_iterator_tuple();
|
||||
//
|
||||
// but equality of tuples currently (7/2003) does not compile
|
||||
// under several compilers. No point in bringing in a bunch
|
||||
// of #ifdefs here.
|
||||
//
|
||||
template<typename OtherIteratorTuple>
|
||||
bool equal(const zip_iterator<OtherIteratorTuple>& other) const
|
||||
{
|
||||
return get_iterator_tuple() == other.get_iterator_tuple();
|
||||
}
|
||||
|
||||
// Advancing a zip iterator means to advance all iterators in the
|
||||
// iterator tuple.
|
||||
void advance(typename super_t::difference_type n)
|
||||
{
|
||||
fusion::for_each(
|
||||
m_iterator_tuple,
|
||||
detail::advance_iterator<BOOST_DEDUCED_TYPENAME super_t::difference_type>(n)
|
||||
);
|
||||
}
|
||||
// Incrementing a zip iterator means to increment all iterators in
|
||||
// the iterator tuple.
|
||||
void increment()
|
||||
{
|
||||
fusion::for_each(
|
||||
m_iterator_tuple,
|
||||
detail::increment_iterator()
|
||||
);
|
||||
}
|
||||
|
||||
// Decrementing a zip iterator means to decrement all iterators in
|
||||
// the iterator tuple.
|
||||
void decrement()
|
||||
{
|
||||
fusion::for_each(
|
||||
m_iterator_tuple,
|
||||
detail::decrement_iterator()
|
||||
);
|
||||
}
|
||||
|
||||
// Distance is calculated using the first iterator in the tuple.
|
||||
template<typename OtherIteratorTuple>
|
||||
typename super_t::difference_type distance_to(
|
||||
const zip_iterator<OtherIteratorTuple>& other
|
||||
) const
|
||||
{
|
||||
return *fusion::begin(other.get_iterator_tuple()) -
|
||||
*fusion::begin(this->get_iterator_tuple());
|
||||
}
|
||||
|
||||
// Data Members
|
||||
// ============
|
||||
|
||||
// The iterator tuple.
|
||||
IteratorTuple m_iterator_tuple;
|
||||
|
||||
};
|
||||
|
||||
// Make function for zip iterator
|
||||
//
|
||||
template<typename IteratorTuple>
|
||||
zip_iterator<IteratorTuple>
|
||||
make_zip_iterator(IteratorTuple t)
|
||||
{ return zip_iterator<IteratorTuple>(t); }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
75
include/boost/pending/detail/int_iterator.hpp
Normal file
75
include/boost/pending/detail/int_iterator.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
// (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify,
|
||||
// sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#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>
|
||||
//using namespace std;
|
||||
|
||||
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
namespace boost {
|
||||
#endif
|
||||
|
||||
// this should use random_access_iterator_helper but I've had
|
||||
// VC++ portablility problems with that. -JGS
|
||||
template <class IntT>
|
||||
class int_iterator
|
||||
{
|
||||
typedef int_iterator self;
|
||||
public:
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef IntT value_type;
|
||||
typedef IntT& reference;
|
||||
typedef IntT* pointer;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
inline int_iterator() : _i(0) { }
|
||||
inline int_iterator(IntT i) : _i(i) { }
|
||||
inline int_iterator(const self& x) : _i(x._i) { }
|
||||
inline self& operator=(const self& x) { _i = x._i; return *this; }
|
||||
inline IntT operator*() { return _i; }
|
||||
inline IntT operator[](IntT n) { return _i + n; }
|
||||
inline self& operator++() { ++_i; return *this; }
|
||||
inline self operator++(int) { self t = *this; ++_i; return t; }
|
||||
inline self& operator+=(IntT n) { _i += n; return *this; }
|
||||
inline self operator+(IntT n) { self t = *this; t += n; return t; }
|
||||
inline self& operator--() { --_i; return *this; }
|
||||
inline self operator--(int) { self t = *this; --_i; return t; }
|
||||
inline self& operator-=(IntT n) { _i -= n; return *this; }
|
||||
inline IntT operator-(const self& x) const { return _i - x._i; }
|
||||
inline bool operator==(const self& x) const { return _i == x._i; }
|
||||
// vc++ had a problem finding != in random_access_iterator_helper
|
||||
// need to look into this... for now implementing everything here -JGS
|
||||
inline bool operator!=(const self& x) const { return _i != x._i; }
|
||||
inline bool operator<(const self& x) const { return _i < x._i; }
|
||||
inline bool operator<=(const self& x) const { return _i <= x._i; }
|
||||
inline bool operator>(const self& x) const { return _i > x._i; }
|
||||
inline bool operator>=(const self& x) const { return _i >= x._i; }
|
||||
protected:
|
||||
IntT _i;
|
||||
};
|
||||
|
||||
template <class IntT>
|
||||
inline int_iterator<IntT>
|
||||
operator+(IntT n, int_iterator<IntT> t) { t += n; return t; }
|
||||
|
||||
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
} /* namespace boost */
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
namespace boost {
|
||||
using ::int_iterator;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* BOOST_INT_ITERATOR_H */
|
99
include/boost/pending/integer_range.hpp
Normal file
99
include/boost/pending/integer_range.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
|
||||
// sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#ifndef BOOST_INTEGER_RANGE_HPP_
|
||||
#define BOOST_INTEGER_RANGE_HPP_
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if 1
|
||||
// Still evaluating whether VC++ can handle this.
|
||||
#define BOOST_USE_ITERATOR_ADAPTORS
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_USE_ITERATOR_ADAPTORS
|
||||
#include <boost/pending/iterator_adaptors.hpp>
|
||||
#else
|
||||
#include <boost/pending/detail/int_iterator.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
//=============================================================================
|
||||
// Counting Iterator and Integer Range Class
|
||||
|
||||
#ifdef BOOST_USE_ITERATOR_ADAPTORS
|
||||
template <class IntegerType>
|
||||
struct counting_iterator_policies : public default_iterator_policies
|
||||
{
|
||||
IntegerType
|
||||
dereference(type<IntegerType>, const IntegerType& i) const
|
||||
{ return i; }
|
||||
};
|
||||
template <class IntegerType>
|
||||
struct counting_iterator_traits {
|
||||
typedef IntegerType value_type;
|
||||
typedef IntegerType reference;
|
||||
typedef value_type* pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
};
|
||||
#endif
|
||||
|
||||
template <class IntegerType>
|
||||
struct integer_range {
|
||||
#ifdef BOOST_USE_ITERATOR_ADAPTORS
|
||||
typedef iterator_adaptor<IntegerType,
|
||||
counting_iterator_policies<IntegerType>,
|
||||
counting_iterator_traits<IntegerType> > iterator;
|
||||
#else
|
||||
typedef int_iterator<IntegerType> iterator;
|
||||
#endif
|
||||
|
||||
typedef iterator const_iterator;
|
||||
typedef IntegerType value_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef IntegerType reference;
|
||||
typedef IntegerType const_reference;
|
||||
typedef const IntegerType* pointer;
|
||||
typedef const IntegerType* const_pointer;
|
||||
typedef IntegerType size_type;
|
||||
|
||||
integer_range(IntegerType start, IntegerType finish)
|
||||
: m_start(start), m_finish(finish) { }
|
||||
|
||||
iterator begin() const { return iterator(m_start); }
|
||||
iterator end() const { return iterator(m_finish); }
|
||||
size_type size() const { return m_finish - m_start; }
|
||||
bool empty() const { return m_finish == m_start; }
|
||||
void swap(integer_range& x) {
|
||||
std::swap(m_start, x.m_start);
|
||||
std::swap(m_finish, x.m_finish);
|
||||
}
|
||||
protected:
|
||||
IntegerType m_start, m_finish;
|
||||
};
|
||||
|
||||
template <class IntegerType>
|
||||
inline integer_range<IntegerType>
|
||||
make_integer_range(IntegerType first, IntegerType last)
|
||||
{
|
||||
return integer_range<IntegerType>(first, last);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_USE_ITERATOR_ADAPTORS
|
||||
#undef BOOST_USE_ITERATOR_ADAPTORS
|
||||
#endif
|
||||
|
||||
#endif // BOOST_INTEGER_RANGE_HPP_
|
735
include/boost/pending/iterator_adaptors.hpp
Normal file
735
include/boost/pending/iterator_adaptors.hpp
Normal file
@ -0,0 +1,735 @@
|
||||
// (C) Copyright David Abrahams 2000. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
|
||||
// sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
|
||||
#ifndef BOOST_ITERATOR_ADAPTOR_DWA053000_HPP_
|
||||
#define BOOST_ITERATOR_ADAPTOR_DWA053000_HPP_
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/compressed_pair.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
// I was having some problems with VC6. I couldn't tell whether our hack for
|
||||
// stock GCC was causing problems so I needed an easy way to turn it on and
|
||||
// off. Now we can test the hack with various compilers and still have an
|
||||
// "out" if it doesn't work. -dwa 7/31/00
|
||||
#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96 && !defined(__STL_USE_NAMESPACES)
|
||||
# define BOOST_RELOPS_AMBIGUITY_BUG 1
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
// Just a "type envelope"; works around some MSVC deficiencies.
|
||||
template <class T>
|
||||
struct type {};
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Concept checking classes that express the requirements for iterator
|
||||
// policies and adapted types. These classes are mostly for
|
||||
// documentation purposes, and are not used in this header file. They
|
||||
// merely provide a more succinct statement of what is expected of the
|
||||
// iterator policies.
|
||||
|
||||
template <class Policies, class Adapted, class Traits>
|
||||
struct TrivialIteratorPoliciesConcept
|
||||
{
|
||||
typedef typename Traits::reference Reference;
|
||||
void constraints() {
|
||||
function_requires< AssignableConcept<Policies> >();
|
||||
function_requires< DefaultConstructibleConcept<Policies> >();
|
||||
function_requires< AssignableConcept<Adapted> >();
|
||||
function_requires< DefaultConstructibleConcept<Adapted> >();
|
||||
|
||||
const_constraints();
|
||||
}
|
||||
void const_constraints() const {
|
||||
Reference r = p.dereference(type<Reference>(), x);
|
||||
b = p.equal(x, x);
|
||||
}
|
||||
Policies p;
|
||||
Adapted x;
|
||||
mutable bool b;
|
||||
};
|
||||
|
||||
template <class Policies, class Adapted, class Traits>
|
||||
struct ForwardIteratorPoliciesConcept
|
||||
{
|
||||
void constraints() {
|
||||
function_requires<
|
||||
TrivialIteratorPoliciesConcept<Policies, Adapted, Traits>
|
||||
>();
|
||||
|
||||
p.increment(x);
|
||||
}
|
||||
Policies p;
|
||||
Adapted x;
|
||||
};
|
||||
|
||||
template <class Policies, class Adapted, class Traits>
|
||||
struct BidirectionalIteratorPoliciesConcept
|
||||
{
|
||||
void constraints() {
|
||||
function_requires<
|
||||
ForwardIteratorPoliciesConcept<Policies, Adapted, Traits>
|
||||
>();
|
||||
|
||||
p.decrement(x);
|
||||
}
|
||||
Policies p;
|
||||
Adapted x;
|
||||
};
|
||||
|
||||
template <class Policies, class Adapted, class Traits>
|
||||
struct RandomAccessIteratorPoliciesConcept
|
||||
{
|
||||
typedef typename Traits::difference_type DifferenceType;
|
||||
void constraints() {
|
||||
function_requires<
|
||||
BidirectionalIteratorPoliciesConcept<Policies, Adapted, Traits>
|
||||
>();
|
||||
|
||||
p.advance(x, n);
|
||||
const_constraints();
|
||||
}
|
||||
void const_constraints() const {
|
||||
n = p.distance(type<DifferenceType>(), x, x);
|
||||
b = p.less(x, x);
|
||||
}
|
||||
Policies p;
|
||||
Adapted x;
|
||||
mutable DifferenceType n;
|
||||
mutable bool b;
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
// Default policies for iterator adaptors. You can use this as a base
|
||||
// class if you want to customize particular policies.
|
||||
struct default_iterator_policies
|
||||
{
|
||||
// Some of these members were defined static, but Borland got confused
|
||||
// and thought they were non-const. Also, Sun C++ does not like static
|
||||
// function templates.
|
||||
|
||||
template <class Reference, class Iterator>
|
||||
Reference dereference(type<Reference>, const Iterator& x) const
|
||||
{ return *x; }
|
||||
|
||||
template <class Iterator>
|
||||
void increment(Iterator& x)
|
||||
{ ++x; }
|
||||
|
||||
template <class Iterator>
|
||||
void decrement(Iterator& x)
|
||||
{ --x; }
|
||||
|
||||
template <class Iterator, class DifferenceType>
|
||||
void advance(Iterator& x, DifferenceType n)
|
||||
{ x += n; }
|
||||
|
||||
template <class Difference, class Iterator1, class Iterator2>
|
||||
Difference distance(type<Difference>, const Iterator1& x,
|
||||
const Iterator2& y) const
|
||||
{ return y - x; }
|
||||
|
||||
template <class Iterator1, class Iterator2>
|
||||
bool equal(const Iterator1& x, const Iterator2& y) const
|
||||
{ return x == y; }
|
||||
|
||||
template <class Iterator1, class Iterator2>
|
||||
bool less(const Iterator1& x, const Iterator2& y) const
|
||||
{ return x < y; }
|
||||
};
|
||||
|
||||
// putting the comparisons in a base class avoids the g++
|
||||
// ambiguous overload bug due to the relops operators
|
||||
|
||||
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
|
||||
template <class Derived, class Base>
|
||||
struct iterator_comparisons : Base { };
|
||||
|
||||
template <class D1, class D2, class Base1, class Base2>
|
||||
inline bool operator==(const iterator_comparisons<D1,Base1>& xb,
|
||||
const iterator_comparisons<D2,Base2>& yb)
|
||||
{
|
||||
const D1& x = static_cast<const D1&>(xb);
|
||||
const D2& y = static_cast<const D2&>(yb);
|
||||
return x.policies().equal(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class D1, class D2, class Base1, class Base2>
|
||||
inline bool operator!=(const iterator_comparisons<D1,Base1>& xb,
|
||||
const iterator_comparisons<D2,Base2>& yb)
|
||||
{
|
||||
const D1& x = static_cast<const D1&>(xb);
|
||||
const D2& y = static_cast<const D2&>(yb);
|
||||
return !x.policies().equal(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class D1, class D2, class Base1, class Base2>
|
||||
inline bool operator<(const iterator_comparisons<D1,Base1>& xb,
|
||||
const iterator_comparisons<D2,Base2>& yb)
|
||||
{
|
||||
const D1& x = static_cast<const D1&>(xb);
|
||||
const D2& y = static_cast<const D2&>(yb);
|
||||
return x.policies().less(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class D1, class D2, class Base1, class Base2>
|
||||
inline bool operator>(const iterator_comparisons<D1,Base1>& xb,
|
||||
const iterator_comparisons<D2,Base2>& yb)
|
||||
{
|
||||
const D1& x = static_cast<const D1&>(xb);
|
||||
const D2& y = static_cast<const D2&>(yb);
|
||||
return x.policies().less(y.iter(), x.iter());
|
||||
}
|
||||
|
||||
template <class D1, class D2, class Base1, class Base2>
|
||||
inline bool operator>=(const iterator_comparisons<D1,Base1>& xb,
|
||||
const iterator_comparisons<D2,Base2>& yb)
|
||||
{
|
||||
const D1& x = static_cast<const D1&>(xb);
|
||||
const D2& y = static_cast<const D2&>(yb);
|
||||
return !x.policies().less(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class D1, class D2, class Base1, class Base2>
|
||||
inline bool operator<=(const iterator_comparisons<D1,Base1>& xb,
|
||||
const iterator_comparisons<D2,Base2>& yb)
|
||||
{
|
||||
const D1& x = static_cast<const D1&>(xb);
|
||||
const D2& y = static_cast<const D2&>(yb);
|
||||
return !x.policies().less(y.iter(), x.iter());
|
||||
}
|
||||
#endif
|
||||
|
||||
//============================================================================
|
||||
// iterator_adaptor - A generalized adaptor around an existing
|
||||
// iterator, which is itself an iterator
|
||||
//
|
||||
// Iterator - the iterator type being wrapped.
|
||||
//
|
||||
// Policies - a set of policies determining how the resulting iterator
|
||||
// works.
|
||||
//
|
||||
// Traits - a class satisfying the same requirements as a specialization of
|
||||
// std::iterator_traits for the resulting iterator.
|
||||
//
|
||||
template <class Iterator, class Policies,
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits
|
||||
#else
|
||||
class Traits = std::iterator_traits<Iterator>
|
||||
#endif
|
||||
>
|
||||
struct iterator_adaptor :
|
||||
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
|
||||
iterator_comparisons<
|
||||
iterator_adaptor<Iterator,Policies,Traits>,
|
||||
#endif
|
||||
boost::iterator<typename Traits::iterator_category,
|
||||
typename Traits::value_type, typename Traits::difference_type,
|
||||
typename Traits::pointer, typename Traits::reference>
|
||||
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
|
||||
>
|
||||
#endif
|
||||
{
|
||||
typedef iterator_adaptor<Iterator, Policies, Traits> Self;
|
||||
public:
|
||||
typedef typename Traits::difference_type difference_type;
|
||||
typedef typename Traits::value_type value_type;
|
||||
typedef typename Traits::pointer pointer;
|
||||
typedef typename Traits::reference reference;
|
||||
typedef typename Traits::iterator_category iterator_category;
|
||||
typedef Iterator iterator_type;
|
||||
|
||||
iterator_adaptor() { }
|
||||
|
||||
iterator_adaptor(const Iterator& iter, const Policies& p = Policies())
|
||||
: m_iter_p(iter, p) {}
|
||||
|
||||
template <class OtherIter, class OtherTraits>
|
||||
iterator_adaptor (const iterator_adaptor<OtherIter, Policies,
|
||||
OtherTraits>& src)
|
||||
: m_iter_p(src.iter(), src.policies()) {
|
||||
}
|
||||
|
||||
reference operator*() const {
|
||||
return policies().dereference(type<reference>(), iter());
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning( disable : 4284 )
|
||||
#endif
|
||||
|
||||
pointer operator->() const
|
||||
{ return &*this; }
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
reference operator[](difference_type n) const
|
||||
{ return *(*this + n); }
|
||||
|
||||
Self& operator++() {
|
||||
#ifdef __MWERKS__
|
||||
// Odd bug, MWERKS couldn't deduce the type for the member template
|
||||
// Workaround by explicitly specifying the type.
|
||||
policies().increment<Iterator>(iter());
|
||||
#else
|
||||
policies().increment(iter());
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
Self operator++(int) { Self tmp(*this); ++*this; return tmp; }
|
||||
|
||||
Self& operator--() {
|
||||
#ifdef __MWERKS__
|
||||
policies().decrement<Iterator>(iter());
|
||||
#else
|
||||
policies().decrement(iter());
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
Self operator--(int) { Self tmp(*this); --*this; return tmp; }
|
||||
|
||||
Self& operator+=(difference_type n) {
|
||||
#ifdef __MWERKS__
|
||||
policies().advance<Iterator>(iter(), n);
|
||||
#else
|
||||
policies().advance(iter(), n);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
Self& operator-=(difference_type n) {
|
||||
#ifdef __MWERKS__
|
||||
policies().advance<Iterator>(iter(), -n);
|
||||
#else
|
||||
policies().advance(iter(), -n);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator_type base() const { return m_iter_p.first(); }
|
||||
|
||||
private:
|
||||
typedef Policies policies_type;
|
||||
compressed_pair<Iterator,Policies> m_iter_p;
|
||||
public: // too many compilers have trouble when these are private.
|
||||
Policies& policies() { return m_iter_p.second(); }
|
||||
const Policies& policies() const { return m_iter_p.second(); }
|
||||
Iterator& iter() { return m_iter_p.first(); }
|
||||
const Iterator& iter() const { return m_iter_p.first(); }
|
||||
};
|
||||
|
||||
template <class Iterator, class Policies, class Traits>
|
||||
iterator_adaptor<Iterator,Policies,Traits>
|
||||
operator-(iterator_adaptor<Iterator,Policies,Traits> p, const typename Traits::difference_type x)
|
||||
{
|
||||
return p -= x;
|
||||
}
|
||||
|
||||
template <class Iterator, class Policies, class Traits>
|
||||
iterator_adaptor<Iterator,Policies,Traits>
|
||||
operator+(iterator_adaptor<Iterator,Policies,Traits> p, typename Traits::difference_type x)
|
||||
{
|
||||
return p += x;
|
||||
}
|
||||
|
||||
template <class Iterator, class Policies, class Traits>
|
||||
iterator_adaptor<Iterator,Policies,Traits>
|
||||
operator+(typename Traits::difference_type x, iterator_adaptor<Iterator,Policies,Traits> p)
|
||||
{
|
||||
return p += x;
|
||||
}
|
||||
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
typename Traits1::difference_type operator-(
|
||||
const iterator_adaptor<Iterator1,Policies,Traits1>& x,
|
||||
const iterator_adaptor<Iterator2,Policies,Traits2>& y )
|
||||
{
|
||||
typedef typename Traits1::difference_type difference_type;
|
||||
return x.policies().distance(type<difference_type>(), y.iter(), x.iter());
|
||||
}
|
||||
|
||||
#ifndef BOOST_RELOPS_AMBIGUITY_BUG
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
inline bool
|
||||
operator==(const iterator_adaptor<Iterator1,Policies,Traits1>& x, const iterator_adaptor<Iterator2,Policies,Traits2>& y) {
|
||||
return x.policies().equal(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
inline bool
|
||||
operator<(const iterator_adaptor<Iterator1,Policies,Traits1>& x, const iterator_adaptor<Iterator2,Policies,Traits2>& y) {
|
||||
return x.policies().less(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
inline bool
|
||||
operator>(const iterator_adaptor<Iterator1,Policies,Traits1>& x,
|
||||
const iterator_adaptor<Iterator2,Policies,Traits2>& y) {
|
||||
return x.policies().less(y.iter(), x.iter());
|
||||
}
|
||||
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
inline bool
|
||||
operator>=(const iterator_adaptor<Iterator1,Policies,Traits1>& x, const iterator_adaptor<Iterator2,Policies,Traits2>& y) {
|
||||
return !x.policies().less(x.iter(), y.iter());
|
||||
}
|
||||
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
inline bool
|
||||
operator<=(const iterator_adaptor<Iterator1,Policies,Traits1>& x,
|
||||
const iterator_adaptor<Iterator2,Policies,Traits2>& y) {
|
||||
return !x.policies().less(y.iter(), x.iter());
|
||||
}
|
||||
|
||||
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2>
|
||||
inline bool
|
||||
operator!=(const iterator_adaptor<Iterator1,Policies,Traits1>& x,
|
||||
const iterator_adaptor<Iterator2,Policies,Traits2>& y) {
|
||||
return !x.policies().equal(x.iter(), y.iter());
|
||||
}
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
// iterator_adaptors - A type generator that simplifies creating
|
||||
// mutable/const pairs of iterator adaptors.
|
||||
|
||||
template <class Iterator, class ConstIterator,
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits,
|
||||
class ConstTraits,
|
||||
#else
|
||||
class Traits = std::iterator_traits<Iterator>,
|
||||
class ConstTraits = std::iterator_traits<ConstIterator>,
|
||||
#endif
|
||||
class Policies = default_iterator_policies>
|
||||
class iterator_adaptors
|
||||
{
|
||||
public:
|
||||
typedef iterator_adaptor<Iterator, Policies, Traits> iterator;
|
||||
typedef iterator_adaptor<ConstIterator, Policies, ConstTraits>
|
||||
const_iterator;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// Transform Iterator Adaptor
|
||||
//
|
||||
// Upon deference, apply some unary function object and return the
|
||||
// result by value.
|
||||
|
||||
template <class AdaptableUnaryFunction>
|
||||
struct transform_iterator_policies : public default_iterator_policies
|
||||
{
|
||||
transform_iterator_policies() { }
|
||||
transform_iterator_policies(const AdaptableUnaryFunction& f) : m_f(f) { }
|
||||
|
||||
template <class Reference, class Iterator>
|
||||
Reference dereference(type<Reference>, const Iterator& iter) const
|
||||
{ return m_f(*iter); }
|
||||
|
||||
AdaptableUnaryFunction m_f;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction, class IteratorTraits>
|
||||
struct transform_iterator_traits {
|
||||
typedef typename AdaptableUnaryFunction::result_type value_type;
|
||||
typedef value_type reference;
|
||||
typedef value_type* pointer;
|
||||
typedef typename IteratorTraits::difference_type difference_type;
|
||||
typedef typename IteratorTraits::iterator_category iterator_category;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction,
|
||||
class Iterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits = std::iterator_traits<Iterator>
|
||||
#else
|
||||
class Traits
|
||||
#endif
|
||||
>
|
||||
struct transform_iterator
|
||||
{
|
||||
typedef transform_iterator_traits<AdaptableUnaryFunction,Traits>
|
||||
TransTraits;
|
||||
typedef iterator_adaptor<Iterator,
|
||||
transform_iterator_policies<AdaptableUnaryFunction>, TransTraits>
|
||||
type;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// Indirect Iterators Adaptor
|
||||
|
||||
// Given a pointer to pointers (or iterator to iterators),
|
||||
// apply a double dereference inside operator*().
|
||||
//
|
||||
// We use the term "outer" to refer to the first level iterator type
|
||||
// and "inner" to refer to the second level iterator type. For
|
||||
// example, given T**, T* is the inner iterator type and T** is the
|
||||
// outer iterator type. Also, const T* would be the const inner
|
||||
// iterator.
|
||||
|
||||
// We tried to implement this with transform_iterator, but that required
|
||||
// using boost::remove_ref, which is not compiler portable.
|
||||
|
||||
struct indirect_iterator_policies : public default_iterator_policies
|
||||
{
|
||||
template <class Reference, class Iterator>
|
||||
Reference dereference(type<Reference>, const Iterator& x) const
|
||||
{ return **x; }
|
||||
};
|
||||
|
||||
template <class OuterIterator, class InnerIterator,
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class OuterTraits,
|
||||
class InnerTraits
|
||||
#else
|
||||
class OuterTraits = std::iterator_traits<OuterIterator>,
|
||||
class InnerTraits = std::iterator_traits<InnerIterator>
|
||||
#endif
|
||||
>
|
||||
struct indirect_traits
|
||||
{
|
||||
typedef typename OuterTraits::difference_type difference_type;
|
||||
typedef typename InnerTraits::value_type value_type;
|
||||
typedef typename InnerTraits::pointer pointer;
|
||||
typedef typename InnerTraits::reference reference;
|
||||
typedef typename OuterTraits::iterator_category iterator_category;
|
||||
};
|
||||
|
||||
template <class OuterIterator, // Mutable or Immutable, does not matter
|
||||
class InnerIterator, // Mutable -> mutable indirect iterator
|
||||
// Immutable -> immutable indirect iterator
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class OuterTraits,
|
||||
class InnerTraits
|
||||
#else
|
||||
class OuterTraits = std::iterator_traits<OuterIterator>,
|
||||
class InnerTraits = std::iterator_traits<InnerIterator>
|
||||
#endif
|
||||
>
|
||||
struct indirect_iterator
|
||||
{
|
||||
typedef iterator_adaptor<OuterIterator,
|
||||
indirect_iterator_policies,
|
||||
indirect_traits<OuterIterator, InnerIterator,
|
||||
OuterTraits, InnerTraits>
|
||||
> type;
|
||||
};
|
||||
|
||||
template <class OuterIterator, // Mutable or Immutable, does not matter
|
||||
class InnerIterator, // Mutable
|
||||
class ConstInnerIterator, // Immutable
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class OuterTraits,
|
||||
class InnerTraits,
|
||||
class ConstInnerTraits
|
||||
#else
|
||||
class OuterTraits = std::iterator_traits<OuterIterator>,
|
||||
class InnerTraits = std::iterator_traits<InnerIterator>,
|
||||
class ConstInnerTraits = std::iterator_traits<ConstInnerIterator>
|
||||
#endif
|
||||
>
|
||||
struct indirect_iterators
|
||||
{
|
||||
typedef iterator_adaptors<OuterIterator, OuterIterator,
|
||||
indirect_traits<OuterIterator, InnerIterator,
|
||||
OuterTraits, InnerTraits>,
|
||||
indirect_traits<OuterIterator, ConstInnerIterator,
|
||||
OuterTraits, ConstInnerTraits>,
|
||||
indirect_iterator_policies
|
||||
> Adaptors;
|
||||
typedef typename Adaptors::iterator iterator;
|
||||
typedef typename Adaptors::const_iterator const_iterator;
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// Reverse Iterators Adaptor
|
||||
|
||||
struct reverse_iterator_policies
|
||||
{
|
||||
template <class Reference, class Iterator>
|
||||
Reference dereference(type<Reference>, const Iterator& x) const
|
||||
{ return *boost::prior(x); }
|
||||
|
||||
template <class Iterator>
|
||||
void increment(Iterator& x) const
|
||||
{ --x; }
|
||||
|
||||
template <class Iterator>
|
||||
void decrement(Iterator& x) const
|
||||
{ ++x; }
|
||||
|
||||
template <class Iterator, class DifferenceType>
|
||||
void advance(Iterator& x, DifferenceType n) const
|
||||
{ x -= n; }
|
||||
|
||||
template <class Difference, class Iterator1, class Iterator2>
|
||||
Difference distance(type<Difference>, const Iterator1& x,
|
||||
const Iterator2& y) const
|
||||
{ return x - y; }
|
||||
|
||||
template <class Iterator1, class Iterator2>
|
||||
bool equal(const Iterator1& x, const Iterator2& y) const
|
||||
{ return x == y; }
|
||||
|
||||
template <class Iterator1, class Iterator2>
|
||||
bool less(const Iterator1& x, const Iterator2& y) const
|
||||
{ return y < x; }
|
||||
};
|
||||
|
||||
template <class Iterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits = std::iterator_traits<Iterator>
|
||||
#else
|
||||
class Traits
|
||||
#endif
|
||||
>
|
||||
struct reverse_iterator
|
||||
{
|
||||
typedef iterator_adaptor<Iterator, reverse_iterator_policies,
|
||||
Traits> type;
|
||||
};
|
||||
|
||||
template <class ConstIterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class ConstTraits = std::iterator_traits<ConstIterator>
|
||||
#else
|
||||
class ConstTraits
|
||||
#endif
|
||||
>
|
||||
struct const_reverse_iterator
|
||||
{
|
||||
typedef iterator_adaptor<ConstIterator, reverse_iterator_policies,
|
||||
ConstTraits> type;
|
||||
};
|
||||
|
||||
template <class Iterator, class ConstIterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits = std::iterator_traits<Iterator>,
|
||||
class ConstTraits = std::iterator_traits<ConstIterator>
|
||||
#else
|
||||
class Traits,
|
||||
class ConstTraits
|
||||
#endif
|
||||
>
|
||||
struct reverse_iterators
|
||||
{
|
||||
typedef iterator_adaptors<Iterator,ConstIterator,Traits,ConstTraits,
|
||||
reverse_iterator_policies> Adaptor;
|
||||
typedef typename Adaptor::iterator iterator;
|
||||
typedef typename Adaptor::const_iterator const_iterator;
|
||||
};
|
||||
|
||||
//=============================================================================
|
||||
// Projection Iterators Adaptor
|
||||
|
||||
template <class AdaptableUnaryFunction>
|
||||
struct projection_iterator_policies : public default_iterator_policies
|
||||
{
|
||||
projection_iterator_policies() { }
|
||||
projection_iterator_policies(const AdaptableUnaryFunction& f) : m_f(f) { }
|
||||
|
||||
template <class Reference, class Iterator>
|
||||
Reference dereference (type<Reference>, Iterator const& iter) const {
|
||||
return m_f(*iter);
|
||||
}
|
||||
|
||||
AdaptableUnaryFunction m_f;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction, class Traits>
|
||||
struct projection_iterator_traits {
|
||||
typedef typename AdaptableUnaryFunction::result_type value_type;
|
||||
typedef value_type& reference;
|
||||
typedef value_type* pointer;
|
||||
typedef typename Traits::difference_type difference_type;
|
||||
typedef typename Traits::iterator_category iterator_category;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction, class Traits>
|
||||
struct const_projection_iterator_traits {
|
||||
typedef typename AdaptableUnaryFunction::result_type value_type;
|
||||
typedef value_type const& reference;
|
||||
typedef value_type const* pointer;
|
||||
typedef typename Traits::difference_type difference_type;
|
||||
typedef typename Traits::iterator_category iterator_category;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction, class Iterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits = std::iterator_traits<Iterator>
|
||||
#else
|
||||
class Traits
|
||||
#endif
|
||||
>
|
||||
struct projection_iterator {
|
||||
typedef projection_iterator_traits<AdaptableUnaryFunction, Traits>
|
||||
Projection_Traits;
|
||||
typedef iterator_adaptor<Iterator,
|
||||
projection_iterator_policies<AdaptableUnaryFunction>,
|
||||
Projection_Traits> type;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction, class Iterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits = std::iterator_traits<Iterator>
|
||||
#else
|
||||
class Traits
|
||||
#endif
|
||||
>
|
||||
struct const_projection_iterator {
|
||||
typedef const_projection_iterator_traits<AdaptableUnaryFunction,
|
||||
Traits> Projection_Traits;
|
||||
typedef iterator_adaptor<Iterator,
|
||||
projection_iterator_policies<AdaptableUnaryFunction>,
|
||||
Projection_Traits> type;
|
||||
};
|
||||
|
||||
template <class AdaptableUnaryFunction, class Iterator, class ConstIterator,
|
||||
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
class Traits = std::iterator_traits<Iterator>,
|
||||
class ConstTraits = std::iterator_traits<ConstIterator>
|
||||
#else
|
||||
class Traits,
|
||||
class ConstTraits
|
||||
#endif
|
||||
>
|
||||
struct projection_iterators {
|
||||
typedef projection_iterator_traits<AdaptableUnaryFunction, Traits>
|
||||
Projection_Traits;
|
||||
typedef const_projection_iterator_traits<AdaptableUnaryFunction,
|
||||
ConstTraits> Const_Projection_Traits;
|
||||
typedef iterator_adaptors<Iterator, ConstIterator,
|
||||
Projection_Traits, Const_Projection_Traits,
|
||||
projection_iterator_policies<AdaptableUnaryFunction> > Adaptors;
|
||||
typedef typename Adaptors::iterator iterator;
|
||||
typedef typename Adaptors::const_iterator const_iterator;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
173
include/boost/pending/iterator_tests.hpp
Normal file
173
include/boost/pending/iterator_tests.hpp
Normal file
@ -0,0 +1,173 @@
|
||||
#ifndef BOOST_ITERATOR_TESTS_HPP
|
||||
#define BOOST_ITERATOR_TESTS_HPP
|
||||
|
||||
// This is meant to be the beginnings of a comprehensive, generic
|
||||
// test suite for STL concepts such as iterators and containers.
|
||||
|
||||
#include <iterator>
|
||||
#include <assert.h>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// use this for the value type
|
||||
struct dummyT {
|
||||
dummyT() { }
|
||||
dummyT(int x) : m_x(x) { }
|
||||
int foo() const { return m_x; }
|
||||
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
|
||||
int m_x;
|
||||
};
|
||||
|
||||
|
||||
// Tests whether type Iterator satisfies the requirements for a
|
||||
// TrivialIterator.
|
||||
// Preconditions: i != j, *i == val
|
||||
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);
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
T v = *i;
|
||||
#else
|
||||
typename std::iterator_traits<Iterator>::value_type v = *i;
|
||||
#endif
|
||||
assert(v == val);
|
||||
#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());
|
||||
#endif
|
||||
k = i;
|
||||
assert(k == k);
|
||||
assert(k == i);
|
||||
assert(k != j);
|
||||
assert(*k == val);
|
||||
}
|
||||
|
||||
|
||||
// Preconditions: i != j
|
||||
template <class Iterator, class T>
|
||||
void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val)
|
||||
{
|
||||
*i = val;
|
||||
trivial_iterator_test(i, j, val);
|
||||
}
|
||||
|
||||
|
||||
// Preconditions: *i == v1, *++i == v2
|
||||
template <class Iterator, class T>
|
||||
void input_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1++);
|
||||
assert(i != ++i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
|
||||
++i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, v2);
|
||||
}
|
||||
|
||||
// how to test output iterator?
|
||||
|
||||
template <class Iterator, class T>
|
||||
void forward_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
input_iterator_test(i, v1, v2);
|
||||
}
|
||||
|
||||
// Preconditions: *i == v1, *++i == v2
|
||||
template <class Iterator, class T>
|
||||
void bidirectional_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
input_iterator_test(i, v1, v2);
|
||||
++i;
|
||||
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1--);
|
||||
assert(i != --i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, v2);
|
||||
|
||||
--i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
--i1;
|
||||
--i2;
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
}
|
||||
|
||||
// mutable_bidirectional_iterator_test
|
||||
|
||||
// Preconditions: [i,i+N) is a valid range
|
||||
template <class Iterator, class TrueVals>
|
||||
void random_access_iterator_test(Iterator i, int N, TrueVals vals)
|
||||
{
|
||||
bidirectional_iterator_test(i, vals[0], vals[1]);
|
||||
const Iterator j = i;
|
||||
int c;
|
||||
|
||||
for (c = 0; c < N-1; ++c) {
|
||||
assert(i == j + c);
|
||||
assert(*i == vals[c]);
|
||||
assert(*i == j[c]);
|
||||
assert(*i == *(j + c));
|
||||
assert(*i == *(c + j));
|
||||
++i;
|
||||
assert(i > j);
|
||||
assert(i >= j);
|
||||
assert(j <= i);
|
||||
assert(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 == j[N - 1 - c]);
|
||||
Iterator q = k - c;
|
||||
assert(*i == *q);
|
||||
assert(i > j);
|
||||
assert(i >= j);
|
||||
assert(j <= i);
|
||||
assert(j < i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
// Precondition: i != j
|
||||
template <class Iterator, class ConstIterator>
|
||||
void const_nonconst_iterator_test(Iterator i, ConstIterator j)
|
||||
{
|
||||
assert(i != j);
|
||||
assert(j != i);
|
||||
|
||||
ConstIterator k(i);
|
||||
assert(k == i);
|
||||
assert(i == k);
|
||||
|
||||
k = i;
|
||||
assert(k == i);
|
||||
assert(i == k);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ITERATOR_TESTS_HPP
|
@ -1,836 +0,0 @@
|
||||
// (C) Copyright Dave Abrahams and Thomas Becker 2003. Permission to
|
||||
// copy, use, modify, sell and distribute this software is granted
|
||||
// provided this copyright notice appears in all copies. This software
|
||||
// is provided "as is" without express or implied warranty, and with
|
||||
// no claim as to its suitability for any purpose.
|
||||
//
|
||||
|
||||
// File:
|
||||
// =====
|
||||
// zip_iterator_test_main.cpp
|
||||
|
||||
// Author:
|
||||
// =======
|
||||
// Thomas Becker
|
||||
|
||||
// Created:
|
||||
// ========
|
||||
// Jul 15, 2003
|
||||
|
||||
// Purpose:
|
||||
// ========
|
||||
// Test driver for zip_iterator.hpp
|
||||
|
||||
// Compilers Tested:
|
||||
// =================
|
||||
// Metrowerks Codewarrior Pro 7.2, 8.3
|
||||
// gcc 2.95.3
|
||||
// gcc 3.2
|
||||
// Microsoft VC 6sp5 (test fails due to some compiler bug)
|
||||
// Microsoft VC 7 (works)
|
||||
// Microsoft VC 7.1
|
||||
// Intel 5
|
||||
// Intel 6
|
||||
// Intel 7.1
|
||||
// Intel 8
|
||||
// Borland 5.5.1 (broken due to lack of support from Boost.Tuples)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define FUSION_MAX_TUPLE_SIZE 13
|
||||
|
||||
#include <boost/iterator/zip_iterator.hpp> // 2nd #include tests #include guard.
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <functional>
|
||||
#include <boost/spirit/fusion/sequence/tuple.hpp>
|
||||
#include <boost/spirit/fusion/sequence/tuple20.hpp>
|
||||
#include <boost/spirit/fusion/sequence/make_tuple.hpp>
|
||||
#include <boost/spirit/fusion/algorithm/push_front.hpp>
|
||||
#include <boost/spirit/fusion/sequence/get.hpp>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
#include <boost/iterator/is_readable_iterator.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
template <class It>
|
||||
struct pure_traversal
|
||||
: boost::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<It>::type
|
||||
>
|
||||
{};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Das Main Funktion
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main( void )
|
||||
{
|
||||
|
||||
std::cout << "\n"
|
||||
<< "***********************************************\n"
|
||||
<< "* *\n"
|
||||
<< "* Test driver for boost::zip_iterator *\n"
|
||||
<< "* Copyright Thomas Becker 2003 *\n"
|
||||
<< "* *\n"
|
||||
<< "***********************************************\n\n"
|
||||
<< std::flush;
|
||||
|
||||
size_t num_successful_tests = 0;
|
||||
size_t num_failed_tests = 0;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator construction and dereferencing
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator construction and dereferencing: "
|
||||
<< std::flush;
|
||||
|
||||
std::vector<double> vect1(3);
|
||||
vect1[0] = 42.;
|
||||
vect1[1] = 43.;
|
||||
vect1[2] = 44.;
|
||||
|
||||
std::set<int> intset;
|
||||
intset.insert(52);
|
||||
intset.insert(53);
|
||||
intset.insert(54);
|
||||
//
|
||||
|
||||
typedef
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::set<int>::iterator
|
||||
, std::vector<double>::iterator
|
||||
>
|
||||
> zit_mixed;
|
||||
|
||||
zit_mixed zip_it_mixed = zit_mixed(
|
||||
boost::fusion::make_tuple(
|
||||
intset.begin()
|
||||
, vect1.begin()
|
||||
)
|
||||
);
|
||||
|
||||
boost::fusion::tuple<int, double> val_tuple(
|
||||
*zip_it_mixed);
|
||||
|
||||
boost::fusion::tuple<const int&, double&> ref_tuple(
|
||||
*zip_it_mixed);
|
||||
|
||||
double dblOldVal = boost::fusion::get<1>(ref_tuple);
|
||||
boost::fusion::get<1>(ref_tuple) -= 41.;
|
||||
|
||||
if( 52 == boost::fusion::get<0>(val_tuple) &&
|
||||
42. == boost::fusion::get<1>(val_tuple) &&
|
||||
52 == boost::fusion::get<0>(ref_tuple) &&
|
||||
1. == boost::fusion::get<1>(ref_tuple) &&
|
||||
1. == *vect1.begin()
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
// Undo change to vect1
|
||||
boost::fusion::get<1>(ref_tuple) = dblOldVal;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator with 12 components
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterators with 12 components: "
|
||||
<< std::flush;
|
||||
|
||||
// Declare 12 containers
|
||||
//
|
||||
std::list<int> li1;
|
||||
li1.push_back(1);
|
||||
std::set<int> se1;
|
||||
se1.insert(2);
|
||||
std::vector<int> ve1;
|
||||
ve1.push_back(3);
|
||||
//
|
||||
std::list<int> li2;
|
||||
li2.push_back(4);
|
||||
std::set<int> se2;
|
||||
se2.insert(5);
|
||||
std::vector<int> ve2;
|
||||
ve2.push_back(6);
|
||||
//
|
||||
std::list<int> li3;
|
||||
li3.push_back(7);
|
||||
std::set<int> se3;
|
||||
se3.insert(8);
|
||||
std::vector<int> ve3;
|
||||
ve3.push_back(9);
|
||||
//
|
||||
std::list<int> li4;
|
||||
li4.push_back(10);
|
||||
std::set<int> se4;
|
||||
se4.insert(11);
|
||||
std::vector<int> ve4;
|
||||
ve4.push_back(12);
|
||||
|
||||
// typedefs for cons lists of iterators.
|
||||
typedef boost::fusion::tuple11<
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::iterator,
|
||||
std::list<int>::iterator,
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::iterator,
|
||||
std::list<int>::iterator,
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::iterator,
|
||||
std::list<int>::iterator,
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::const_iterator
|
||||
> cons_11_its_type;
|
||||
|
||||
//
|
||||
typedef boost::fusion::meta::generate<
|
||||
boost::fusion::meta::push_front<
|
||||
cons_11_its_type,
|
||||
std::list<int>::const_iterator
|
||||
>::type
|
||||
>::type cons_12_its_type;
|
||||
|
||||
// typedefs for cons lists for dereferencing the zip iterator
|
||||
// made from the cons list above.
|
||||
typedef boost::fusion::tuple11<
|
||||
const int&,
|
||||
int&,
|
||||
int&,
|
||||
const int&,
|
||||
int&,
|
||||
int&,
|
||||
const int&,
|
||||
int&,
|
||||
int&,
|
||||
const int&,
|
||||
const int&
|
||||
> cons_11_refs_type;
|
||||
//
|
||||
typedef boost::fusion::meta::generate<
|
||||
boost::fusion::meta::push_front<
|
||||
cons_11_refs_type,
|
||||
const int&
|
||||
>::type
|
||||
>::type cons_12_refs_type;
|
||||
|
||||
// typedef for zip iterator with 12 elements
|
||||
typedef boost::zip_iterator<cons_12_its_type> zip_it_12_type;
|
||||
|
||||
// Declare a 12-element zip iterator.
|
||||
zip_it_12_type zip_it_12(
|
||||
cons_12_its_type(
|
||||
li1.begin(),
|
||||
se1.begin(),
|
||||
ve1.begin(),
|
||||
li2.begin(),
|
||||
se2.begin(),
|
||||
ve2.begin(),
|
||||
li3.begin(),
|
||||
se3.begin(),
|
||||
ve3.begin(),
|
||||
li4.begin(),
|
||||
se4.begin(),
|
||||
ve4.begin()
|
||||
)
|
||||
);
|
||||
|
||||
// Dereference, mess with the result a little.
|
||||
cons_12_refs_type zip_it_12_dereferenced(*zip_it_12);
|
||||
boost::fusion::get<9>(zip_it_12_dereferenced) = 42;
|
||||
|
||||
// Make a copy and move it a little to force some instantiations.
|
||||
zip_it_12_type zip_it_12_copy(zip_it_12);
|
||||
++zip_it_12_copy;
|
||||
|
||||
if( boost::fusion::get<11>(zip_it_12.get_iterator_tuple()) == ve4.begin() &&
|
||||
boost::fusion::get<11>(zip_it_12_copy.get_iterator_tuple()) == ve4.end() &&
|
||||
1 == boost::fusion::get<0>(zip_it_12_dereferenced) &&
|
||||
12 == boost::fusion::get<11>(zip_it_12_dereferenced) &&
|
||||
42 == *(li4.begin())
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator incrementing and dereferencing
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator ++ and *: "
|
||||
<< std::flush;
|
||||
|
||||
std::vector<double> vect2(3);
|
||||
vect2[0] = 2.2;
|
||||
vect2[1] = 3.3;
|
||||
vect2[2] = 4.4;
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_begin(
|
||||
boost::fusion::make_tuple(
|
||||
vect1.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_run(
|
||||
boost::fusion::make_tuple(
|
||||
vect1.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_end(
|
||||
boost::fusion::make_tuple(
|
||||
vect1.end(),
|
||||
vect2.end()
|
||||
)
|
||||
);
|
||||
|
||||
if( zip_it_run == zip_it_begin &&
|
||||
42. == boost::fusion::get<0>(*zip_it_run) &&
|
||||
2.2 == boost::fusion::get<1>(*zip_it_run) &&
|
||||
43. == boost::fusion::get<0>(*(++zip_it_run)) &&
|
||||
3.3 == boost::fusion::get<1>(*zip_it_run) &&
|
||||
44. == boost::fusion::get<0>(*(++zip_it_run)) &&
|
||||
4.4 == boost::fusion::get<1>(*zip_it_run) &&
|
||||
zip_it_end == ++zip_it_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator decrementing and dereferencing
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator -- and *: "
|
||||
<< std::flush;
|
||||
|
||||
if( zip_it_run == zip_it_end &&
|
||||
zip_it_end == zip_it_run-- &&
|
||||
44. == boost::fusion::get<0>(*zip_it_run) &&
|
||||
4.4 == boost::fusion::get<1>(*zip_it_run) &&
|
||||
43. == boost::fusion::get<0>(*(--zip_it_run)) &&
|
||||
3.3 == boost::fusion::get<1>(*zip_it_run) &&
|
||||
42. == boost::fusion::get<0>(*(--zip_it_run)) &&
|
||||
2.2 == boost::fusion::get<1>(*zip_it_run) &&
|
||||
zip_it_begin == zip_it_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator copy construction and equality
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator copy construction and equality: "
|
||||
<< std::flush;
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
> zip_it_run_copy(zip_it_run);
|
||||
|
||||
if(zip_it_run == zip_it_run && zip_it_run == zip_it_run_copy)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator inequality
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator inequality: "
|
||||
<< std::flush;
|
||||
|
||||
if(!(zip_it_run != zip_it_run_copy) && zip_it_run != ++zip_it_run_copy)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator less than
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator less than: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run_copy == zip_it_run + 1
|
||||
//
|
||||
if( zip_it_run < zip_it_run_copy &&
|
||||
!( zip_it_run < --zip_it_run_copy) &&
|
||||
zip_it_run == zip_it_run_copy
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator less than or equal
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "zip iterator less than or equal: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run_copy == zip_it_run
|
||||
//
|
||||
++zip_it_run;
|
||||
zip_it_run_copy += 2;
|
||||
|
||||
if( zip_it_run <= zip_it_run_copy &&
|
||||
zip_it_run <= --zip_it_run_copy &&
|
||||
!( zip_it_run <= --zip_it_run_copy) &&
|
||||
zip_it_run <= zip_it_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator greater than
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator greater than: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run_copy == zip_it_run - 1
|
||||
//
|
||||
if( zip_it_run > zip_it_run_copy &&
|
||||
!( zip_it_run > ++zip_it_run_copy) &&
|
||||
zip_it_run == zip_it_run_copy
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator greater than or equal
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator greater than or equal: "
|
||||
<< std::flush;
|
||||
|
||||
++zip_it_run;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy + 1
|
||||
//
|
||||
if( zip_it_run >= zip_it_run_copy &&
|
||||
--zip_it_run >= zip_it_run_copy &&
|
||||
! (zip_it_run >= ++zip_it_run_copy)
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator + int
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator + int: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy - 1
|
||||
//
|
||||
zip_it_run = zip_it_run + 2;
|
||||
++zip_it_run_copy;
|
||||
|
||||
if( zip_it_run == zip_it_run_copy && zip_it_run == zip_it_begin + 3 )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator - int
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator - int: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy, and both are at end position
|
||||
//
|
||||
zip_it_run = zip_it_run - 2;
|
||||
--zip_it_run_copy;
|
||||
--zip_it_run_copy;
|
||||
|
||||
if( zip_it_run == zip_it_run_copy && (zip_it_run - 1) == zip_it_begin )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator +=
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator +=: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy, and both are at begin + 1
|
||||
//
|
||||
zip_it_run += 2;
|
||||
if( zip_it_run == zip_it_begin + 3 )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator -=
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator -=: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run is at end position, zip_it_run_copy is at
|
||||
// begin plus one.
|
||||
//
|
||||
zip_it_run -= 2;
|
||||
if( zip_it_run == zip_it_run_copy )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator getting member iterators
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator member iterators: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run and zip_it_run_copy are both at
|
||||
// begin plus one.
|
||||
//
|
||||
if( boost::fusion::get<0>(zip_it_run.get_iterator_tuple()) == vect1.begin() + 1 &&
|
||||
boost::fusion::get<1>(zip_it_run.get_iterator_tuple()) == vect2.begin() + 1
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Making zip iterators
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Making zip iterators: "
|
||||
<< std::flush;
|
||||
|
||||
std::vector<boost::fusion::tuple<double, double> >
|
||||
vect_of_tuples(3);
|
||||
|
||||
std::copy(
|
||||
boost::make_zip_iterator(
|
||||
boost::fusion::make_tuple(
|
||||
vect1.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
),
|
||||
boost::make_zip_iterator(
|
||||
boost::fusion::make_tuple(
|
||||
vect1.end(),
|
||||
vect2.end()
|
||||
)
|
||||
),
|
||||
vect_of_tuples.begin()
|
||||
);
|
||||
|
||||
if( 42. == boost::fusion::get<0>(*vect_of_tuples.begin()) &&
|
||||
2.2 == boost::fusion::get<1>(*vect_of_tuples.begin()) &&
|
||||
43. == boost::fusion::get<0>(*(vect_of_tuples.begin() + 1)) &&
|
||||
3.3 == boost::fusion::get<1>(*(vect_of_tuples.begin() + 1)) &&
|
||||
44. == boost::fusion::get<0>(*(vect_of_tuples.begin() + 2)) &&
|
||||
4.4 == boost::fusion::get<1>(*(vect_of_tuples.begin() + 2))
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator non-const --> const conversion
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator non-const to const conversion: "
|
||||
<< std::flush;
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::set<int>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_const(
|
||||
boost::fusion::make_tuple(
|
||||
intset.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
//
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::set<int>::iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_half_const(
|
||||
boost::fusion::make_tuple(
|
||||
intset.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
//
|
||||
boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::set<int>::iterator,
|
||||
std::vector<double>::iterator
|
||||
>
|
||||
>
|
||||
zip_it_non_const(
|
||||
boost::fusion::make_tuple(
|
||||
intset.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
|
||||
zip_it_half_const = ++zip_it_non_const;
|
||||
zip_it_const = zip_it_half_const;
|
||||
++zip_it_const;
|
||||
// zip_it_non_const = ++zip_it_const; // Error: can't convert from const to non-const
|
||||
|
||||
if( 54 == boost::fusion::get<0>(*zip_it_const) &&
|
||||
4.4 == boost::fusion::get<1>(*zip_it_const) &&
|
||||
53 == boost::fusion::get<0>(*zip_it_half_const) &&
|
||||
3.3 == boost::fusion::get<1>(*zip_it_half_const)
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator categories
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator categories: "
|
||||
<< std::flush;
|
||||
|
||||
// The big iterator of the previous test has vector, list, and set iterators.
|
||||
// Therefore, it must be bidirectional, but not random access.
|
||||
bool bBigItIsBidirectionalIterator = boost::is_convertible<
|
||||
boost::iterator_traversal<zip_it_12_type>::type
|
||||
, boost::bidirectional_traversal_tag
|
||||
>::value;
|
||||
|
||||
bool bBigItIsRandomAccessIterator = boost::is_convertible<
|
||||
boost::iterator_traversal<zip_it_12_type>::type
|
||||
, boost::random_access_traversal_tag
|
||||
>::value;
|
||||
|
||||
// A combining iterator with all vector iterators must have random access
|
||||
// traversal.
|
||||
//
|
||||
typedef boost::zip_iterator<
|
||||
boost::fusion::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
> all_vects_type;
|
||||
|
||||
bool bAllVectsIsRandomAccessIterator = boost::is_convertible<
|
||||
boost::iterator_traversal<all_vects_type>::type
|
||||
, boost::random_access_traversal_tag
|
||||
>::value;
|
||||
|
||||
// The big test.
|
||||
if( bBigItIsBidirectionalIterator &&
|
||||
! bBigItIsRandomAccessIterator &&
|
||||
bAllVectsIsRandomAccessIterator
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
// Done
|
||||
//
|
||||
std::cout << "\nTest Result:"
|
||||
<< "\n============"
|
||||
<< "\nNumber of successful tests: " << static_cast<unsigned int>(num_successful_tests)
|
||||
<< "\nNumber of failed tests: " << static_cast<unsigned int>(num_failed_tests)
|
||||
<< std::endl;
|
||||
|
||||
return num_failed_tests;
|
||||
}
|
||||
|
Reference in New Issue
Block a user