diff --git a/include/boost/multi_array/base.hpp b/include/boost/multi_array/base.hpp index c3beb7e..22fd9ef 100644 --- a/include/boost/multi_array/base.hpp +++ b/include/boost/multi_array/base.hpp @@ -25,7 +25,8 @@ #include "boost/multi_array/storage_order.hpp" #include "boost/multi_array/types.hpp" #include "boost/config.hpp" -#include "boost/multi_array/iterator_adaptors.hpp" +#include "boost/mpl/if.hpp" +#include "boost/iterator/reverse_iterator.hpp" #include "boost/static_assert.hpp" #include "boost/type.hpp" #include @@ -76,27 +77,9 @@ class sub_array; template class const_sub_array; -template -struct iterator_generator; - -template -struct const_iterator_generator; - -template -struct reverse_iterator_generator; - -template -struct const_reverse_iterator_generator; - -template -struct iterator_base; - -template -struct iterator_policies; +template +class array_iterator; template class const_multi_array_view; @@ -233,19 +216,6 @@ public: ///////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////// -// multi_array/sub_array base stuffs -///////////////////////////////////////////////////////////////////////// -template -struct iterator_tag_selector { - typedef std::input_iterator_tag type; -}; - -template <> -struct iterator_tag_selector<1> { - typedef std::random_access_iterator_tag type; -}; - //////////////////////////////////////////////////////////////////////// // multi_array_base @@ -288,28 +258,25 @@ public: // iterator support // - typedef typename iterator_tag_selector::type iterator_tag; - typedef typename - iterator_generator::type iterator; + mpl::if_c<(NumDims == 1), + writable_lvalue_iterator_tag, + readable_writable_iterator_tag>::type iterator_tag; - typedef typename - const_iterator_generator::type const_iterator; + typedef typename + mpl::if_c<(NumDims == 1), + readable_lvalue_iterator_tag, + readable_iterator_tag>::type const_iterator_tag; - typedef typename - reverse_iterator_generator::type reverse_iterator; + typedef array_iterator iterator; + typedef array_iterator const_iterator; - typedef typename - const_reverse_iterator_generator::type const_reverse_iterator; + typedef ::boost::reverse_iterator reverse_iterator; + typedef ::boost::reverse_iterator const_reverse_iterator; BOOST_STATIC_CONSTANT(std::size_t, dimensionality = NumDims); protected: - typedef iterator_base iter_base; - typedef iterator_base const_iter_base; multi_array_impl_base() { } ~multi_array_impl_base() { } diff --git a/include/boost/multi_array/iterator.hpp b/include/boost/multi_array/iterator.hpp index 5cd47c9..e485759 100644 --- a/include/boost/multi_array/iterator.hpp +++ b/include/boost/multi_array/iterator.hpp @@ -20,7 +20,6 @@ #include "boost/multi_array/base.hpp" #include "boost/iterator/iterator_facade.hpp" -#include "boost/iterator/reverse_iterator.hpp" #include #include @@ -94,9 +93,9 @@ public: idx_(idx), base_(base), extents_(extents), strides_(strides), index_base_(index_base) { } - template + template array_iterator(const - array_iterator& rhs) + array_iterator& rhs) : idx_(rhs.idx_), base_(rhs.base_), extents_(rhs.extents_), strides_(rhs.strides_), index_base_(rhs.index_base_) { } @@ -149,37 +148,13 @@ public: template struct iterator_generator { - // RG: readable_writeable is temporary until later dim-based fixes - typedef array_iterator type; + typedef array_iterator type; }; template struct const_iterator_generator { - // RG: readable is temporary until later dim-based fixes - typedef array_iterator type; -}; - -template -struct reverse_iterator_generator { -private: - typedef typename iterator_generator::type iterator_type; -public: - typedef ::boost::reverse_iterator type; -}; - -template -struct const_reverse_iterator_generator { -private: - typedef typename const_iterator_generator::type iterator_type; -public: - typedef ::boost::reverse_iterator type; + typedef array_iterator type; }; diff --git a/include/boost/multi_array/iterator_adaptors.hpp b/include/boost/multi_array/iterator_adaptors.hpp deleted file mode 100644 index ec78ef1..0000000 --- a/include/boost/multi_array/iterator_adaptors.hpp +++ /dev/null @@ -1,970 +0,0 @@ -// (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. -// - -// Thes code is modified from its original form to meet the needs of -// Boost.MultiArray. - -// Revision History: - -// 27 Mar 2002 Ronald Garcia -// Forked from the main tree iterator adaptors. Necessary to -// allow iterator::operator->*() to work with multi_array iterators. -// 01 Feb 2002 Jeremy Siek -// Added more comments in default_iterator_policies. -// 08 Jan 2001 David Abrahams -// Moved concept checks into a separate class, which makes MSVC -// better at dealing with them. -// 07 Jan 2001 David Abrahams -// Choose proxy for operator->() only if the reference type is not a reference. -// Updated workarounds for __MWERKS__ == 0x2406 -// 20 Dec 2001 David Abrahams -// Adjusted is_convertible workarounds for __MWERKS__ == 0x2406 -// 03 Nov 2001 Jeremy Siek -// Changed the named template parameter interface and internal. -// 04 Oct 2001 Jeremy Siek -// Changed projection_iterator to not rely on the default reference, -// working around a limitation of detail::iterator_traits. -// 04 Oct 2001 David Abrahams -// Applied indirect_iterator patch from George A. Heintzelman -// Changed name of "bind" to "select" to avoid problems with MSVC. -// 26 Sep 2001 David Abrahams -// Added borland bug fix -// 08 Mar 2001 Jeremy Siek -// Added support for optional named template parameters. -// 19 Feb 2001 David Abrahams -// Rolled back reverse_iterator_pair_generator again, as it doesn't -// save typing on a conforming compiler. -// 18 Feb 2001 David Abrahams -// Reinstated reverse_iterator_pair_generator -// 16 Feb 2001 David Abrahams -// Add an implicit conversion operator to operator_arrow_proxy -// as CW and BCC workarounds. -// 11 Feb 2001 David Abrahams -// Switch to use of BOOST_STATIC_CONSTANT where possible -// 11 Feb 2001 Jeremy Siek -// Removed workaround for older MIPSpro compiler. The workaround -// was preventing the proper functionality of the underlying -// iterator being carried forward into the iterator adaptor. -// Also added is_bidirectional enum to avoid EDG compiler error. -// 11 Feb 2001 David Abrahams -// Borland fixes up the wazoo. It finally works! -// 10 Feb 2001 David Abrahams -// Removed traits argument from iterator_adaptor<> and switched to -// explicit trait specification for maximum ease-of-use. -// Added comments to detail::iterator_defaults<> -// Began using detail::iterator_defaults<> unconditionally for code clarity -// Changed uses of `Iterator' to `Base' where non-iterators can be used. -// -// 10 Feb 2001 David Abrahams -// Rolled in supposed Borland fixes from John Maddock, but not seeing any -// improvement yet -// Changed argument order to indirect_ generator, for convenience in the -// case of input iterators (where Reference must be a value type). -// Removed derivation of filter_iterator_policies from -// default_iterator_policies, since the iterator category is likely to be -// reduced (we don't want to allow illegal operations like decrement). -// Support for a simpler filter iterator interface. -// -// 09 Feb 2001 David Abrahams -// Improved interface to indirect_ and reverse_ iterators -// Rolled back Jeremy's new constructor for now; it was causing -// problems with counting_iterator_test -// Attempted fix for Borland -// -// 09 Feb 2001 Jeremy Siek -// Added iterator constructor to allow const adaptor -// from non-const adaptee. -// Changed make_xxx to pass iterators by-value to -// get arrays converted to pointers. -// Removed InnerIterator template parameter from -// indirect_iterator_generator. -// Rearranged parameters for make_filter_iterator -// -// 07 Feb 2001 Jeremy Siek -// Removed some const iterator adaptor generators. -// Added make_xxx_iterator() helper functions for remaining -// iterator adaptors. -// Removed some traits template parameters where they -// where no longer needed thanks to detail::iterator_traits. -// Moved some of the compile-time logic into enums for -// EDG compatibility. -// -// 07 Feb 2001 David Abrahams -// Removed iterator_adaptor_pair_generator and -// reverse_iterator_pair_generator (more such culling to come) -// Improved comments -// Changed all uses of std::iterator_traits as default arguments -// to boost::detail::iterator_traits for improved utility in -// non-generic contexts -// Fixed naming convention of non-template parameter names -// -// 06 Feb 2001 David Abrahams -// Produce operator-> proxy objects for InputIterators -// Added static assertions to do some basic concept checks -// Renamed single-type generators -> xxx_generator -// Renamed const/nonconst iterator generators -> xxx_pair_generator -// Added make_transform_iterator(iter, function) -// The existence of boost::detail::iterator_traits allowed many -// template arguments to be defaulted. Some arguments had to be -// moved to accomplish it. -// -// 04 Feb 2001 MWERKS bug workaround, concept checking for proper -// reference types (David Abrahams) - -#ifndef BOOST_ITERATOR_ADAPTOR_RG032702_HPP_ -# define BOOST_ITERATOR_ADAPTOR_RG032702_HPP_ - -# include -# include -# include -# include -# include -# include -# include -# include -# include - -// 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 { -namespace detail { -namespace multi_array { - -//============================================================================ -// 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 the member functions were defined static, but Borland - // got confused and thought they were non-const. Also, Sun C++ - // does not like static function templates. - // - // The reason some members were defined static is because there is - // not state (data members) needed by those members of the - // default_iterator_policies class. If your policies class member - // functions need to access state stored in the policies object, - // then the member functions should not be static (they can't be). - - template - void initialize(Base&) - { } - - template - typename IteratorAdaptor::reference dereference(const IteratorAdaptor& x) const - { return *x.base(); } - - template - void increment(IteratorAdaptor& x) - { ++x.base(); } - - template - void decrement(IteratorAdaptor& x) - { --x.base(); } - - template - void advance(IteratorAdaptor& x, DifferenceType n) - { x.base() += n; } - - template - typename IteratorAdaptor1::difference_type - distance(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const - { return y.base() - x.base(); } - - template - bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const - { return x.base() == y.base(); } -}; - -// putting the comparisons in a base class avoids the g++ -// ambiguous overload bug due to the relops operators - -#ifdef BOOST_RELOPS_AMBIGUITY_BUG -template -struct iterator_comparisons : Base { }; - -template -inline bool operator==(const iterator_comparisons& xb, - const iterator_comparisons& yb) -{ - const D1& x = static_cast(xb); - const D2& y = static_cast(yb); - return x.policies().equal(x, y); -} - -template -inline bool operator!=(const iterator_comparisons& xb, - const iterator_comparisons& yb) -{ - const D1& x = static_cast(xb); - const D2& y = static_cast(yb); - return !x.policies().equal(x, y); -} - -template -inline bool operator<(const iterator_comparisons& xb, - const iterator_comparisons& yb) -{ - const D1& x = static_cast(xb); - const D2& y = static_cast(yb); - return x.policies().distance(y, x) < 0; -} - -template -inline bool operator>(const iterator_comparisons& xb, - const iterator_comparisons& yb) -{ - const D1& x = static_cast(xb); - const D2& y = static_cast(yb); - return x.policies().distance(y, x) > 0; -} - -template -inline bool operator>=(const iterator_comparisons& xb, - const iterator_comparisons& yb) -{ - const D1& x = static_cast(xb); - const D2& y = static_cast(yb); - return x.policies().distance(y, x) >= 0; -} - -template -inline bool operator<=(const iterator_comparisons& xb, - const iterator_comparisons& yb) -{ - const D1& x = static_cast(xb); - const D2& y = static_cast(yb); - return x.policies().distance(y, x) <= 0; -} -#endif - -namespace detail { - - // operator->() needs special support for input iterators to strictly meet the - // standard's requirements. If *i is not a reference type, we must still - // produce a (constant) lvalue to which a pointer can be formed. We do that by - // returning an instantiation of this special proxy class template. - - template - struct operator_arrow_proxy - { - operator_arrow_proxy(const T& x) : m_value(x) {} - // RG removed const below - T* operator->() const { return &m_value; } - // This function is needed for MWCW and BCC, which won't call operator-> - // again automatically per 13.3.1.2 para 8 - - // RG - removed const below - operator T*() const { return &m_value; } - mutable T m_value; - }; - - template - inline operator_arrow_proxy - operator_arrow(const Iter& i, std::input_iterator_tag) { - // RG - THIS is the change I needed to make! - // My input iterators need to return proxy references rather than values - typedef typename Iter::reference value_t; // VC++ needs this typedef - return operator_arrow_proxy(*i); - } - - template - inline typename Iter::pointer - operator_arrow(const Iter& i, std::forward_iterator_tag) { - return &(*i); - } - - template - struct operator_arrow_result_generator - { - //RG - another important change! - typedef operator_arrow_proxy proxy; - // Borland chokes unless it's an actual enum (!) - enum { use_proxy = !boost::is_reference::value }; - - typedef typename boost::detail::if_true<(use_proxy)>::template - then< - proxy, - // else - Pointer - >::type type; - }; - -# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || defined(BOOST_NO_STD_ITERATOR_TRAITS) - - - // Select default pointer and reference types for adapted non-pointer - // iterators based on the iterator and the value_type. Poor man's partial - // specialization is in use here. - template - struct iterator_defaults_select - { - template - struct traits - { - // The assumption is that iterator_traits can deduce these types - // properly as long as the iterator is not a pointer. - typedef typename boost::detail::iterator_traits::pointer pointer; - typedef typename boost::detail::iterator_traits::reference reference; - }; - }; - - // Select default pointer and reference types for adapted pointer iterators - // given a (possibly-const) value_type. - template <> - struct iterator_defaults_select - { - template - struct traits - { - typedef Value* pointer; - typedef Value& reference; - }; - }; - - // Consolidate selection of the default pointer and reference type - template - struct iterator_defaults - { - BOOST_STATIC_CONSTANT(bool, is_ptr = boost::is_pointer::value); - - typedef typename iterator_defaults_select::template traits traits; - typedef typename traits::pointer pointer; - typedef typename traits::reference reference; - }; -# else - template - struct iterator_defaults : iterator_traits - { - // Trying to factor the common is_same expression into an enum or a - // static bool constant confused Borland. - typedef typename if_true<( - ::boost::is_same::value_type>::value - )>::template then< - typename iterator_traits::pointer, - Value* - >::type pointer; - - typedef typename if_true<( - ::boost::is_same::value_type>::value - )>::template then< - typename iterator_traits::reference, - Value& - >::type reference; - - }; -# endif - - //=========================================================================== - // Specify the defaults for iterator_adaptor's template parameters - - struct default_argument { }; - // This class template is a workaround for MSVC. - struct dummy_default_gen { - template - struct select { typedef default_argument type; }; - }; - // This class template is a workaround for MSVC. - template struct default_generator { - typedef dummy_default_gen type; - }; - - struct default_value_type { - template - struct select { - typedef typename boost::detail::iterator_traits::value_type type; - }; - }; - template <> struct default_generator - { typedef default_value_type type; }; // VC++ workaround - - struct default_difference_type { - template - struct select { - typedef typename boost::detail::iterator_traits::difference_type type; - }; - }; - template <> struct default_generator - { typedef default_difference_type type; }; // VC++ workaround - - struct default_iterator_category { - template - struct select { - typedef typename boost::detail::iterator_traits::iterator_category type; - }; - }; - template <> struct default_generator - { typedef default_iterator_category type; }; // VC++ workaround - - struct default_pointer { - template - struct select { - typedef typename Traits::value_type Value; - typedef typename boost::detail::multi_array::detail::iterator_defaults::pointer - type; - }; - }; - template <> struct default_generator - { typedef default_pointer type; }; // VC++ workaround - - struct default_reference { - template - struct select { - typedef typename Traits::value_type Value; - typedef typename boost::detail::multi_array::detail::iterator_defaults::reference - type; - }; - }; - template <> struct default_generator - { typedef default_reference type; }; // VC++ workaround - -} // namespace detail - - - //=========================================================================== - // Support for named template parameters - -struct named_template_param_base { }; - -namespace detail { - struct value_type_tag { }; - struct reference_tag { }; - struct pointer_tag { }; - struct difference_type_tag { }; - struct iterator_category_tag { }; - - // avoid using std::pair because A or B might be a reference type, and g++ - // complains about forming references to references inside std::pair - template - struct cons_type { - typedef A first_type; - typedef B second_type; - }; - -} // namespace detail - -template struct value_type_is : public named_template_param_base -{ - typedef detail::cons_type type; -}; -template struct reference_is : public named_template_param_base -{ - typedef detail::cons_type type; -}; -template struct pointer_is : public named_template_param_base -{ - typedef detail::cons_type type; -}; -template struct difference_type_is - : public named_template_param_base -{ - typedef detail::cons_type type; -}; -template struct iterator_category_is - : public named_template_param_base -{ - typedef detail::cons_type type; -}; - -namespace detail { - - struct end_of_list { }; - - // Given an associative list, find the value with the matching key. - // An associative list is a list of key-value pairs. The list is - // built out of cons_type's and is terminated by end_of_list. - -# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || defined(__BORLANDC__) - template - struct find_param; - - struct find_param_continue { - template struct select { - typedef typename AssocList::first_type Head; - typedef typename Head::first_type Key1; - typedef typename Head::second_type Value; - typedef typename if_true<(is_same::value)>::template - then::type - >::type type; - }; - }; - struct find_param_end { - template - struct select { typedef detail::default_argument type; }; - }; - template struct find_param_helper1 - { typedef find_param_continue type; }; - template <> struct find_param_helper1 - { typedef find_param_end type; }; - - template - struct find_param { - typedef typename find_param_helper1::type select1; - typedef typename select1::template select::type type; - }; -# else - template struct find_param; - - template - struct find_param { typedef default_argument type; }; - - // Found a matching Key, return the associated Value - template - struct find_param, Rest>, Key> { - typedef Value type; - }; - - // Non-matching keys, continue the search - template - struct find_param, Rest>, Key2> { - typedef typename find_param::type type; - }; -# endif - - struct make_named_arg { - template - struct select { typedef typename Value::type type; }; - }; - struct make_key_value { - template - struct select { typedef detail::cons_type type; }; - }; - - template - struct is_named_parameter - { - enum { value = is_convertible::value }; - }; - -# if defined(__MWERKS__) && __MWERKS__ <= 0x2406 // workaround for broken is_convertible implementation - template struct is_named_parameter > { enum { value = true }; }; - template struct is_named_parameter > { enum { value = true }; }; - template struct is_named_parameter > { enum { value = true }; }; - template struct is_named_parameter > { enum { value = true }; }; - template struct is_named_parameter > { enum { value = true }; }; -# endif - - template - struct make_arg { -# ifdef __BORLANDC__ - // Borland C++ doesn't like the extra indirection of is_named_parameter - typedef typename - if_true<(is_convertible::value)>:: - template then::type Make; -# else - enum { is_named = is_named_parameter::value }; - typedef typename if_true<(is_named)>::template - then::type Make; -# endif - typedef typename Make::template select::type type; - }; - - // Mechanism for resolving the default argument for a template parameter. - - template struct is_default { typedef type_traits::no_type type; }; - template <> struct is_default - { typedef type_traits::yes_type type; }; - - struct choose_default { - template - struct select { - typedef typename default_generator::type Gen; - typedef typename Gen::template select::type type; - }; - }; - struct choose_arg { - template - struct select { - typedef Arg type; - }; - }; - - template - struct choose_arg_or_default { typedef choose_arg type; }; - template <> struct choose_arg_or_default { - typedef choose_default type; - }; - - template - class resolve_default { - typedef typename choose_arg_or_default::type>::type - Selector; - public: - typedef typename Selector - ::template select::type type; - }; - - template - class iterator_adaptor_traits_gen - { - // Form an associative list out of the template parameters - // If the argument is a normal parameter (not named) then make_arg - // creates a key-value pair. If the argument is a named parameter, - // then make_arg extracts the key-value pair defined inside the - // named parameter. - typedef detail::cons_type< typename make_arg::type, - detail::cons_type::type, - detail::cons_type::type, - detail::cons_type::type, - detail::cons_type::type, - end_of_list> > > > > ArgList; - - // Search the list for particular parameters - typedef typename find_param::type Val; - typedef typename find_param::type Diff; - typedef typename find_param::type Cat; - typedef typename find_param::type Ptr; - typedef typename find_param::type Ref; - - typedef boost::iterator - Traits0; - - // Compute the defaults if necessary - typedef typename resolve_default::type - value_type; - // if getting default value type from iterator_traits, then it won't be const - typedef typename resolve_default::type difference_type; - typedef typename resolve_default::type iterator_category; - - typedef boost::iterator Traits1; - - // Compute the defaults for pointer and reference. This is done as a - // separate step because the defaults for pointer and reference depend - // on value_type. - typedef typename resolve_default::type - pointer; - typedef typename resolve_default::type - reference; - - public: - typedef boost::iterator::type, - difference_type, pointer, reference> type; - }; - - // This is really a partial concept check for iterators. Should it - // be moved or done differently? - template - struct validator - { - BOOST_STATIC_CONSTANT( - bool, is_input_or_output_iter - = (boost::is_convertible::value - | boost::is_convertible::value)); - - // Iterators should satisfy one of the known categories - BOOST_STATIC_ASSERT(is_input_or_output_iter); - - // Iterators >= ForwardIterator must produce real references - // as required by the C++ standard requirements in Table 74. - BOOST_STATIC_CONSTANT( - bool, forward_iter_with_real_reference - = ((!boost::is_convertible::value) - | boost::is_same::value - | boost::is_same::type&>::value)); - - BOOST_STATIC_ASSERT(forward_iter_with_real_reference); - }; -} // namespace detail - - - -// This macro definition is only temporary in this file -# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 -# define BOOST_ARG_DEPENDENT_TYPENAME typename -# else -# define BOOST_ARG_DEPENDENT_TYPENAME -# endif - -//============================================================================ -//iterator_adaptor - Adapts a generic piece of data as an iterator. Adaptation -// is especially easy if the data being adapted is itself an iterator -// -// Base - the base (usually iterator) type being wrapped. -// -// Policies - a set of policies determining how the resulting iterator -// works. -// -// Value - if supplied, the value_type of the resulting iterator, unless -// const. If const, a conforming compiler strips constness for the -// value_type. If not supplied, iterator_traits::value_type is used -// -// Reference - the reference type of the resulting iterator, and in -// particular, the result type of operator*(). If not supplied but -// Value is supplied, Value& is used. Otherwise -// iterator_traits::reference is used. -// -// Pointer - the pointer type of the resulting iterator, and in -// particular, the result type of operator->(). If not -// supplied but Value is supplied, Value* is used. Otherwise -// iterator_traits::pointer is used. -// -// Category - the iterator_category of the resulting iterator. If not -// supplied, iterator_traits::iterator_category is used. -// -// Distance - the difference_type of the resulting iterator. If not -// supplied, iterator_traits::difference_type is used. -template -struct iterator_adaptor : -#ifdef BOOST_RELOPS_AMBIGUITY_BUG - iterator_comparisons< - iterator_adaptor, - typename detail::iterator_adaptor_traits_gen::type - > -#else - detail::iterator_adaptor_traits_gen::type -#endif -{ - typedef iterator_adaptor self; - public: - typedef detail::iterator_adaptor_traits_gen TraitsGen; - typedef typename TraitsGen::type Traits; - - 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 Base base_type; - typedef Policies policies_type; - - private: - typedef detail::validator< - iterator_category,value_type,difference_type,pointer,reference - > concept_check; - - public: - iterator_adaptor() - { - } - - explicit - iterator_adaptor(const Base& it, const Policies& p = Policies()) - : m_iter_p(it, p) { - policies().initialize(base()); - } - - template - iterator_adaptor ( - const iterator_adaptor& src) - : m_iter_p(src.base(), src.policies()) - { - policies().initialize(base()); - } - -#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__BORLANDC__) - // This is required to prevent a bug in how VC++ generates - // the assignment operator for compressed_pair - iterator_adaptor& operator= (const iterator_adaptor& x) { - m_iter_p = x.m_iter_p; - return *this; - } -#endif - reference operator*() const { - return policies().dereference(*this); - } - -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning( disable : 4284 ) -#endif - - typename boost::detail::multi_array::detail::operator_arrow_result_generator::type - operator->() const - { return detail::operator_arrow(*this, iterator_category()); } - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - - value_type operator[](difference_type n) const - { return *(*this + n); } - - self& operator++() { -#if !defined(__MWERKS__) || __MWERKS__ >= 0x2405 - policies().increment(*this); -#else - // Odd bug, MWERKS couldn't deduce the type for the member template - // Workaround by explicitly specifying the type. - policies().increment(*this); -#endif - return *this; - } - - self operator++(int) { self tmp(*this); ++*this; return tmp; } - - self& operator--() { -#if !defined(__MWERKS__) || __MWERKS__ >= 0x2405 - policies().decrement(*this); -#else - policies().decrement(*this); -#endif - return *this; - } - - self operator--(int) { self tmp(*this); --*this; return tmp; } - - self& operator+=(difference_type n) { - policies().advance(*this, n); - return *this; - } - - self& operator-=(difference_type n) { - policies().advance(*this, -n); - return *this; - } - - base_type const& base() const { return m_iter_p.first(); } - - // Moved from global scope to avoid ambiguity with the operator-() which - // subtracts iterators from one another. - self operator-(difference_type x) const - { self result(*this); return result -= x; } -private: - compressed_pair m_iter_p; - -public: // implementation details (too many compilers have trouble when these are private). - base_type& base() { return m_iter_p.first(); } - Policies& policies() { return m_iter_p.second(); } - const Policies& policies() const { return m_iter_p.second(); } -}; - -template -iterator_adaptor -operator+( - iterator_adaptor p, - Distance2 x) -{ - return p += x; -} - -template -iterator_adaptor -operator+( - Distance2 x, - iterator_adaptor p) -{ - return p += x; -} - -template -typename iterator_adaptor::difference_type -operator-( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - typedef typename iterator_adaptor::difference_type difference_type; - return x.policies().distance(y, x); -} - -#ifndef BOOST_RELOPS_AMBIGUITY_BUG -template -inline bool -operator==( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - return x.policies().equal(x, y); -} - -template -inline bool -operator<( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - return x.policies().distance(y, x) < 0; -} - -template -inline bool -operator>( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - return x.policies().distance(y, x) > 0; -} - -template -inline bool -operator>=( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - return x.policies().distance(y, x) >= 0; -} - -template -inline bool -operator<=( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - return x.policies().distance(y, x) <= 0; -} - -template -inline bool -operator!=( - const iterator_adaptor& x, - const iterator_adaptor& y) -{ - return !x.policies().equal(x, y); -} -#endif - - -} // namespace multi_array -} // namespace detail -} // namespace boost -# undef BOOST_ARG_DEPENDENT_TYPENAME - - -#endif - - -