Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

mapinit.h

00001 #ifndef WFTK_MAPINIT_H 00002 #define WFTK_MAPINIT_H 00003 00004 // a trick to init a map from constant data 00032 namespace wftk { 00033 00034 template<class P> 00035 struct PairInit 00036 { 00037 // We can't implement _any_ constructors if we want 00038 // C-style struct initialization to work. Fortunately, 00039 // the default constructors (and the default operator=()) 00040 // do what we want them to. 00041 00042 typename P::first_type first; 00043 typename P::second_type second; 00044 00045 operator P() const {return P(first, second);} 00046 00047 class const_iterator 00048 { 00049 public: 00050 const_iterator(const PairInit* val) : _val(val) {} 00051 00052 // default copy constructor, operator=() are fine 00053 00054 P operator*() const {return *_val;} 00055 // I->first, I->second will work because of this 00056 const PairInit* operator->() const {return _val;} 00057 00058 const_iterator& operator++() {++_val; return *this;} 00059 const_iterator operator++(int) {const_iterator tmp(*this); operator++(); return tmp;} 00060 00061 bool operator==(const const_iterator& I) const {return _val == I._val;} 00062 bool operator!=(const const_iterator& I) const {return _val != I._val;} 00063 00064 private: 00065 const PairInit* _val; 00066 }; 00067 00068 const_iterator itr(unsigned offset = 0) const {return this + offset;} 00069 }; 00070 00071 } // namespace 00072 00073 #endif // WFTK_MAPINIT_H

Generated Mon Sep 6 21:58:16 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.