123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878 |
- #ifndef BOOST_ITERATOR_FACADE_23022003THW_HPP
- #define BOOST_ITERATOR_FACADE_23022003THW_HPP
- #include <boost/iterator.hpp>
- #include <boost/iterator/interoperable.hpp>
- #include <boost/iterator/iterator_traits.hpp>
- #include <boost/iterator/detail/facade_iterator_category.hpp>
- #include <boost/iterator/detail/enable_if.hpp>
- #include <boost/implicit_cast.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/type_traits/add_const.hpp>
- #include <boost/type_traits/add_pointer.hpp>
- #include <boost/type_traits/remove_const.hpp>
- #include <boost/type_traits/remove_reference.hpp>
- #include <boost/type_traits/is_convertible.hpp>
- #include <boost/type_traits/is_pod.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/mpl/or.hpp>
- #include <boost/mpl/and.hpp>
- #include <boost/mpl/not.hpp>
- #include <boost/mpl/always.hpp>
- #include <boost/mpl/apply.hpp>
- #include <boost/mpl/identity.hpp>
- #include <boost/iterator/detail/config_def.hpp> // this goes last
- namespace boost
- {
-
-
- template <class I, class V, class TC, class R, class D> class iterator_facade;
- namespace detail
- {
-
-
-
- struct always_bool2
- {
- template <class T, class U>
- struct apply
- {
- typedef bool type;
- };
- };
-
-
-
- template <
- class Facade1
- , class Facade2
- , class Return
- >
- struct enable_if_interoperable
- #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
- {
- typedef typename mpl::if_<
- mpl::or_<
- is_convertible<Facade1, Facade2>
- , is_convertible<Facade2, Facade1>
- >
- , Return
- , int[3]
- >::type type;
- };
- #else
- : ::boost::iterators::enable_if<
- mpl::or_<
- is_convertible<Facade1, Facade2>
- , is_convertible<Facade2, Facade1>
- >
- , Return
- >
- {};
- #endif
-
-
-
-
- template <
- class ValueParam
- , class CategoryOrTraversal
- , class Reference
- , class Difference
- >
- struct iterator_facade_types
- {
- typedef typename facade_iterator_category<
- CategoryOrTraversal, ValueParam, Reference
- >::type iterator_category;
-
- typedef typename remove_const<ValueParam>::type value_type;
-
- typedef typename mpl::eval_if<
- boost::detail::iterator_writability_disabled<ValueParam,Reference>
- , add_pointer<const value_type>
- , add_pointer<value_type>
- >::type pointer;
-
- # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
- && (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \
- || BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, BOOST_TESTED_AT(310))) \
- || BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)) \
- || BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 310)
-
-
-
-
- # define BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE 1
- typedef
- iterator<iterator_category, value_type, Difference, pointer, Reference>
- base;
- # endif
- };
-
-
-
-
-
-
- template <class Iterator>
- class postfix_increment_proxy
- {
- typedef typename iterator_value<Iterator>::type value_type;
- public:
- explicit postfix_increment_proxy(Iterator const& x)
- : stored_value(*x)
- {}
-
-
-
-
- value_type&
- operator*() const
- {
- return this->stored_value;
- }
- private:
- mutable value_type stored_value;
- };
-
-
-
-
-
- template <class Iterator>
- class writable_postfix_increment_proxy
- {
- typedef typename iterator_value<Iterator>::type value_type;
- public:
- explicit writable_postfix_increment_proxy(Iterator const& x)
- : stored_value(*x)
- , stored_iterator(x)
- {}
-
-
-
-
- writable_postfix_increment_proxy const&
- operator*() const
- {
- return *this;
- }
-
- operator value_type&() const
- {
- return stored_value;
- }
-
- template <class T>
- T const& operator=(T const& x) const
- {
- *this->stored_iterator = x;
- return x;
- }
-
- template <class T>
- T& operator=(T& x) const
- {
- *this->stored_iterator = x;
- return x;
- }
-
- operator Iterator const&() const
- {
- return stored_iterator;
- }
-
- private:
- mutable value_type stored_value;
- Iterator stored_iterator;
- };
- # ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- template <class Reference, class Value>
- struct is_non_proxy_reference_impl
- {
- static Reference r;
-
- template <class R>
- static typename mpl::if_<
- is_convertible<
- R const volatile*
- , Value const volatile*
- >
- , char[1]
- , char[2]
- >::type& helper(R const&);
-
- BOOST_STATIC_CONSTANT(bool, value = sizeof(helper(r)) == 1);
- };
-
- template <class Reference, class Value>
- struct is_non_proxy_reference
- : mpl::bool_<
- is_non_proxy_reference_impl<Reference, Value>::value
- >
- {};
- # else
- template <class Reference, class Value>
- struct is_non_proxy_reference
- : is_convertible<
- typename remove_reference<Reference>::type
- const volatile*
- , Value const volatile*
- >
- {};
- # endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class Iterator, class Value, class Reference, class CategoryOrTraversal>
- struct postfix_increment_result
- : mpl::eval_if<
- mpl::and_<
-
- is_convertible<Reference,Value const&>
-
-
-
- , mpl::not_<
- is_convertible<
- typename iterator_category_to_traversal<CategoryOrTraversal>::type
- , forward_traversal_tag
- >
- >
- >
- , mpl::if_<
- is_non_proxy_reference<Reference,Value>
- , postfix_increment_proxy<Iterator>
- , writable_postfix_increment_proxy<Iterator>
- >
- , mpl::identity<Iterator>
- >
- {};
-
-
-
-
- template <class T>
- struct operator_arrow_proxy
- {
- operator_arrow_proxy(T const* px) : m_value(*px) {}
- T* operator->() const { return &m_value; }
-
-
- operator T*() const { return &m_value; }
- mutable T m_value;
- };
-
-
-
- template <class ValueType, class Reference, class Pointer>
- struct operator_arrow_result
- {
-
-
-
- typedef typename mpl::if_<
- is_reference<Reference>
- , Pointer
- , operator_arrow_proxy<ValueType>
- >::type type;
- static type make(Reference x)
- {
- return implicit_cast<type>(&x);
- }
- };
- # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- // Deal with ETI
- template<>
- struct operator_arrow_result<int, int, int>
- {
- typedef int type;
- };
- # endif
-
-
-
- template <class Iterator>
- class operator_brackets_proxy
- {
-
-
- typedef typename Iterator::reference reference;
- typedef typename Iterator::value_type value_type;
- public:
- operator_brackets_proxy(Iterator const& iter)
- : m_iter(iter)
- {}
- operator reference() const
- {
- return *m_iter;
- }
- operator_brackets_proxy& operator=(value_type const& val)
- {
- *m_iter = val;
- return *this;
- }
- private:
- Iterator m_iter;
- };
-
-
- template <class ValueType, class Reference>
- struct use_operator_brackets_proxy
- : mpl::not_<
- mpl::and_<
-
-
- boost::is_POD<ValueType>
- , iterator_writability_disabled<ValueType,Reference>
- >
- >
- {};
-
- template <class Iterator, class Value, class Reference>
- struct operator_brackets_result
- {
- typedef typename mpl::if_<
- use_operator_brackets_proxy<Value,Reference>
- , operator_brackets_proxy<Iterator>
- , Value
- >::type type;
- };
- template <class Iterator>
- operator_brackets_proxy<Iterator> make_operator_brackets_result(Iterator const& iter, mpl::true_)
- {
- return operator_brackets_proxy<Iterator>(iter);
- }
- template <class Iterator>
- typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::false_)
- {
- return *iter;
- }
- struct choose_difference_type
- {
- template <class I1, class I2>
- struct apply
- :
- # ifdef BOOST_NO_ONE_WAY_ITERATOR_INTEROP
- iterator_difference<I1>
- # elif BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- mpl::if_<
- is_convertible<I2,I1>
- , typename I1::difference_type
- , typename I2::difference_type
- >
- # else
- mpl::eval_if<
- is_convertible<I2,I1>
- , iterator_difference<I1>
- , iterator_difference<I2>
- >
- # endif
- {};
- };
- }
-
- # ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
- # define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
- template < \
- class Derived1, class V1, class TC1, class Reference1, class Difference1 \
- , class Derived2, class V2, class TC2, class Reference2, class Difference2 \
- > \
- prefix typename mpl::apply2<result_type,Derived1,Derived2>::type \
- operator op( \
- iterator_facade<Derived1, V1, TC1, Reference1, Difference1> const& lhs \
- , iterator_facade<Derived2, V2, TC2, Reference2, Difference2> const& rhs)
- # else
- # define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
- template < \
- class Derived1, class V1, class TC1, class Reference1, class Difference1 \
- , class Derived2, class V2, class TC2, class Reference2, class Difference2 \
- > \
- prefix typename boost::detail::enable_if_interoperable< \
- Derived1, Derived2 \
- , typename mpl::apply2<result_type,Derived1,Derived2>::type \
- >::type \
- operator op( \
- iterator_facade<Derived1, V1, TC1, Reference1, Difference1> const& lhs \
- , iterator_facade<Derived2, V2, TC2, Reference2, Difference2> const& rhs)
- # endif
- # define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \
- template <class Derived, class V, class TC, class R, class D> \
- prefix Derived operator+ args
-
-
-
-
-
-
-
-
-
- class iterator_core_access
- {
- # if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
-
-
- public:
- # else
-
- template <class I, class V, class TC, class R, class D> friend class iterator_facade;
- # define BOOST_ITERATOR_FACADE_RELATION(op) \
- BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, boost::detail::always_bool2);
- BOOST_ITERATOR_FACADE_RELATION(==)
- BOOST_ITERATOR_FACADE_RELATION(!=)
- BOOST_ITERATOR_FACADE_RELATION(<)
- BOOST_ITERATOR_FACADE_RELATION(>)
- BOOST_ITERATOR_FACADE_RELATION(<=)
- BOOST_ITERATOR_FACADE_RELATION(>=)
- # undef BOOST_ITERATOR_FACADE_RELATION
- BOOST_ITERATOR_FACADE_INTEROP_HEAD(
- friend, -, boost::detail::choose_difference_type)
- ;
- BOOST_ITERATOR_FACADE_PLUS_HEAD(
- friend inline
- , (iterator_facade<Derived, V, TC, R, D> const&
- , typename Derived::difference_type)
- )
- ;
- BOOST_ITERATOR_FACADE_PLUS_HEAD(
- friend inline
- , (typename Derived::difference_type
- , iterator_facade<Derived, V, TC, R, D> const&)
- )
- ;
- # endif
- template <class Facade>
- static typename Facade::reference dereference(Facade const& f)
- {
- return f.dereference();
- }
- template <class Facade>
- static void increment(Facade& f)
- {
- f.increment();
- }
- template <class Facade>
- static void decrement(Facade& f)
- {
- f.decrement();
- }
- template <class Facade1, class Facade2>
- static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::true_)
- {
- return f1.equal(f2);
- }
- template <class Facade1, class Facade2>
- static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::false_)
- {
- return f2.equal(f1);
- }
- template <class Facade>
- static void advance(Facade& f, typename Facade::difference_type n)
- {
- f.advance(n);
- }
- template <class Facade1, class Facade2>
- static typename Facade1::difference_type distance_from(
- Facade1 const& f1, Facade2 const& f2, mpl::true_)
- {
- return -f1.distance_to(f2);
- }
- template <class Facade1, class Facade2>
- static typename Facade2::difference_type distance_from(
- Facade1 const& f1, Facade2 const& f2, mpl::false_)
- {
- return f2.distance_to(f1);
- }
-
-
-
- template <class I, class V, class TC, class R, class D>
- static I& derived(iterator_facade<I,V,TC,R,D>& facade)
- {
- return *static_cast<I*>(&facade);
- }
- template <class I, class V, class TC, class R, class D>
- static I const& derived(iterator_facade<I,V,TC,R,D> const& facade)
- {
- return *static_cast<I const*>(&facade);
- }
- private:
-
- iterator_core_access();
- };
-
-
-
-
- template <
- class Derived
- , class Value
- , class CategoryOrTraversal
- , class Reference = Value&
- , class Difference = std::ptrdiff_t
- >
- class iterator_facade
- # ifdef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
- : public boost::detail::iterator_facade_types<
- Value, CategoryOrTraversal, Reference, Difference
- >::base
- # undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
- # endif
- {
- private:
-
-
-
- Derived& derived()
- {
- return *static_cast<Derived*>(this);
- }
- Derived const& derived() const
- {
- return *static_cast<Derived const*>(this);
- }
- typedef boost::detail::iterator_facade_types<
- Value, CategoryOrTraversal, Reference, Difference
- > associated_types;
- protected:
-
- typedef iterator_facade<Derived,Value,CategoryOrTraversal,Reference,Difference> iterator_facade_;
-
- public:
- typedef typename associated_types::value_type value_type;
- typedef Reference reference;
- typedef Difference difference_type;
- typedef typename associated_types::pointer pointer;
- typedef typename associated_types::iterator_category iterator_category;
- reference operator*() const
- {
- return iterator_core_access::dereference(this->derived());
- }
- typename boost::detail::operator_arrow_result<
- value_type
- , reference
- , pointer
- >::type
- operator->() const
- {
- return boost::detail::operator_arrow_result<
- value_type
- , reference
- , pointer
- >::make(*this->derived());
- }
-
- typename boost::detail::operator_brackets_result<Derived,Value,reference>::type
- operator[](difference_type n) const
- {
- typedef boost::detail::use_operator_brackets_proxy<Value,Reference> use_proxy;
-
- return boost::detail::make_operator_brackets_result<Derived>(
- this->derived() + n
- , use_proxy()
- );
- }
- Derived& operator++()
- {
- iterator_core_access::increment(this->derived());
- return this->derived();
- }
- # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- typename boost::detail::postfix_increment_result<Derived,Value,Reference,CategoryOrTraversal>::type
- operator++(int)
- {
- typename boost::detail::postfix_increment_result<Derived,Value,Reference,CategoryOrTraversal>::type
- tmp(this->derived());
- ++*this;
- return tmp;
- }
- # endif
-
- Derived& operator--()
- {
- iterator_core_access::decrement(this->derived());
- return this->derived();
- }
- Derived operator--(int)
- {
- Derived tmp(this->derived());
- --*this;
- return tmp;
- }
- Derived& operator+=(difference_type n)
- {
- iterator_core_access::advance(this->derived(), n);
- return this->derived();
- }
- Derived& operator-=(difference_type n)
- {
- iterator_core_access::advance(this->derived(), -n);
- return this->derived();
- }
- Derived operator-(difference_type x) const
- {
- Derived result(this->derived());
- return result -= x;
- }
- # if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- // There appears to be a bug which trashes the data of classes
- // derived from iterator_facade when they are assigned unless we
- // define this assignment operator. This bug is only revealed
- // (so far) in STLPort debug mode, but it's clearly a codegen
- // problem so we apply the workaround for all MSVC6.
- iterator_facade& operator=(iterator_facade const&)
- {
- return *this;
- }
- # endif
- };
- # if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- template <class I, class V, class TC, class R, class D>
- inline typename boost::detail::postfix_increment_result<I,V,R,TC>::type
- operator++(
- iterator_facade<I,V,TC,R,D>& i
- , int
- )
- {
- typename boost::detail::postfix_increment_result<I,V,R,TC>::type
- tmp(*static_cast<I*>(&i));
-
- ++i;
-
- return tmp;
- }
- # endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # ifdef BOOST_NO_ONE_WAY_ITERATOR_INTEROP
- # define BOOST_ITERATOR_CONVERTIBLE(a,b) mpl::true_()
- # else
- # define BOOST_ITERATOR_CONVERTIBLE(a,b) is_convertible<a,b>()
- # endif
- # define BOOST_ITERATOR_FACADE_INTEROP(op, result_type, return_prefix, base_op) \
- BOOST_ITERATOR_FACADE_INTEROP_HEAD(inline, op, result_type) \
- { \
- \
- BOOST_STATIC_ASSERT(( \
- is_interoperable< Derived1, Derived2 >::value \
- )); \
- return_prefix iterator_core_access::base_op( \
- *static_cast<Derived1 const*>(&lhs) \
- , *static_cast<Derived2 const*>(&rhs) \
- , BOOST_ITERATOR_CONVERTIBLE(Derived2,Derived1) \
- ); \
- }
- # define BOOST_ITERATOR_FACADE_RELATION(op, return_prefix, base_op) \
- BOOST_ITERATOR_FACADE_INTEROP( \
- op \
- , boost::detail::always_bool2 \
- , return_prefix \
- , base_op \
- )
- BOOST_ITERATOR_FACADE_RELATION(==, return, equal)
- BOOST_ITERATOR_FACADE_RELATION(!=, return !, equal)
- BOOST_ITERATOR_FACADE_RELATION(<, return 0 >, distance_from)
- BOOST_ITERATOR_FACADE_RELATION(>, return 0 <, distance_from)
- BOOST_ITERATOR_FACADE_RELATION(<=, return 0 >=, distance_from)
- BOOST_ITERATOR_FACADE_RELATION(>=, return 0 <=, distance_from)
- # undef BOOST_ITERATOR_FACADE_RELATION
-
- BOOST_ITERATOR_FACADE_INTEROP(
- -
- , boost::detail::choose_difference_type
- , return
- , distance_from
- )
- # undef BOOST_ITERATOR_FACADE_INTEROP
- # undef BOOST_ITERATOR_FACADE_INTEROP_HEAD
- # define BOOST_ITERATOR_FACADE_PLUS(args) \
- BOOST_ITERATOR_FACADE_PLUS_HEAD(inline, args) \
- { \
- Derived tmp(static_cast<Derived const&>(i)); \
- return tmp += n; \
- }
- BOOST_ITERATOR_FACADE_PLUS((
- iterator_facade<Derived, V, TC, R, D> const& i
- , typename Derived::difference_type n
- ))
- BOOST_ITERATOR_FACADE_PLUS((
- typename Derived::difference_type n
- , iterator_facade<Derived, V, TC, R, D> const& i
- ))
- # undef BOOST_ITERATOR_FACADE_PLUS
- # undef BOOST_ITERATOR_FACADE_PLUS_HEAD
- }
- #include <boost/iterator/detail/config_undef.hpp>
- #endif // BOOST_ITERATOR_FACADE_23022003THW_HPP
|