1 // (C) Copyright David Abrahams 2000. Permission to copy, use,
2 // modify, sell and distribute this software is granted provided this
3 // copyright notice appears in all copies. This software is provided
4 // "as is" without express or implied warranty, and with no claim as
5 // to its suitability for any purpose.
7 // (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
8 // sell and distribute this software is granted provided this
9 // copyright notice appears in all copies. This software is provided
10 // "as is" without express or implied warranty, and with no claim as
11 // to its suitability for any purpose.
15 // 27 Mar 2002 Ronald Garcia
16 // Forked from the main tree iterator adaptors. Necessary to
17 // allow iterator::operator->*() to work with multi_array iterators.
18 // 01 Feb 2002 Jeremy Siek
19 // Added more comments in default_iterator_policies.
20 // 08 Jan 2001 David Abrahams
21 // Moved concept checks into a separate class, which makes MSVC
22 // better at dealing with them.
23 // 07 Jan 2001 David Abrahams
24 // Choose proxy for operator->() only if the reference type is not a reference.
25 // Updated workarounds for __MWERKS__ == 0x2406
26 // 20 Dec 2001 David Abrahams
27 // Adjusted is_convertible workarounds for __MWERKS__ == 0x2406
28 // 03 Nov 2001 Jeremy Siek
29 // Changed the named template parameter interface and internal.
30 // 04 Oct 2001 Jeremy Siek
31 // Changed projection_iterator to not rely on the default reference,
32 // working around a limitation of detail::iterator_traits.
33 // 04 Oct 2001 David Abrahams
34 // Applied indirect_iterator patch from George A. Heintzelman <georgeh@aya.yale.edu>
35 // Changed name of "bind" to "select" to avoid problems with MSVC.
36 // 26 Sep 2001 David Abrahams
37 // Added borland bug fix
38 // 08 Mar 2001 Jeremy Siek
39 // Added support for optional named template parameters.
40 // 19 Feb 2001 David Abrahams
41 // Rolled back reverse_iterator_pair_generator again, as it doesn't
42 // save typing on a conforming compiler.
43 // 18 Feb 2001 David Abrahams
44 // Reinstated reverse_iterator_pair_generator
45 // 16 Feb 2001 David Abrahams
46 // Add an implicit conversion operator to operator_arrow_proxy
47 // as CW and BCC workarounds.
48 // 11 Feb 2001 David Abrahams
49 // Switch to use of BOOST_STATIC_CONSTANT where possible
50 // 11 Feb 2001 Jeremy Siek
51 // Removed workaround for older MIPSpro compiler. The workaround
52 // was preventing the proper functionality of the underlying
53 // iterator being carried forward into the iterator adaptor.
54 // Also added is_bidirectional enum to avoid EDG compiler error.
55 // 11 Feb 2001 David Abrahams
56 // Borland fixes up the wazoo. It finally works!
57 // 10 Feb 2001 David Abrahams
58 // Removed traits argument from iterator_adaptor<> and switched to
59 // explicit trait specification for maximum ease-of-use.
60 // Added comments to detail::iterator_defaults<>
61 // Began using detail::iterator_defaults<> unconditionally for code clarity
62 // Changed uses of `Iterator' to `Base' where non-iterators can be used.
64 // 10 Feb 2001 David Abrahams
65 // Rolled in supposed Borland fixes from John Maddock, but not seeing any
67 // Changed argument order to indirect_ generator, for convenience in the
68 // case of input iterators (where Reference must be a value type).
69 // Removed derivation of filter_iterator_policies from
70 // default_iterator_policies, since the iterator category is likely to be
71 // reduced (we don't want to allow illegal operations like decrement).
72 // Support for a simpler filter iterator interface.
74 // 09 Feb 2001 David Abrahams
75 // Improved interface to indirect_ and reverse_ iterators
76 // Rolled back Jeremy's new constructor for now; it was causing
77 // problems with counting_iterator_test
78 // Attempted fix for Borland
80 // 09 Feb 2001 Jeremy Siek
81 // Added iterator constructor to allow const adaptor
82 // from non-const adaptee.
83 // Changed make_xxx to pass iterators by-value to
84 // get arrays converted to pointers.
85 // Removed InnerIterator template parameter from
86 // indirect_iterator_generator.
87 // Rearranged parameters for make_filter_iterator
89 // 07 Feb 2001 Jeremy Siek
90 // Removed some const iterator adaptor generators.
91 // Added make_xxx_iterator() helper functions for remaining
93 // Removed some traits template parameters where they
94 // where no longer needed thanks to detail::iterator_traits.
95 // Moved some of the compile-time logic into enums for
98 // 07 Feb 2001 David Abrahams
99 // Removed iterator_adaptor_pair_generator and
100 // reverse_iterator_pair_generator (more such culling to come)
102 // Changed all uses of std::iterator_traits as default arguments
103 // to boost::detail::iterator_traits for improved utility in
104 // non-generic contexts
105 // Fixed naming convention of non-template parameter names
107 // 06 Feb 2001 David Abrahams
108 // Produce operator-> proxy objects for InputIterators
109 // Added static assertions to do some basic concept checks
110 // Renamed single-type generators -> xxx_generator
111 // Renamed const/nonconst iterator generators -> xxx_pair_generator
112 // Added make_transform_iterator(iter, function)
113 // The existence of boost::detail::iterator_traits allowed many
114 // template arguments to be defaulted. Some arguments had to be
115 // moved to accomplish it.
117 // 04 Feb 2001 MWERKS bug workaround, concept checking for proper
118 // reference types (David Abrahams)
120 #ifndef BOOST_ITERATOR_ADAPTOR_RG032702_HPP_
121 # define BOOST_ITERATOR_ADAPTOR_RG032702_HPP_
123 # include <boost/iterator.hpp>
124 # include <boost/utility.hpp>
125 # include <boost/compressed_pair.hpp>
126 # include <boost/concept_check.hpp>
127 # include <boost/type.hpp>
128 # include <boost/static_assert.hpp>
129 # include <boost/type_traits.hpp>
130 # include <boost/detail/iterator.hpp>
131 # include <boost/detail/select_type.hpp>
133 // I was having some problems with VC6. I couldn't tell whether our hack for
134 // stock GCC was causing problems so I needed an easy way to turn it on and
135 // off. Now we can test the hack with various compilers and still have an
136 // "out" if it doesn't work. -dwa 7/31/00
137 # if __GNUC__ == 2 && __GNUC_MINOR__ <= 96 && !defined(__STL_USE_NAMESPACES)
138 # define BOOST_RELOPS_AMBIGUITY_BUG 1
143 namespace multi_array {
145 //============================================================================
146 // Default policies for iterator adaptors. You can use this as a base
147 // class if you want to customize particular policies.
148 struct default_iterator_policies
150 // Some of the member functions were defined static, but Borland
151 // got confused and thought they were non-const. Also, Sun C++
152 // does not like static function templates.
154 // The reason some members were defined static is because there is
155 // not state (data members) needed by those members of the
156 // default_iterator_policies class. If your policies class member
157 // functions need to access state stored in the policies object,
158 // then the member functions should not be static (they can't be).
160 template <class Base>
161 void initialize(Base&)
164 template <class IteratorAdaptor>
165 typename IteratorAdaptor::reference dereference(const IteratorAdaptor& x) const
166 { return *x.base(); }
168 template <class IteratorAdaptor>
169 void increment(IteratorAdaptor& x)
172 template <class IteratorAdaptor>
173 void decrement(IteratorAdaptor& x)
176 template <class IteratorAdaptor, class DifferenceType>
177 void advance(IteratorAdaptor& x, DifferenceType n)
180 template <class IteratorAdaptor1, class IteratorAdaptor2>
181 typename IteratorAdaptor1::difference_type
182 distance(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
183 { return y.base() - x.base(); }
185 template <class IteratorAdaptor1, class IteratorAdaptor2>
186 bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
187 { return x.base() == y.base(); }
190 // putting the comparisons in a base class avoids the g++
191 // ambiguous overload bug due to the relops operators
193 #ifdef BOOST_RELOPS_AMBIGUITY_BUG
194 template <class Derived, class Base>
195 struct iterator_comparisons : Base { };
197 template <class D1, class D2, class Base1, class Base2>
198 inline bool operator==(const iterator_comparisons<D1,Base1>& xb,
199 const iterator_comparisons<D2,Base2>& yb)
201 const D1& x = static_cast<const D1&>(xb);
202 const D2& y = static_cast<const D2&>(yb);
203 return x.policies().equal(x, y);
206 template <class D1, class D2, class Base1, class Base2>
207 inline bool operator!=(const iterator_comparisons<D1,Base1>& xb,
208 const iterator_comparisons<D2,Base2>& yb)
210 const D1& x = static_cast<const D1&>(xb);
211 const D2& y = static_cast<const D2&>(yb);
212 return !x.policies().equal(x, y);
215 template <class D1, class D2, class Base1, class Base2>
216 inline bool operator<(const iterator_comparisons<D1,Base1>& xb,
217 const iterator_comparisons<D2,Base2>& yb)
219 const D1& x = static_cast<const D1&>(xb);
220 const D2& y = static_cast<const D2&>(yb);
221 return x.policies().distance(y, x) < 0;
224 template <class D1, class D2, class Base1, class Base2>
225 inline bool operator>(const iterator_comparisons<D1,Base1>& xb,
226 const iterator_comparisons<D2,Base2>& yb)
228 const D1& x = static_cast<const D1&>(xb);
229 const D2& y = static_cast<const D2&>(yb);
230 return x.policies().distance(y, x) > 0;
233 template <class D1, class D2, class Base1, class Base2>
234 inline bool operator>=(const iterator_comparisons<D1,Base1>& xb,
235 const iterator_comparisons<D2,Base2>& yb)
237 const D1& x = static_cast<const D1&>(xb);
238 const D2& y = static_cast<const D2&>(yb);
239 return x.policies().distance(y, x) >= 0;
242 template <class D1, class D2, class Base1, class Base2>
243 inline bool operator<=(const iterator_comparisons<D1,Base1>& xb,
244 const iterator_comparisons<D2,Base2>& yb)
246 const D1& x = static_cast<const D1&>(xb);
247 const D2& y = static_cast<const D2&>(yb);
248 return x.policies().distance(y, x) <= 0;
254 // operator->() needs special support for input iterators to strictly meet the
255 // standard's requirements. If *i is not a reference type, we must still
256 // produce a (constant) lvalue to which a pointer can be formed. We do that by
257 // returning an instantiation of this special proxy class template.
260 struct operator_arrow_proxy
262 operator_arrow_proxy(const T& x) : m_value(x) {}
263 // RG removed const below
264 T* operator->() const { return &m_value; }
265 // This function is needed for MWCW and BCC, which won't call operator->
266 // again automatically per 13.3.1.2 para 8
268 // RG - removed const below
269 operator T*() const { return &m_value; }
273 template <class Iter>
274 inline operator_arrow_proxy<typename Iter::reference>
275 operator_arrow(const Iter& i, std::input_iterator_tag) {
276 // RG - THIS is the change I needed to make!
277 // My input iterators need to return proxy references rather than values
278 typedef typename Iter::reference value_t; // VC++ needs this typedef
279 return operator_arrow_proxy<value_t>(*i);
282 template <class Iter>
283 inline typename Iter::pointer
284 operator_arrow(const Iter& i, std::forward_iterator_tag) {
288 template <class Value, class Reference, class Pointer>
289 struct operator_arrow_result_generator
291 //RG - another important change!
292 typedef operator_arrow_proxy<Reference> proxy;
293 // Borland chokes unless it's an actual enum (!)
294 enum { use_proxy = !boost::is_reference<Reference>::value };
296 typedef typename boost::detail::if_true<(use_proxy)>::template
305 # ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
307 // Select default pointer and reference types for adapted non-pointer
308 // iterators based on the iterator and the value_type. Poor man's partial
309 // specialization is in use here.
310 template <bool is_pointer>
311 struct iterator_defaults_select
313 template <class Iterator,class Value>
316 // The assumption is that iterator_traits can deduce these types
317 // properly as long as the iterator is not a pointer.
318 typedef typename boost::detail::iterator_traits<Iterator>::pointer pointer;
319 typedef typename boost::detail::iterator_traits<Iterator>::reference reference;
323 // Select default pointer and reference types for adapted pointer iterators
324 // given a (possibly-const) value_type.
326 struct iterator_defaults_select<true>
328 template <class Iterator,class Value>
331 typedef Value* pointer;
332 typedef Value& reference;
336 // Consolidate selection of the default pointer and reference type
337 template <class Iterator,class Value>
338 struct iterator_defaults
340 BOOST_STATIC_CONSTANT(bool, is_ptr = boost::is_pointer<Iterator>::value);
342 typedef typename iterator_defaults_select<is_ptr>::template traits<Iterator,Value> traits;
343 typedef typename traits::pointer pointer;
344 typedef typename traits::reference reference;
347 template <class Iterator,class Value>
348 struct iterator_defaults : iterator_traits<Iterator>
350 // Trying to factor the common is_same expression into an enum or a
351 // static bool constant confused Borland.
352 typedef typename if_true<(
353 ::boost::is_same<Value,typename iterator_traits<Iterator>::value_type>::value
355 typename iterator_traits<Iterator>::pointer,
359 typedef typename if_true<(
360 ::boost::is_same<Value,typename iterator_traits<Iterator>::value_type>::value
362 typename iterator_traits<Iterator>::reference,
369 //===========================================================================
370 // Specify the defaults for iterator_adaptor's template parameters
372 struct default_argument { };
373 // This class template is a workaround for MSVC.
374 struct dummy_default_gen {
375 template <class Base, class Traits>
376 struct select { typedef default_argument type; };
378 // This class template is a workaround for MSVC.
379 template <class Gen> struct default_generator {
380 typedef dummy_default_gen type;
383 struct default_value_type {
384 template <class Base, class Traits>
386 typedef typename boost::detail::iterator_traits<Base>::value_type type;
389 template <> struct default_generator<default_value_type>
390 { typedef default_value_type type; }; // VC++ workaround
392 struct default_difference_type {
393 template <class Base, class Traits>
395 typedef typename boost::detail::iterator_traits<Base>::difference_type type;
398 template <> struct default_generator<default_difference_type>
399 { typedef default_difference_type type; }; // VC++ workaround
401 struct default_iterator_category {
402 template <class Base, class Traits>
404 typedef typename boost::detail::iterator_traits<Base>::iterator_category type;
407 template <> struct default_generator<default_iterator_category>
408 { typedef default_iterator_category type; }; // VC++ workaround
410 struct default_pointer {
411 template <class Base, class Traits>
413 typedef typename Traits::value_type Value;
414 typedef typename boost::detail::multi_array::detail::iterator_defaults<Base,Value>::pointer
418 template <> struct default_generator<default_pointer>
419 { typedef default_pointer type; }; // VC++ workaround
421 struct default_reference {
422 template <class Base, class Traits>
424 typedef typename Traits::value_type Value;
425 typedef typename boost::detail::multi_array::detail::iterator_defaults<Base,Value>::reference
429 template <> struct default_generator<default_reference>
430 { typedef default_reference type; }; // VC++ workaround
432 } // namespace detail
435 //===========================================================================
436 // Support for named template parameters
438 struct named_template_param_base { };
441 struct value_type_tag { };
442 struct reference_tag { };
443 struct pointer_tag { };
444 struct difference_type_tag { };
445 struct iterator_category_tag { };
447 // avoid using std::pair because A or B might be a reference type, and g++
448 // complains about forming references to references inside std::pair
449 template <class A, class B>
451 typedef A first_type;
452 typedef B second_type;
455 } // namespace detail
457 template <class Value> struct value_type_is : public named_template_param_base
459 typedef detail::cons_type<detail::value_type_tag, Value> type;
461 template <class Reference> struct reference_is : public named_template_param_base
463 typedef detail::cons_type<detail::reference_tag, Reference> type;
465 template <class Pointer> struct pointer_is : public named_template_param_base
467 typedef detail::cons_type<detail::pointer_tag, Pointer> type;
469 template <class Difference> struct difference_type_is
470 : public named_template_param_base
472 typedef detail::cons_type<detail::difference_type_tag, Difference> type;
474 template <class IteratorCategory> struct iterator_category_is
475 : public named_template_param_base
477 typedef detail::cons_type<detail::iterator_category_tag, IteratorCategory> type;
482 struct end_of_list { };
484 // Given an associative list, find the value with the matching key.
485 // An associative list is a list of key-value pairs. The list is
486 // built out of cons_type's and is terminated by end_of_list.
488 # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || defined(__BORLANDC__)
489 template <class AssocList, class Key>
492 struct find_param_continue {
493 template <class AssocList, class Key2> struct select {
494 typedef typename AssocList::first_type Head;
495 typedef typename Head::first_type Key1;
496 typedef typename Head::second_type Value;
497 typedef typename if_true<(is_same<Key1, Key2>::value)>::template
499 typename find_param<typename AssocList::second_type, Key2>::type
503 struct find_param_end {
504 template <class AssocList, class Key>
505 struct select { typedef detail::default_argument type; };
507 template <class AssocList> struct find_param_helper1
508 { typedef find_param_continue type; };
509 template <> struct find_param_helper1<end_of_list>
510 { typedef find_param_end type; };
512 template <class AssocList, class Key>
514 typedef typename find_param_helper1<AssocList>::type select1;
515 typedef typename select1::template select<AssocList, Key>::type type;
518 template <class AssocList, class Key> struct find_param;
521 struct find_param<end_of_list, Key> { typedef default_argument type; };
523 // Found a matching Key, return the associated Value
524 template <class Key, class Value, class Rest>
525 struct find_param<detail::cons_type< detail::cons_type<Key, Value>, Rest>, Key> {
529 // Non-matching keys, continue the search
530 template <class Key1, class Value, class Rest, class Key2>
531 struct find_param<detail::cons_type< detail::cons_type<Key1, Value>, Rest>, Key2> {
532 typedef typename find_param<Rest, Key2>::type type;
536 struct make_named_arg {
537 template <class Key, class Value>
538 struct select { typedef typename Value::type type; };
540 struct make_key_value {
541 template <class Key, class Value>
542 struct select { typedef detail::cons_type<Key, Value> type; };
545 template <class Value>
546 struct is_named_parameter
548 enum { value = is_convertible<Value, named_template_param_base>::value };
551 # if defined(__MWERKS__) && __MWERKS__ <= 0x2406 // workaround for broken is_convertible implementation
552 template <class T> struct is_named_parameter<value_type_is<T> > { enum { value = true }; };
553 template <class T> struct is_named_parameter<reference_is<T> > { enum { value = true }; };
554 template <class T> struct is_named_parameter<pointer_is<T> > { enum { value = true }; };
555 template <class T> struct is_named_parameter<difference_type_is<T> > { enum { value = true }; };
556 template <class T> struct is_named_parameter<iterator_category_is<T> > { enum { value = true }; };
559 template <class Key, class Value>
562 // Borland C++ doesn't like the extra indirection of is_named_parameter
564 if_true<(is_convertible<Value,named_template_param_base>::value)>::
565 template then<make_named_arg, make_key_value>::type Make;
567 enum { is_named = is_named_parameter<Value>::value };
568 typedef typename if_true<(is_named)>::template
569 then<make_named_arg, make_key_value>::type Make;
571 typedef typename Make::template select<Key, Value>::type type;
574 // Mechanism for resolving the default argument for a template parameter.
576 template <class T> struct is_default { typedef type_traits::no_type type; };
577 template <> struct is_default<default_argument>
578 { typedef type_traits::yes_type type; };
580 struct choose_default {
581 template <class Arg, class DefaultGen, class Base, class Traits>
583 typedef typename default_generator<DefaultGen>::type Gen;
584 typedef typename Gen::template select<Base,Traits>::type type;
588 template <class Arg, class DefaultGen, class Base, class Traits>
594 template <class UseDefault>
595 struct choose_arg_or_default { typedef choose_arg type; };
596 template <> struct choose_arg_or_default<type_traits::yes_type> {
597 typedef choose_default type;
600 template <class Arg, class DefaultGen, class Base, class Traits>
601 class resolve_default {
602 typedef typename choose_arg_or_default<typename is_default<Arg>::type>::type
605 typedef typename Selector
606 ::template select<Arg, DefaultGen, Base, Traits>::type type;
609 template <class Base, class Value, class Reference, class Pointer,
610 class Category, class Distance>
611 class iterator_adaptor_traits_gen
613 // Form an associative list out of the template parameters
614 // If the argument is a normal parameter (not named) then make_arg
615 // creates a key-value pair. If the argument is a named parameter,
616 // then make_arg extracts the key-value pair defined inside the
618 typedef detail::cons_type< typename make_arg<value_type_tag, Value>::type,
619 detail::cons_type<typename make_arg<reference_tag, Reference>::type,
620 detail::cons_type<typename make_arg<pointer_tag, Pointer>::type,
621 detail::cons_type<typename make_arg<iterator_category_tag, Category>::type,
622 detail::cons_type<typename make_arg<difference_type_tag, Distance>::type,
623 end_of_list> > > > > ArgList;
625 // Search the list for particular parameters
626 typedef typename find_param<ArgList, value_type_tag>::type Val;
627 typedef typename find_param<ArgList, difference_type_tag>::type Diff;
628 typedef typename find_param<ArgList, iterator_category_tag>::type Cat;
629 typedef typename find_param<ArgList, pointer_tag>::type Ptr;
630 typedef typename find_param<ArgList, reference_tag>::type Ref;
632 typedef boost::iterator<Category, Value, Distance, Pointer, Reference>
635 // Compute the defaults if necessary
636 typedef typename resolve_default<Val, default_value_type, Base, Traits0>::type
638 // if getting default value type from iterator_traits, then it won't be const
639 typedef typename resolve_default<Diff, default_difference_type, Base,
640 Traits0>::type difference_type;
641 typedef typename resolve_default<Cat, default_iterator_category, Base,
642 Traits0>::type iterator_category;
644 typedef boost::iterator<iterator_category, value_type, difference_type,
645 Pointer, Reference> Traits1;
647 // Compute the defaults for pointer and reference. This is done as a
648 // separate step because the defaults for pointer and reference depend
650 typedef typename resolve_default<Ptr, default_pointer, Base, Traits1>::type
652 typedef typename resolve_default<Ref, default_reference, Base, Traits1>::type
656 typedef boost::iterator<iterator_category,
657 typename remove_const<value_type>::type,
658 difference_type, pointer, reference> type;
661 // This is really a partial concept check for iterators. Should it
662 // be moved or done differently?
663 template <class Category, class Value, class Difference, class Pointer, class Reference>
666 BOOST_STATIC_CONSTANT(
667 bool, is_input_or_output_iter
668 = (boost::is_convertible<Category*,std::input_iterator_tag*>::value
669 | boost::is_convertible<Category*,std::output_iterator_tag*>::value));
671 // Iterators should satisfy one of the known categories
672 BOOST_STATIC_ASSERT(is_input_or_output_iter);
674 // Iterators >= ForwardIterator must produce real references
675 // as required by the C++ standard requirements in Table 74.
676 BOOST_STATIC_CONSTANT(
677 bool, forward_iter_with_real_reference
678 = ((!boost::is_convertible<Category*,std::forward_iterator_tag*>::value)
679 | boost::is_same<Reference,Value&>::value
680 | boost::is_same<Reference,typename add_const<Value>::type&>::value));
682 BOOST_STATIC_ASSERT(forward_iter_with_real_reference);
684 } // namespace detail
688 // This macro definition is only temporary in this file
689 # if !defined(BOOST_MSVC)
690 # define BOOST_ARG_DEPENDENT_TYPENAME typename
692 # define BOOST_ARG_DEPENDENT_TYPENAME
695 //============================================================================
696 //iterator_adaptor - Adapts a generic piece of data as an iterator. Adaptation
697 // is especially easy if the data being adapted is itself an iterator
699 // Base - the base (usually iterator) type being wrapped.
701 // Policies - a set of policies determining how the resulting iterator
704 // Value - if supplied, the value_type of the resulting iterator, unless
705 // const. If const, a conforming compiler strips constness for the
706 // value_type. If not supplied, iterator_traits<Base>::value_type is used
708 // Reference - the reference type of the resulting iterator, and in
709 // particular, the result type of operator*(). If not supplied but
710 // Value is supplied, Value& is used. Otherwise
711 // iterator_traits<Base>::reference is used.
713 // Pointer - the pointer type of the resulting iterator, and in
714 // particular, the result type of operator->(). If not
715 // supplied but Value is supplied, Value* is used. Otherwise
716 // iterator_traits<Base>::pointer is used.
718 // Category - the iterator_category of the resulting iterator. If not
719 // supplied, iterator_traits<Base>::iterator_category is used.
721 // Distance - the difference_type of the resulting iterator. If not
722 // supplied, iterator_traits<Base>::difference_type is used.
723 template <class Base, class Policies,
724 class Value = ::boost::detail::multi_array::detail::default_argument,
725 class Reference = ::boost::detail::multi_array::detail::default_argument,
726 class Pointer = ::boost::detail::multi_array::detail::default_argument,
727 class Category = ::boost::detail::multi_array::detail::default_argument,
728 class Distance = ::boost::detail::multi_array::detail::default_argument
730 struct iterator_adaptor :
731 #ifdef BOOST_RELOPS_AMBIGUITY_BUG
732 iterator_comparisons<
733 iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance>,
734 typename detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category, Distance>::type
737 detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance>::type
740 typedef iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance> self;
742 typedef detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance> TraitsGen;
743 typedef typename TraitsGen::type Traits;
745 typedef typename Traits::difference_type difference_type;
746 typedef typename Traits::value_type value_type;
747 typedef typename Traits::pointer pointer;
748 typedef typename Traits::reference reference;
749 typedef typename Traits::iterator_category iterator_category;
751 typedef Base base_type;
752 typedef Policies policies_type;
755 typedef detail::validator<
756 iterator_category,value_type,difference_type,pointer,reference
765 iterator_adaptor(const Base& it, const Policies& p = Policies())
767 policies().initialize(base());
770 template <class Iter2, class Value2, class Pointer2, class Reference2>
772 const iterator_adaptor<Iter2,Policies,Value2,Reference2,Pointer2,Category,Distance>& src)
773 : m_iter_p(src.base(), src.policies())
775 policies().initialize(base());
778 #if defined(BOOST_MSVC) || defined(__BORLANDC__)
779 // This is required to prevent a bug in how VC++ generates
780 // the assignment operator for compressed_pairv
781 iterator_adaptor& operator= (const iterator_adaptor& x) {
782 m_iter_p = x.m_iter_p;
786 reference operator*() const {
787 return policies().dereference(*this);
791 # pragma warning(push)
792 # pragma warning( disable : 4284 )
795 typename boost::detail::multi_array::detail::operator_arrow_result_generator<value_type,reference,pointer>::type
797 { return detail::operator_arrow(*this, iterator_category()); }
800 # pragma warning(pop)
803 value_type operator[](difference_type n) const
804 { return *(*this + n); }
807 #if !defined(__MWERKS__) || __MWERKS__ >= 0x2405
808 policies().increment(*this);
810 // Odd bug, MWERKS couldn't deduce the type for the member template
811 // Workaround by explicitly specifying the type.
812 policies().increment<self>(*this);
817 self operator++(int) { self tmp(*this); ++*this; return tmp; }
820 #if !defined(__MWERKS__) || __MWERKS__ >= 0x2405
821 policies().decrement(*this);
823 policies().decrement<self>(*this);
828 self operator--(int) { self tmp(*this); --*this; return tmp; }
830 self& operator+=(difference_type n) {
831 policies().advance(*this, n);
835 self& operator-=(difference_type n) {
836 policies().advance(*this, -n);
840 base_type const& base() const { return m_iter_p.first(); }
842 // Moved from global scope to avoid ambiguity with the operator-() which
843 // subtracts iterators from one another.
844 self operator-(difference_type x) const
845 { self result(*this); return result -= x; }
847 compressed_pair<Base,Policies> m_iter_p;
849 public: // implementation details (too many compilers have trouble when these are private).
850 base_type& base() { return m_iter_p.first(); }
851 Policies& policies() { return m_iter_p.second(); }
852 const Policies& policies() const { return m_iter_p.second(); }
855 template <class Base, class Policies, class Value, class Reference, class Pointer,
856 class Category, class Distance1, class Distance2>
857 iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance1>
859 iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance1> p,
865 template <class Base, class Policies, class Value, class Reference, class Pointer,
866 class Category, class Distance1, class Distance2>
867 iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance1>
870 iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance1> p)
875 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
876 class Reference1, class Reference2, class Pointer1, class Pointer2, class Category,
878 typename iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>::difference_type
880 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
881 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
883 typedef typename iterator_adaptor<Iterator1,Policies,Value1,Reference1,
884 Pointer1,Category,Distance>::difference_type difference_type;
885 return x.policies().distance(y, x);
888 #ifndef BOOST_RELOPS_AMBIGUITY_BUG
889 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
890 class Reference1, class Reference2, class Pointer1, class Pointer2,
891 class Category, class Distance>
894 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
895 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
897 return x.policies().equal(x, y);
900 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
901 class Reference1, class Reference2, class Pointer1, class Pointer2,
902 class Category, class Distance>
905 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
906 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
908 return x.policies().distance(y, x) < 0;
911 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
912 class Reference1, class Reference2, class Pointer1, class Pointer2,
913 class Category, class Distance>
916 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
917 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
919 return x.policies().distance(y, x) > 0;
922 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
923 class Reference1, class Reference2, class Pointer1, class Pointer2,
924 class Category, class Distance>
927 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
928 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
930 return x.policies().distance(y, x) >= 0;
933 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
934 class Reference1, class Reference2, class Pointer1, class Pointer2,
935 class Category, class Distance>
938 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
939 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
941 return x.policies().distance(y, x) <= 0;
944 template <class Iterator1, class Iterator2, class Policies, class Value1, class Value2,
945 class Reference1, class Reference2, class Pointer1, class Pointer2,
946 class Category, class Distance>
949 const iterator_adaptor<Iterator1,Policies,Value1,Reference1,Pointer1,Category,Distance>& x,
950 const iterator_adaptor<Iterator2,Policies,Value2,Reference2,Pointer2,Category,Distance>& y)
952 return !x.policies().equal(x, y);
957 } // namespace multi_array
958 } // namespace detail
960 # undef BOOST_ARG_DEPENDENT_TYPENAME