Ignore:
Timestamp:
Feb 14, 2017, 3:58:01 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
cf97ccb, efd60d67
Parents:
9bb90a86 (diff), e58dfb9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/VectorMap.h

    r9bb90a86 r35cd219  
    3838        typedef const const_value_type* const_pointer;
    3939       
    40         class iterator : public std::iterator< std::bidirectional_iterator_tag,
     40        class iterator : public std::iterator< std::random_access_iterator_tag,
    4141                                               value_type,
    42                                                                                     difference_type,
    43                                                                                         pointer,
    44                                                                                         reference > {
     42                                                                                   difference_type,
     43                                                                                   pointer,
     44                                                                                   reference > {
    4545        friend class VectorMap;
    4646        friend class const_iterator;
     
    7474                iterator operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
    7575
     76                iterator& operator+= (difference_type i) {
     77                        // SHENANIGANS: same reasons as operator++
     78                        new(&data) value_type{ (data.first + i), *(&data.second + i) };
     79                        return *this;
     80                }
     81
     82                iterator operator+ (difference_type i) const { iterator tmp = *this; return tmp += i; }
     83
     84                iterator& operator-= (difference_type i) {
     85                        // SHENANIGANS: same reasons as operator++
     86                        new(&data) value_type{ (data.first - i), *(&data.second - i) };
     87                        return *this;
     88                }
     89
     90                iterator operator- (difference_type i) const { iterator tmp = *this; return tmp -= i; }
     91
     92                difference_type operator- (const iterator& o) const { return data.first - o.data.first; }
     93
     94                value_type operator[] (difference_type i) const {
     95                        // SHENANIGANS: same reasons as operator++
     96                        return value_type{ (data.first + i), *(&data.second + i) };
     97                }
     98
    7699                bool operator== (const iterator& o) const {
    77100                        return data.first == o.data.first && &data.second == &o.data.second;
    78101                }
     102               
    79103                bool operator!= (const iterator& that) const { return !(*this == that); }
     104
     105                bool operator< (const iterator& o) const { return data.first < o.data.first; }
     106
     107                bool operator> (const iterator& o) const { return data.first > o.data.first; }
     108
     109                bool operator<= (const iterator& o) const { return data.first <= o.data.first; }
     110
     111                bool operator>= (const iterator& o) const { return data.first >= o.data.first; }
    80112        };
    81113
     
    118150                const_iterator operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
    119151
     152                const_iterator& operator+= (difference_type i) {
     153                        // SHENANIGANS: same reasons as iterator::operator++
     154                        new(&data) const_value_type{ (data.first + i), *(&data.second + i) };
     155                        return *this;
     156                }
     157
     158                const_iterator operator+ (difference_type i) const {
     159                        const_iterator tmp = *this; return tmp += i;
     160                }
     161
     162                const_iterator& operator-= (difference_type i) {
     163                        // SHENANIGANS: same reasons as iterator::operator++
     164                        new(&data) const_value_type{ (data.first - i), *(&data.second - i) };
     165                        return *this;
     166                }
     167
     168                const_iterator operator- (difference_type i) const {
     169                        const_iterator tmp = *this; return tmp -= i;
     170                }
     171
     172                difference_type operator- (const const_iterator& o) const {
     173                        return data.first - o.data.first;
     174                }
     175
     176                const_value_type operator[] (difference_type i) const {
     177                        // SHENANIGANS: same reasons as iterator::operator++
     178                        return const_value_type{ (data.first + i), *(&data.second + i) };
     179                }
     180
    120181                bool operator== (const const_iterator& o) const {
    121182                        return data.first == o.data.first && &data.second == &o.data.second;
    122183                }
     184               
    123185                bool operator!= (const const_iterator& that) const { return !(*this == that); }
     186
     187                bool operator< (const const_iterator& o) const { return data.first < o.data.first; }
     188
     189                bool operator> (const const_iterator& o) const { return data.first > o.data.first; }
     190
     191                bool operator<= (const const_iterator& o) const { return data.first <= o.data.first; }
     192
     193                bool operator>= (const const_iterator& o) const { return data.first >= o.data.first; }
    124194        };
    125195
     
    163233};
    164234
     235template<typename T>
     236typename VectorMap<T>::iterator operator+ (typename VectorMap<T>::difference_type i,
     237                                           const typename VectorMap<T>::iterator& it) {
     238        return it + i;
     239}
     240
     241template<typename T>
     242typename VectorMap<T>::const_iterator operator+ (typename VectorMap<T>::difference_type i,
     243                                                 const typename VectorMap<T>::const_iterator& it) {
     244        return it + i;
     245}
     246
    165247#endif // _VECTORMAP_H
    166248
Note: See TracChangeset for help on using the changeset viewer.