1 #ifndef BOOST_RANGE_DETAIL_MICROSOFT_HPP
2 #define BOOST_RANGE_DETAIL_MICROSOFT_HPP
4 // Boost.Range MFC/ATL Extension
6 // Copyright Shunsuke Sogame 2005-2006.
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
18 #include <boost/range/iterator.hpp>
21 #define BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1 1
24 #if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1)
25 #define BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator range_mutable_iterator
26 #define BOOST_RANGE_DETAIL_MICROSOFT_range_begin range_begin
27 #define BOOST_RANGE_DETAIL_MICROSOFT_range_end range_end
29 #define BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator range_mutable_iterator
30 #define BOOST_RANGE_DETAIL_MICROSOFT_range_begin range_begin
31 #define BOOST_RANGE_DETAIL_MICROSOFT_range_end range_end
37 // yet another customization way
41 #include <boost/iterator/iterator_traits.hpp> // iterator_difference
42 #include <boost/mpl/identity.hpp>
43 #include <boost/mpl/if.hpp>
44 #include <boost/preprocessor/cat.hpp>
45 #include <boost/preprocessor/control/iif.hpp>
46 #include <boost/preprocessor/comma_if.hpp>
47 #include <boost/preprocessor/detail/is_unary.hpp>
48 #include <boost/preprocessor/list/for_each.hpp>
49 #include <boost/preprocessor/repetition/enum_params.hpp>
50 #include <boost/preprocessor/repetition/repeat.hpp>
51 #include <boost/preprocessor/seq/for_each_i.hpp>
52 #include <boost/preprocessor/seq/size.hpp>
53 #include <boost/preprocessor/tuple/eat.hpp>
54 #include <boost/range/const_iterator.hpp>
55 #include <boost/range/size_type.hpp>
56 #include <boost/type_traits/is_const.hpp>
57 #include <boost/type_traits/is_same.hpp>
58 #include <boost/type_traits/remove_cv.hpp>
59 #include <boost/utility/addressof.hpp>
60 #include <boost/utility/enable_if.hpp> // disable_if
62 #if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1)
63 #include <boost/range/mutable_iterator.hpp>
65 #include <iterator> // distance
66 #include <boost/range/begin.hpp>
67 #include <boost/range/end.hpp>
68 #include <boost/range/iterator.hpp>
72 namespace boost { namespace range_detail_microsoft {
75 // customization point
83 struct customization_tag;
86 struct using_type_as_tag
91 // In fact, it is unnecessary for VC++.
92 // VC++'s behavior seems conforming, while GCC fails without this.
93 template< class Iterator, class T >
95 disable_if< is_const<T>, Iterator >
102 template< class Tag, class T >
103 struct customization_tag_of
105 typedef typename mpl::if_< is_same<using_type_as_tag, Tag>,
113 struct customization_of
115 typedef typename remove_cv<T>::type bare_t;
116 typedef typename customization_tag<bare_t>::type tag_t;
117 typedef customization<tag_t> type;
122 struct mutable_iterator_of
124 typedef typename remove_cv<T>::type bare_t;
125 typedef typename customization_of<bare_t>::type cust_t;
126 typedef typename cust_t::template meta<bare_t>::mutable_iterator type;
131 struct const_iterator_of
133 typedef typename remove_cv<T>::type bare_t;
134 typedef typename customization_of<bare_t>::type cust_t;
135 typedef typename cust_t::template meta<bare_t>::const_iterator type;
142 typedef typename range_detail_microsoft::mutable_iterator_of<T>::type miter_t;
143 typedef typename iterator_difference<miter_t>::type type;
147 template< class T > inline
148 typename mutable_iterator_of<T>::type
151 typedef typename customization_of<T>::type cust_t;
152 return cust_t().template begin<typename mutable_iterator_of<T>::type>(x);
156 template< class T > inline
157 typename const_iterator_of<T>::type
160 typedef typename customization_of<T>::type cust_t;
161 return cust_t().template begin<typename const_iterator_of<T>::type>(x);
165 template< class T > inline
166 typename mutable_iterator_of<T>::type
169 typedef typename customization_of<T>::type cust_t;
170 return cust_t().template end<typename mutable_iterator_of<T>::type>(x);
174 template< class T > inline
175 typename const_iterator_of<T>::type
178 typedef typename customization_of<T>::type cust_t;
179 return cust_t().template end<typename const_iterator_of<T>::type>(x);
183 #if defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1)
185 template< class T > inline
186 typename size_type_of<T>::type
189 return std::distance(boost::begin(x), boost::end(x));
195 template< class Range >
196 struct compatible_mutable_iterator :
197 BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator<Range>
201 } } // namespace boost::range_detail_microsoft
204 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open(NamespaceList) \
205 BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open_op, ~, NamespaceList) \
208 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open_op(r, data, elem) \
213 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close(NamespaceList) \
214 BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close_op, ~, NamespaceList) \
217 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close_op(r, data, elem) \
222 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_expand_op(r, data, elem) \
227 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE(Tag, NamespaceList, Name) \
228 namespace boost { namespace range_detail_microsoft { \
229 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_tag(Tag, BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
233 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_mutable_iterator(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
234 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_const_iterator(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
235 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size_type(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
238 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open(NamespaceList) \
239 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
240 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin_const(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
241 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
242 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end_const(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
243 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name)) \
244 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close(NamespaceList) \
248 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_fullname(NamespaceList, Name) \
249 BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_expand_op, ~, NamespaceList) :: Name \
253 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_tag(Tag, Fullname) \
255 struct customization_tag< Fullname > : \
256 customization_tag_of< Tag, Fullname > \
264 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_mutable_iterator(Fullname) \
266 struct BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator< Fullname > : \
267 range_detail_microsoft::mutable_iterator_of< Fullname > \
272 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_const_iterator(Fullname) \
274 struct range_const_iterator< Fullname > : \
275 range_detail_microsoft::const_iterator_of< Fullname > \
280 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size_type(Fullname) \
282 struct range_size< Fullname > : \
283 range_detail_microsoft::size_type_of< Fullname > \
291 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin(Fullname) \
293 boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \
294 BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname& x) \
296 return boost::range_detail_microsoft::begin_of(x); \
301 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_begin_const(Fullname) \
303 boost::range_detail_microsoft::const_iterator_of< Fullname >::type \
304 BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname const& x) \
306 return boost::range_detail_microsoft::begin_of(x); \
311 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end(Fullname) \
313 boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \
314 BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname& x) \
316 return boost::range_detail_microsoft::end_of(x); \
321 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_end_const(Fullname) \
323 boost::range_detail_microsoft::const_iterator_of< Fullname >::type \
324 BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname const& x) \
326 return boost::range_detail_microsoft::end_of(x); \
331 #if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1)
333 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size(Fullname) \
338 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TYPE_size(Fullname) \
340 boost::range_detail_microsoft::size_type_of< Fullname >::type \
341 boost_range_size(Fullname const& x) \
343 return boost::range_detail_microsoft::size_of(x); \
350 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE(Tag, NamespaceList, Name, ParamSeqOrCount) \
351 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_impl( \
352 Tag, NamespaceList, Name, \
353 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq(ParamSeqOrCount) \
357 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq(ParamSeqOrCount) \
358 BOOST_PP_IIF(BOOST_PP_IS_UNARY(ParamSeqOrCount), \
359 ParamSeqOrCount BOOST_PP_TUPLE_EAT(3), \
361 )(ParamSeqOrCount, BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq_op, ~) \
364 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_to_param_seq_op(z, n, _) \
369 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_impl(Tag, NamespaceList, Name, ParamSeq) \
370 namespace boost { namespace range_detail_microsoft { \
371 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_tag( \
373 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
374 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
379 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_mutable_iterator( \
380 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
381 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
383 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_const_iterator( \
384 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
385 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
388 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size_type( \
389 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
390 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
394 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_open(NamespaceList) \
395 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin( \
396 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
397 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
399 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin_const( \
400 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
401 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
403 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end( \
404 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
405 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
407 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end_const( \
408 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
409 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
411 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size( \
412 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq), \
413 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
415 BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_close(NamespaceList) \
419 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params(ParamSeq) \
420 BOOST_PP_SEQ_FOR_EACH_I(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params_op, ~, ParamSeq) \
423 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_params_op(r, data, i, elem) \
424 BOOST_PP_COMMA_IF(i) elem BOOST_PP_CAT(T, i) \
428 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_fullname(NamespaceList, Name, ParamSeq) \
429 BOOST_PP_LIST_FOR_EACH(BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_namespace_expand_op, ~, NamespaceList) \
430 :: Name < BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(ParamSeq), T) > \
434 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_tag(Tag, Params, Fullname) \
436 struct customization_tag< Fullname > : \
437 customization_tag_of< Tag, Fullname > \
445 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_mutable_iterator(Params, Fullname) \
447 struct BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator< Fullname > : \
448 range_detail_microsoft::mutable_iterator_of< Fullname > \
453 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_const_iterator(Params, Fullname) \
455 struct range_const_iterator< Fullname > : \
456 range_detail_microsoft::const_iterator_of< Fullname > \
461 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size_type(Params, Fullname) \
463 struct range_size< Fullname > : \
464 range_detail_microsoft::size_type_of< Fullname > \
472 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin(Params, Fullname) \
473 template< Params > inline \
474 typename boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \
475 BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname& x) \
477 return boost::range_detail_microsoft::begin_of(x); \
482 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_begin_const(Params, Fullname) \
483 template< Params > inline \
484 typename boost::range_detail_microsoft::const_iterator_of< Fullname >::type \
485 BOOST_RANGE_DETAIL_MICROSOFT_range_begin(Fullname const& x) \
487 return boost::range_detail_microsoft::begin_of(x); \
492 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end(Params, Fullname) \
493 template< Params > inline \
494 typename boost::range_detail_microsoft::mutable_iterator_of< Fullname >::type \
495 BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname& x) \
497 return boost::range_detail_microsoft::end_of(x); \
502 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_end_const(Params, Fullname) \
503 template< Params > inline \
504 typename boost::range_detail_microsoft::const_iterator_of< Fullname >::type \
505 BOOST_RANGE_DETAIL_MICROSOFT_range_end(Fullname const& x) \
507 return boost::range_detail_microsoft::end_of(x); \
512 #if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1)
514 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size(Params, Fullname) \
519 #define BOOST_RANGE_DETAIL_MICROSOFT_CUSTOMIZATION_TEMPLATE_size(Params, Fullname) \
520 template< Params > inline \
521 typename boost::range_detail_microsoft::size_type_of< Fullname >::type \
522 boost_range_size(Fullname const& x) \
524 return boost::range_detail_microsoft::size_of(x); \
533 // list_iterator and helpers
537 #include <boost/assert.hpp>
538 #include <boost/iterator/iterator_categories.hpp>
539 #include <boost/iterator/iterator_facade.hpp>
540 #include <boost/mpl/if.hpp>
541 #include <boost/type_traits/is_same.hpp>
544 // POSITION's header is undocumented, so is NULL.
546 struct __POSITION; // incomplete, but used as just a pointer.
547 typedef __POSITION *POSITION;
550 namespace boost { namespace range_detail_microsoft {
559 struct list_iterator;
568 struct list_iterator_super
570 typedef typename mpl::if_< is_same<use_default, Reference>,
575 typedef typename mpl::if_< is_same<use_default, Traversal>,
576 bidirectional_traversal_tag,
580 typedef iterator_facade<
581 list_iterator<ListT, Value, Reference, Traversal>,
592 class Reference = use_default,
593 class Traversal = use_default
595 struct list_iterator :
596 list_iterator_super<ListT, Value, Reference, Traversal>::type
599 typedef list_iterator self_t;
600 typedef typename list_iterator_super<ListT, Value, Reference, Traversal>::type super_t;
601 typedef typename super_t::reference ref_t;
604 explicit list_iterator()
607 explicit list_iterator(ListT& lst, POSITION pos) :
608 m_plst(boost::addressof(lst)), m_pos(pos)
611 template< class, class, class, class > friend struct list_iterator;
612 template< class ListT_, class Value_, class Reference_, class Traversal_>
613 list_iterator(list_iterator<ListT_, Value_, Reference_, Traversal_> const& other) :
614 m_plst(other.m_plst), m_pos(other.m_pos)
621 friend class iterator_core_access;
622 ref_t dereference() const
624 BOOST_ASSERT(m_pos != 0 && "out of range");
625 return m_plst->GetAt(m_pos);
633 BOOST_ASSERT(m_pos != 0 && "out of range");
634 m_plst->GetNext(m_pos);
640 m_pos = m_plst->GetTailPosition();
644 m_plst->GetPrev(m_pos);
647 bool equal(self_t const& other) const
649 BOOST_ASSERT(m_plst == other.m_plst && "iterators incompatible");
650 return m_pos == other.m_pos;
655 // customization helpers
658 struct array_functions
660 template< class Iterator, class X >
666 template< class Iterator, class X >
669 return begin<Iterator>(x) + x.GetSize();
674 struct list_functions
676 template< class Iterator, class X >
679 return Iterator(x, x.GetHeadPosition());
682 template< class Iterator, class X >
685 return Iterator(x, POSITION(0));
690 } } // namespace boost::range_detail_microsoft
699 #if defined(BOOST_RANGE_DETAIL_MICROSOFT_TEST)
705 #include <boost/concept_check.hpp>
706 #include <boost/next_prior.hpp>
707 #include <boost/range/begin.hpp>
708 #include <boost/range/concepts.hpp>
709 #include <boost/range/const_iterator.hpp>
710 #include <boost/range/difference_type.hpp>
711 #include <boost/range/distance.hpp>
712 #include <boost/range/empty.hpp>
713 #include <boost/range/iterator_range.hpp>
714 #include <boost/range/mutable_iterator.hpp>
715 #include <boost/range/rbegin.hpp>
716 #include <boost/range/rend.hpp>
717 #include <boost/range/value_type.hpp>
718 #include <boost/type_traits/is_same.hpp>
721 namespace boost { namespace range_detail_microsoft {
724 template< class Range1, class Range2 >
725 bool test_equals(Range1 const& rng1, Range2 const& rng2)
728 boost::distance(rng1) == boost::distance(rng2) &&
729 std::equal(boost::begin(rng1), boost::end(rng1), boost::begin(rng2))
734 template< class AssocContainer, class PairT >
735 bool test_find_key_and_mapped(AssocContainer const& ac, PairT const& pa)
737 typedef typename boost::range_const_iterator<AssocContainer>::type iter_t;
738 for (iter_t it = boost::const_begin(ac), last = boost::const_end(ac); it != last; ++it) {
739 if (it->first == pa.first && it->second == pa.second)
750 template< class Range >
751 bool test_emptiness(Range& )
756 result = result && boost::empty(emptyRng);
762 template< class Range >
763 bool test_trivial(Range& rng)
767 // convertibility check
768 typedef typename range_const_iterator<Range>::type citer_t;
769 citer_t cit = boost::begin(rng);
773 typedef typename range_value<Range>::type val_t;
774 val_t v = *boost::begin(rng);
775 *boost::begin(rng) = v;
776 result = result && *boost::begin(rng) == v;
782 template< class Range >
783 bool test_forward(Range& rng)
785 boost::function_requires< ForwardRangeConcept<Range> >();
787 bool result = (test_trivial)(rng);
789 typedef typename range_value<Range>::type val_t;
791 std::vector<val_t> saved;
792 std::copy(boost::begin(rng), boost::end(rng), std::back_inserter(saved));
793 std::rotate(boost::begin(saved), boost::next(boost::begin(saved)), boost::end(saved));
795 std::rotate(boost::begin(rng), boost::next(boost::begin(rng)), boost::end(rng));
797 return result && (test_equals)(saved, rng);
801 template< class Range >
802 bool test_bidirectional(Range& rng)
804 boost::function_requires< BidirectionalRangeConcept<Range> >();
806 bool result = (test_forward)(rng);
808 typedef typename range_value<Range>::type val_t;
810 std::vector<val_t> saved;
811 std::copy(boost::begin(rng), boost::end(rng), std::back_inserter(saved));
813 result = result && (test_equals)(
814 boost::make_iterator_range(boost::rbegin(saved), boost::rend(saved)),
815 boost::make_iterator_range(boost::rbegin(rng), boost::rend(rng))
822 template< class Range >
823 bool test_random_access(Range& rng)
825 boost::function_requires< RandomAccessRangeConcept<Range> >();
827 bool result = (test_bidirectional)(rng);
829 typedef typename range_value<Range>::type val_t;
831 std::vector<val_t> saved;
832 std::copy(boost::begin(rng), boost::end(rng), std::back_inserter(saved));
833 std::sort(boost::begin(saved), boost::end(saved));
835 std::random_shuffle(boost::begin(rng), boost::end(rng));
836 std::sort(boost::begin(rng), boost::end(rng));
837 result = result && (test_equals)(rng, saved);
839 std::random_shuffle(boost::begin(rng), boost::end(rng));
840 std::stable_sort(boost::begin(rng), boost::end(rng));
841 result = result && (test_equals)(rng, saved);
843 std::random_shuffle(boost::begin(rng), boost::end(rng));
844 std::partial_sort(boost::begin(rng), boost::end(rng), boost::end(rng));
845 result = result && (test_equals)(rng, saved);
854 template< class ArrayT, class SampleRange >
855 bool test_init_array(ArrayT& arr, SampleRange const& sample)
857 typedef typename range_const_iterator<SampleRange>::type iter_t;
858 typedef typename range_value<SampleRange>::type val_t;
860 for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) {
861 val_t v = *it; // works around ATL3 CSimpleArray
865 return (test_equals)(arr, sample);
869 template< class ListT, class SampleRange >
870 bool test_init_list(ListT& lst, SampleRange const& sample)
872 typedef typename range_const_iterator<SampleRange>::type iter_t;
874 for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) {
878 return (test_equals)(lst, sample);
882 template< class StringT, class SampleRange >
883 bool test_init_string(StringT& str, SampleRange const& sample)
885 typedef typename range_const_iterator<SampleRange>::type iter_t;
886 typedef typename range_value<SampleRange>::type val_t;
888 for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) {
892 return (test_equals)(str, sample);
896 template< class MapT, class SampleMap >
897 bool test_init_map(MapT& map, SampleMap const& sample)
899 typedef typename range_const_iterator<SampleMap>::type iter_t;
901 for (iter_t it = boost::const_begin(sample), last = boost::const_end(sample); it != last; ++it) {
902 map.SetAt(it->first, it->second);
905 return boost::distance(map) == boost::distance(sample);
912 template< class Range, class Iter >
913 struct test_mutable_iter :
914 boost::is_same< typename boost::BOOST_RANGE_DETAIL_MICROSOFT_range_mutable_iterator<Range>::type, Iter >
918 template< class Range, class Iter >
919 struct test_const_iter :
920 boost::is_same< typename boost::range_const_iterator<Range>::type, Iter >
924 } } // namespace boost::range_detail_microsoft
927 #endif // defined(BOOST_RANGE_DETAIL_MICROSOFT_TEST)