Changes in src/helpers.hpp [36166d:d9f51c]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/helpers.hpp
r36166d rd9f51c 194 194 }; 195 195 196 /************ struct to contain simple enumerations ***************/ 197 template <class C> 198 struct enumeration{ 199 enumeration() : max(0) {} 200 enumeration(unsigned int i) : max(i) {} 201 enumeration(const enumeration &src) : 202 there(src.there), 203 back(src.back), 204 max(src.max) 205 {} 206 enumeration &operator=(const enumeration &src){ 207 /* no self-assignment check needed */ 208 there = src.there; 209 back = src.back; 210 max = src.max; 211 return *this; 212 } 213 void add(const C &value){ 214 if(!there.count(value)){ 215 there[value]=max; 216 back[max++]=value; 217 } 218 } 219 unsigned int getMax() const{ 220 return max; 221 } 222 223 map<C,unsigned int> there; 224 map<unsigned int,C> back; 225 private: 226 unsigned int max; 227 }; 228 229 /***** A counter to generate sequential numbers *******************/ 230 struct counter{ 231 inline counter() : count(0){}; 232 inline counter(int i) : count(i){}; 233 inline unsigned int operator()(){ 234 return count++; 235 } 236 private: 237 unsigned int count; 238 }; 239 240 template <class C,class ForwardIterator> 241 enumeration<C> enumerate(ForwardIterator first,ForwardIterator last){ 242 enumeration<C> res; 243 for_each(first,last,bind1st(mem_fun(&enumeration<C>::add),&res)); 244 return res; 245 } 246 196 247 #endif /*HELPERS_HPP_*/
Note:
See TracChangeset
for help on using the changeset viewer.