Minor improvement in groups.dox.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_CONCEPT_MAPS_H
20 #define LEMON_CONCEPT_MAPS_H
22 #include <lemon/bits/utility.h>
23 #include <lemon/concept_check.h>
27 ///\brief Map concepts checking classes for testing and documenting.
33 /// \addtogroup concept
36 /// Readable map concept
38 /// Readable map concept.
40 template<typename K, typename T>
44 /// The key type of the map.
46 /// The value type of the map. (The type of objects associated with the keys).
49 /// Returns the value associated with a key.
51 /// Returns the value associated with a key.
52 /// \bug Value shouldn't need to be default constructible.
54 Value operator[](const Key &) const {return Value();}
56 template<typename _ReadMap>
62 typename _ReadMap::Value own_val = m[own_key];
65 ignore_unused_variable_warning(val);
66 ignore_unused_variable_warning(own_val);
67 ignore_unused_variable_warning(key);
70 typename _ReadMap::Key& own_key;
77 /// Writable map concept
79 /// Writable map concept.
81 template<typename K, typename T>
85 /// The key type of the map.
87 /// The value type of the map. (The type of objects associated with the keys).
90 /// Sets the value associated with a key.
91 void set(const Key &,const Value &) {}
93 ///Default constructor
96 template <typename _WriteMap>
99 // No constraints for constructor.
101 m.set(own_key, own_val);
102 ignore_unused_variable_warning(key);
103 ignore_unused_variable_warning(val);
104 ignore_unused_variable_warning(own_key);
105 ignore_unused_variable_warning(own_val);
109 typename _WriteMap::Value own_val;
111 typename _WriteMap::Key& own_key;
117 /// Read/writable map concept
119 /// Read/writable map concept.
121 template<typename K, typename T>
122 class ReadWriteMap : public ReadMap<K,T>,
126 /// The key type of the map.
128 /// The value type of the map. (The type of objects associated with the keys).
131 /// Returns the value associated with a key.
132 Value operator[](const Key &) const {return Value();}
133 /// Sets the value associated with a key.
134 void set(const Key & ,const Value &) {}
136 template<typename _ReadWriteMap>
139 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
140 checkConcept<WriteMap<K, T>, _ReadWriteMap >();
146 /// Dereferable map concept
148 /// Dereferable map concept.
150 /// \todo Rethink this concept.
151 template<typename K, typename T, typename R, typename CR>
152 class ReferenceMap : public ReadWriteMap<K,T>
155 /// Tag for reference maps.
156 typedef True ReferenceMapTag;
157 /// The key type of the map.
159 /// The value type of the map. (The type of objects associated with the keys).
161 /// The reference type of the map.
163 /// The const reference type of the map.
164 typedef CR ConstReference;
170 ///Returns a reference to the value associated with a key.
171 Reference operator[](const Key &) { return tmp; }
172 ///Returns a const reference to the value associated with a key.
173 ConstReference operator[](const Key &) const { return tmp; }
174 /// Sets the value associated with a key.
175 void set(const Key &k,const Value &t) { operator[](k)=t; }
177 template<typename _ReferenceMap>
178 struct ReferenceMapConcept {
181 checkConcept<ReadWriteMap, _ReferenceMap >();
186 m[own_key] = own_val;
187 own_val = m[own_key];
188 m[own_key] = own_ref;
189 own_ref = m[own_key];
192 typename _ReferenceMap::Key& own_key;
193 typename _ReferenceMap::Value& own_val;
194 typename _ReferenceMap::Reference& own_ref;
204 } //namespace concepts
208 #endif // LEMON_CONCEPT_MAPS_H