ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/IRC/foreach.hpp
(Generate patch)

Comparing FreeBSDAdmin/IRC/foreach.hpp (file contents):
Revision 1262 by douglas, 2010-03-20T20:07:58-07:00 vs.
Revision 1263 by douglas, 2010-03-21T06:30:15-07:00

# Line 56 | Line 56
56   #define _repeat(count) \
57          for (unsigned _index(0), _end(count); _index != _end; ++_index)
58  
59 < #define _foreach(type, item, set) \
59 > template <typename List_, bool noop = true>
60 > struct StrictIterator;
61 >
62 > template <typename List_>
63 > struct StrictIterator<List_, true> {
64 >        typedef typename List_::iterator Result;
65 > };
66 >
67 > template <typename List_>
68 > struct StrictIterator<const List_, true> {
69 >        typedef typename List_::const_iterator Result;
70 > };
71 >
72 > template <typename List_, bool noop = true>
73 > struct ListTraits;
74 >
75 > template <typename List_>
76 > struct ListTraits<List_, true>
77 > {
78 >        typedef typename StrictIterator<List_>::Result Iterator;
79 >
80 >        static inline Iterator Begin(List_ &arg) {
81 >                return arg.begin();
82 >        }
83 >
84 >        static inline Iterator End(List_ &arg) {
85 >                return arg.end();
86 >        }
87 > };
88 >
89 > #define _foreach_(type, item, set, forall, _typename) \
90          for (bool _stop(true); _stop; ) \
91 <                for (const type& _set = set; _stop; _stop = false) \
92 <                        _forall (type::const_iterator, item, _set.begin(), _set.end())
91 >                for (type &_set = set; _stop; _stop = false) \
92 >                        forall (_typename ListTraits< type >::Iterator, item, ListTraits< type >::Begin(_set), ListTraits< type >::End(_set))
93 >
94 > #define _foreach(type, item, set) \
95 >        _foreach_(type, item, set, _forall, )
96  
97   #define _rforeach(type, item, set) \
98 <        for (bool _stop(true); _stop; ) \
99 <                for (const type& _set = set; _stop; _stop = false) \
100 <                        _rforall (type::const_iterator, item, _set.begin(), _set.end())
98 >        _foreach_(type, item, set, _rforall, )
99 >
100 > #define _tforeach(type, item, set) \
101 >        _foreach_(type, item, set, _forall, typename)
102 >
103 > #define _rtforeach(type, item, set) \
104 >        _foreach_(type, item, set, _rforall, typename)
105  
106   #endif//_foreach_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines