gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Rename StoreBoolMap to LoggerBoolMap (ticket #34).
0 3 0
default
3 files changed with 20 insertions and 20 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_KRUSKAL_H
20 20
#define LEMON_KRUSKAL_H
21 21

	
22 22
#include <algorithm>
23 23
#include <vector>
24 24
#include <lemon/unionfind.h>
25 25
// #include <lemon/graph_utils.h>
26 26
#include <lemon/maps.h>
27 27

	
28 28
// #include <lemon/radix_sort.h>
29 29

	
30 30
#include <lemon/bits/utility.h>
31 31
#include <lemon/bits/traits.h>
32 32

	
33 33
///\ingroup spantree
34 34
///\file
35 35
///\brief Kruskal's algorithm to compute a minimum cost tree
36 36
///
37 37
///Kruskal's algorithm to compute a minimum cost tree.
38 38
///
39 39

	
40 40
namespace lemon {
41 41

	
42 42
  namespace _kruskal_bits {
43 43

	
44 44
    // Kruskal for directed graphs.
45 45

	
46 46
    template <typename Digraph, typename In, typename Out>
47 47
    typename disable_if<lemon::UndirectedTagIndicator<Digraph>,
48 48
		       typename In::value_type::second_type >::type
49 49
    kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) {
50 50
      typedef typename In::value_type::second_type Value;
51 51
      typedef typename Digraph::template NodeMap<int> IndexMap;
52 52
      typedef typename Digraph::Node Node;
53 53
      
54 54
      IndexMap index(digraph);
55 55
      UnionFind<IndexMap> uf(index);
56 56
      for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) {
57 57
        uf.insert(it);
58 58
      }
59 59
      
60 60
      Value tree_value = 0;
61 61
      for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
62 62
        if (uf.join(digraph.target(it->first),digraph.source(it->first))) {
63 63
          out.set(it->first, true);
64 64
          tree_value += it->second;
65 65
        }
66 66
        else {
67 67
          out.set(it->first, false);
68 68
        }
69 69
      }
70 70
      return tree_value;
71 71
    }
72 72

	
73 73
    // Kruskal for undirected graphs.
74 74

	
75 75
    template <typename Graph, typename In, typename Out>
76 76
    typename enable_if<lemon::UndirectedTagIndicator<Graph>,
77 77
		       typename In::value_type::second_type >::type
78 78
    kruskal(const Graph& graph, const In& in, Out& out,dummy<1> = 1) {
79 79
      typedef typename In::value_type::second_type Value;
80 80
      typedef typename Graph::template NodeMap<int> IndexMap;
81 81
      typedef typename Graph::Node Node;
82 82
      
83 83
      IndexMap index(graph);
84 84
      UnionFind<IndexMap> uf(index);
85 85
      for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
86 86
        uf.insert(it);
87 87
      }
88 88
      
89 89
      Value tree_value = 0;
90 90
      for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
91 91
        if (uf.join(graph.u(it->first),graph.v(it->first))) {
92 92
          out.set(it->first, true);
93 93
          tree_value += it->second;
94 94
        }
95 95
        else {
96 96
          out.set(it->first, false);
97 97
        }
98 98
      }
99 99
      return tree_value;
100 100
    }
101 101

	
102 102

	
103 103
    template <typename Sequence>
104 104
    struct PairComp {
105 105
      typedef typename Sequence::value_type Value;
106 106
      bool operator()(const Value& left, const Value& right) {
107 107
	return left.second < right.second;
108 108
      }
109 109
    };
110 110

	
111 111
    template <typename In, typename Enable = void>
112 112
    struct SequenceInputIndicator {
113 113
      static const bool value = false;
114 114
    };
115 115

	
116 116
    template <typename In>
117 117
    struct SequenceInputIndicator<In, 
118 118
      typename exists<typename In::value_type::first_type>::type> {
119 119
      static const bool value = true;
120 120
    };
121 121

	
122 122
    template <typename In, typename Enable = void>
123 123
    struct MapInputIndicator {
124 124
      static const bool value = false;
125 125
    };
126 126

	
127 127
    template <typename In>
128 128
    struct MapInputIndicator<In, 
129 129
      typename exists<typename In::Value>::type> {
130 130
      static const bool value = true;
131 131
    };
132 132

	
133 133
    template <typename In, typename Enable = void>
134 134
    struct SequenceOutputIndicator {
135 135
      static const bool value = false;
136 136
    };
137 137
 
138 138
    template <typename Out>
139 139
    struct SequenceOutputIndicator<Out, 
140 140
      typename exists<typename Out::value_type>::type> {
141 141
      static const bool value = true;
142 142
    };
143 143

	
144 144
    template <typename Out, typename Enable = void>
145 145
    struct MapOutputIndicator {
146 146
      static const bool value = false;
147 147
    };
148 148

	
149 149
    template <typename Out>
150 150
    struct MapOutputIndicator<Out, 
151 151
      typename exists<typename Out::Value>::type> {
152 152
      static const bool value = true;
153 153
    };
154 154

	
155 155
    template <typename In, typename InEnable = void>
156 156
    struct KruskalValueSelector {};
157 157

	
158 158
    template <typename In>
159 159
    struct KruskalValueSelector<In,
160 160
      typename enable_if<SequenceInputIndicator<In>, void>::type> 
161 161
    {
162 162
      typedef typename In::value_type::second_type Value;
163 163
    };    
164 164

	
165 165
    template <typename In>
166 166
    struct KruskalValueSelector<In,
167 167
      typename enable_if<MapInputIndicator<In>, void>::type> 
168 168
    {
169 169
      typedef typename In::Value Value;
170 170
    };    
171 171
    
172 172
    template <typename Graph, typename In, typename Out,
173 173
              typename InEnable = void>
174 174
    struct KruskalInputSelector {};
175 175

	
176 176
    template <typename Graph, typename In, typename Out,
177 177
              typename InEnable = void>
178 178
    struct KruskalOutputSelector {};
179 179
    
180 180
    template <typename Graph, typename In, typename Out>
181 181
    struct KruskalInputSelector<Graph, In, Out,
182 182
      typename enable_if<SequenceInputIndicator<In>, void>::type > 
183 183
    {
184 184
      typedef typename In::value_type::second_type Value;
185 185

	
186 186
      static Value kruskal(const Graph& graph, const In& in, Out& out) {
187 187
        return KruskalOutputSelector<Graph, In, Out>::
188 188
          kruskal(graph, in, out);
189 189
      }
190 190

	
191 191
    };
192 192

	
193 193
    template <typename Graph, typename In, typename Out>
194 194
    struct KruskalInputSelector<Graph, In, Out,
195 195
      typename enable_if<MapInputIndicator<In>, void>::type > 
196 196
    {
197 197
      typedef typename In::Value Value;
198 198
      static Value kruskal(const Graph& graph, const In& in, Out& out) {
199 199
        typedef typename In::Key MapArc;
200 200
        typedef typename In::Value Value;
201 201
        typedef typename ItemSetTraits<Graph, MapArc>::ItemIt MapArcIt;
202 202
        typedef std::vector<std::pair<MapArc, Value> > Sequence;
203 203
        Sequence seq;
204 204
        
205 205
        for (MapArcIt it(graph); it != INVALID; ++it) {
206 206
          seq.push_back(std::make_pair(it, in[it]));
207 207
        }
208 208

	
209 209
        std::sort(seq.begin(), seq.end(), PairComp<Sequence>());
210 210
        return KruskalOutputSelector<Graph, Sequence, Out>::
211 211
          kruskal(graph, seq, out);
212 212
      }
213 213
    };
214 214

	
215 215
    template <typename T>
216 216
    struct RemoveConst {
217 217
      typedef T type;
218 218
    };
219 219

	
220 220
    template <typename T>
221 221
    struct RemoveConst<const T> {
222 222
      typedef T type;
223 223
    };
224 224

	
225 225
    template <typename Graph, typename In, typename Out>
226 226
    struct KruskalOutputSelector<Graph, In, Out,
227 227
      typename enable_if<SequenceOutputIndicator<Out>, void>::type > 
228 228
    {
229 229
      typedef typename In::value_type::second_type Value;
230 230

	
231 231
      static Value kruskal(const Graph& graph, const In& in, Out& out) {
232
        typedef StoreBoolMap<typename RemoveConst<Out>::type> Map;
232
        typedef LoggerBoolMap<typename RemoveConst<Out>::type> Map;
233 233
        Map map(out);
234 234
        return _kruskal_bits::kruskal(graph, in, map);
235 235
      }
236 236

	
237 237
    };
238 238

	
239 239
    template <typename Graph, typename In, typename Out>
240 240
    struct KruskalOutputSelector<Graph, In, Out,
241 241
      typename enable_if<MapOutputIndicator<Out>, void>::type > 
242 242
    {
243 243
      typedef typename In::value_type::second_type Value;
244 244

	
245 245
      static Value kruskal(const Graph& graph, const In& in, Out& out) {
246 246
        return _kruskal_bits::kruskal(graph, in, out);
247 247
      }
248 248
    };
249 249

	
250 250
  }
251 251

	
252 252
  /// \ingroup spantree
253 253
  ///
254 254
  /// \brief Kruskal's algorithm to find a minimum cost tree of a graph.
255 255
  ///
256 256
  /// This function runs Kruskal's algorithm to find a minimum cost tree.
257 257
  /// Due to some C++ hacking, it accepts various input and output types.
258 258
  ///
259 259
  /// \param g The graph the algorithm runs on.
260 260
  /// It can be either \ref concepts::Digraph "directed" or 
261 261
  /// \ref concepts::Graph "undirected".
262 262
  /// If the graph is directed, the algorithm consider it to be 
263 263
  /// undirected by disregarding the direction of the arcs.
264 264
  ///
265 265
  /// \param in This object is used to describe the arc costs. It can be one
266 266
  /// of the following choices.
267 267
  /// - An STL compatible 'Forward Container' with
268 268
  /// <tt>std::pair<GR::Edge,X></tt> or
269 269
  /// <tt>std::pair<GR::Arc,X></tt> as its <tt>value_type</tt>, where
270 270
  /// \c X is the type of the costs. The pairs indicates the arcs
271 271
  /// along with the assigned cost. <em>They must be in a
272 272
  /// cost-ascending order.</em>
273 273
  /// - Any readable Arc map. The values of the map indicate the arc costs.
274 274
  ///
275 275
  /// \retval out Here we also have a choise.
276 276
  /// - It can be a writable \c bool arc map.  After running the
277 277
  /// algorithm this will contain the found minimum cost spanning
278 278
  /// tree: the value of an arc will be set to \c true if it belongs
279 279
  /// to the tree, otherwise it will be set to \c false. The value of
280 280
  /// each arc will be set exactly once.
281 281
  /// - It can also be an iteraror of an STL Container with
282 282
  /// <tt>GR::Edge</tt> or <tt>GR::Arc</tt> as its
283 283
  /// <tt>value_type</tt>.  The algorithm copies the elements of the
284 284
  /// found tree into this sequence.  For example, if we know that the
285 285
  /// spanning tree of the graph \c g has say 53 arcs, then we can
286 286
  /// put its arcs into an STL vector \c tree with a code like this.
287 287
  ///\code
288 288
  /// std::vector<Arc> tree(53);
289 289
  /// kruskal(g,cost,tree.begin());
290 290
  ///\endcode
291 291
  /// Or if we don't know in advance the size of the tree, we can
292 292
  /// write this.  
293 293
  ///\code std::vector<Arc> tree;
294 294
  /// kruskal(g,cost,std::back_inserter(tree)); 
295 295
  ///\endcode
296 296
  ///
297 297
  /// \return The total cost of the found tree.
298 298
  ///
299 299
  /// \warning If kruskal runs on an be consistent of using the same
300 300
  /// Arc type for input and output.
301 301
  ///
302 302

	
303 303
#ifdef DOXYGEN
304 304
  template <class Graph, class In, class Out>
305 305
  Value kruskal(GR const& g, const In& in, Out& out)
306 306
#else 
307 307
  template <class Graph, class In, class Out>
308 308
  inline typename _kruskal_bits::KruskalValueSelector<In>::Value 
309 309
  kruskal(const Graph& graph, const In& in, Out& out) 
310 310
#endif
311 311
  {
312 312
    return _kruskal_bits::KruskalInputSelector<Graph, In, Out>::
313 313
      kruskal(graph, in, out);
314 314
  }
315 315

	
316 316
 
317 317
  
318 318

	
319 319
  template <class Graph, class In, class Out>
320 320
  inline typename _kruskal_bits::KruskalValueSelector<In>::Value
321 321
  kruskal(const Graph& graph, const In& in, const Out& out)
322 322
  {
323 323
    return _kruskal_bits::KruskalInputSelector<Graph, In, const Out>::
324 324
      kruskal(graph, in, out);
325 325
  }  
326 326

	
327 327
} //namespace lemon
328 328

	
329 329
#endif //LEMON_KRUSKAL_H
Ignore white space 12288 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_MAPS_H
20 20
#define LEMON_MAPS_H
21 21

	
22 22
#include <iterator>
23 23
#include <functional>
24 24
#include <vector>
25 25

	
26 26
#include <lemon/bits/utility.h>
27 27
#include <lemon/bits/traits.h>
28 28

	
29 29
///\file
30 30
///\ingroup maps
31 31
///\brief Miscellaneous property maps
32 32

	
33 33
#include <map>
34 34

	
35 35
namespace lemon {
36 36

	
37 37
  /// \addtogroup maps
38 38
  /// @{
39 39

	
40 40
  /// Base class of maps.
41 41

	
42 42
  /// Base class of maps. It provides the necessary type definitions
43 43
  /// required by the map %concepts.
44 44
  template<typename K, typename V>
45 45
  class MapBase {
46 46
  public:
47 47
    /// \biref The key type of the map.
48 48
    typedef K Key;
49 49
    /// \brief The value type of the map.
50 50
    /// (The type of objects associated with the keys).
51 51
    typedef V Value;
52 52
  };
53 53

	
54 54

	
55 55
  /// Null map. (a.k.a. DoNothingMap)
56 56

	
57 57
  /// This map can be used if you have to provide a map only for
58 58
  /// its type definitions, or if you have to provide a writable map,
59 59
  /// but data written to it is not required (i.e. it will be sent to
60 60
  /// <tt>/dev/null</tt>).
61 61
  /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
62 62
  ///
63 63
  /// \sa ConstMap
64 64
  template<typename K, typename V>
65 65
  class NullMap : public MapBase<K, V> {
66 66
  public:
67 67
    typedef MapBase<K, V> Parent;
68 68
    typedef typename Parent::Key Key;
69 69
    typedef typename Parent::Value Value;
70 70

	
71 71
    /// Gives back a default constructed element.
72 72
    Value operator[](const Key&) const { return Value(); }
73 73
    /// Absorbs the value.
74 74
    void set(const Key&, const Value&) {}
75 75
  };
76 76

	
77 77
  /// Returns a \ref NullMap class
78 78

	
79 79
  /// This function just returns a \ref NullMap class.
80 80
  /// \relates NullMap
81 81
  template <typename K, typename V>
82 82
  NullMap<K, V> nullMap() {
83 83
    return NullMap<K, V>();
84 84
  }
85 85

	
86 86

	
87 87
  /// Constant map.
88 88

	
89 89
  /// This \ref concepts::ReadMap "readable map" assigns a specified
90 90
  /// value to each key.
91 91
  ///
92 92
  /// In other aspects it is equivalent to \ref NullMap.
93 93
  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
94 94
  /// concept, but it absorbs the data written to it.
95 95
  ///
96 96
  /// The simplest way of using this map is through the constMap()
97 97
  /// function.
98 98
  ///
99 99
  /// \sa NullMap
100 100
  /// \sa IdentityMap
101 101
  template<typename K, typename V>
102 102
  class ConstMap : public MapBase<K, V> {
103 103
  private:
104 104
    V _value;
105 105
  public:
106 106
    typedef MapBase<K, V> Parent;
107 107
    typedef typename Parent::Key Key;
108 108
    typedef typename Parent::Value Value;
109 109

	
110 110
    /// Default constructor
111 111

	
112 112
    /// Default constructor.
113 113
    /// The value of the map will be default constructed.
114 114
    ConstMap() {}
115 115

	
116 116
    /// Constructor with specified initial value
117 117

	
118 118
    /// Constructor with specified initial value.
119 119
    /// \param v The initial value of the map.
120 120
    ConstMap(const Value &v) : _value(v) {}
121 121

	
122 122
    /// Gives back the specified value.
123 123
    Value operator[](const Key&) const { return _value; }
124 124

	
125 125
    /// Absorbs the value.
126 126
    void set(const Key&, const Value&) {}
127 127

	
128 128
    /// Sets the value that is assigned to each key.
129 129
    void setAll(const Value &v) {
130 130
      _value = v;
131 131
    }
132 132

	
133 133
    template<typename V1>
134 134
    ConstMap(const ConstMap<K, V1> &, const Value &v) : _value(v) {}
135 135
  };
136 136

	
137 137
  /// Returns a \ref ConstMap class
138 138

	
139 139
  /// This function just returns a \ref ConstMap class.
140 140
  /// \relates ConstMap
141 141
  template<typename K, typename V>
142 142
  inline ConstMap<K, V> constMap(const V &v) {
143 143
    return ConstMap<K, V>(v);
144 144
  }
145 145

	
146 146
  template<typename K, typename V>
147 147
  inline ConstMap<K, V> constMap() {
148 148
    return ConstMap<K, V>();
149 149
  }
150 150

	
151 151

	
152 152
  template<typename T, T v>
153 153
  struct Const {};
154 154

	
155 155
  /// Constant map with inlined constant value.
156 156

	
157 157
  /// This \ref concepts::ReadMap "readable map" assigns a specified
158 158
  /// value to each key.
159 159
  ///
160 160
  /// In other aspects it is equivalent to \ref NullMap.
161 161
  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
162 162
  /// concept, but it absorbs the data written to it.
163 163
  ///
164 164
  /// The simplest way of using this map is through the constMap()
165 165
  /// function.
166 166
  ///
167 167
  /// \sa NullMap
168 168
  /// \sa IdentityMap
169 169
  template<typename K, typename V, V v>
170 170
  class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
171 171
  public:
172 172
    typedef MapBase<K, V> Parent;
173 173
    typedef typename Parent::Key Key;
174 174
    typedef typename Parent::Value Value;
175 175

	
176 176
    /// Constructor.
177 177
    ConstMap() {}
178 178

	
179 179
    /// Gives back the specified value.
180 180
    Value operator[](const Key&) const { return v; }
181 181

	
182 182
    /// Absorbs the value.
183 183
    void set(const Key&, const Value&) {}
184 184
  };
185 185

	
186 186
  /// Returns a \ref ConstMap class with inlined constant value
187 187

	
188 188
  /// This function just returns a \ref ConstMap class with inlined
189 189
  /// constant value.
190 190
  /// \relates ConstMap
191 191
  template<typename K, typename V, V v>
192 192
  inline ConstMap<K, Const<V, v> > constMap() {
193 193
    return ConstMap<K, Const<V, v> >();
194 194
  }
195 195

	
196 196

	
197 197
  /// Identity map.
198 198

	
199 199
  /// This \ref concepts::ReadMap "read-only map" gives back the given
200 200
  /// key as value without any modification.
201 201
  ///
202 202
  /// \sa ConstMap
203 203
  template <typename T>
204 204
  class IdentityMap : public MapBase<T, T> {
205 205
  public:
206 206
    typedef MapBase<T, T> Parent;
207 207
    typedef typename Parent::Key Key;
208 208
    typedef typename Parent::Value Value;
209 209

	
210 210
    /// Gives back the given value without any modification.
211 211
    Value operator[](const Key &k) const {
212 212
      return k;
213 213
    }
214 214
  };
215 215

	
216 216
  /// Returns an \ref IdentityMap class
217 217

	
218 218
  /// This function just returns an \ref IdentityMap class.
219 219
  /// \relates IdentityMap
220 220
  template<typename T>
221 221
  inline IdentityMap<T> identityMap() {
222 222
    return IdentityMap<T>();
223 223
  }
224 224

	
225 225

	
226 226
  /// \brief Map for storing values for integer keys from the range
227 227
  /// <tt>[0..size-1]</tt>.
228 228
  ///
229 229
  /// This map is essentially a wrapper for \c std::vector. It assigns
230 230
  /// values to integer keys from the range <tt>[0..size-1]</tt>.
231 231
  /// It can be used with some data structures, for example
232 232
  /// \ref UnionFind, \ref BinHeap, when the used items are small
233 233
  /// integers. This map conforms the \ref concepts::ReferenceMap
234 234
  /// "ReferenceMap" concept.
235 235
  ///
236 236
  /// The simplest way of using this map is through the rangeMap()
237 237
  /// function.
238 238
  template <typename V>
239 239
  class RangeMap : public MapBase<int, V> {
240 240
    template <typename V1>
241 241
    friend class RangeMap;
242 242
  private:
243 243

	
244 244
    typedef std::vector<V> Vector;
245 245
    Vector _vector;
246 246

	
247 247
  public:
248 248

	
249 249
    typedef MapBase<int, V> Parent;
250 250
    /// Key type
251 251
    typedef typename Parent::Key Key;
252 252
    /// Value type
253 253
    typedef typename Parent::Value Value;
254 254
    /// Reference type
255 255
    typedef typename Vector::reference Reference;
256 256
    /// Const reference type
257 257
    typedef typename Vector::const_reference ConstReference;
258 258

	
259 259
    typedef True ReferenceMapTag;
260 260

	
261 261
  public:
262 262

	
263 263
    /// Constructor with specified default value.
264 264
    RangeMap(int size = 0, const Value &value = Value())
265 265
      : _vector(size, value) {}
266 266

	
267 267
    /// Constructs the map from an appropriate \c std::vector.
268 268
    template <typename V1>
269 269
    RangeMap(const std::vector<V1>& vector)
270 270
      : _vector(vector.begin(), vector.end()) {}
271 271

	
272 272
    /// Constructs the map from another \ref RangeMap.
273 273
    template <typename V1>
274 274
    RangeMap(const RangeMap<V1> &c)
275 275
      : _vector(c._vector.begin(), c._vector.end()) {}
276 276

	
277 277
    /// Returns the size of the map.
278 278
    int size() {
279 279
      return _vector.size();
280 280
    }
281 281

	
282 282
    /// Resizes the map.
283 283

	
284 284
    /// Resizes the underlying \c std::vector container, so changes the
285 285
    /// keyset of the map.
286 286
    /// \param size The new size of the map. The new keyset will be the
287 287
    /// range <tt>[0..size-1]</tt>.
288 288
    /// \param value The default value to assign to the new keys.
289 289
    void resize(int size, const Value &value = Value()) {
290 290
      _vector.resize(size, value);
291 291
    }
292 292

	
293 293
  private:
294 294

	
295 295
    RangeMap& operator=(const RangeMap&);
296 296

	
297 297
  public:
298 298

	
299 299
    ///\e
300 300
    Reference operator[](const Key &k) {
301 301
      return _vector[k];
302 302
    }
303 303

	
304 304
    ///\e
305 305
    ConstReference operator[](const Key &k) const {
306 306
      return _vector[k];
307 307
    }
308 308

	
309 309
    ///\e
310 310
    void set(const Key &k, const Value &v) {
311 311
      _vector[k] = v;
312 312
    }
313 313
  };
314 314

	
315 315
  /// Returns a \ref RangeMap class
316 316

	
317 317
  /// This function just returns a \ref RangeMap class.
318 318
  /// \relates RangeMap
319 319
  template<typename V>
320 320
  inline RangeMap<V> rangeMap(int size = 0, const V &value = V()) {
321 321
    return RangeMap<V>(size, value);
322 322
  }
323 323

	
324 324
  /// \brief Returns a \ref RangeMap class created from an appropriate
325 325
  /// \c std::vector
326 326

	
327 327
  /// This function just returns a \ref RangeMap class created from an
328 328
  /// appropriate \c std::vector.
329 329
  /// \relates RangeMap
330 330
  template<typename V>
331 331
  inline RangeMap<V> rangeMap(const std::vector<V> &vector) {
332 332
    return RangeMap<V>(vector);
333 333
  }
334 334

	
335 335

	
336 336
  /// Map type based on \c std::map
337 337

	
338 338
  /// This map is essentially a wrapper for \c std::map with addition
339 339
  /// that you can specify a default value for the keys that are not
340 340
  /// stored actually. This value can be different from the default
341 341
  /// contructed value (i.e. \c %Value()).
342 342
  /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
343 343
  /// concept.
344 344
  ///
345 345
  /// This map is useful if a default value should be assigned to most of
346 346
  /// the keys and different values should be assigned only to a few
347 347
  /// keys (i.e. the map is "sparse").
348 348
  /// The name of this type also refers to this important usage.
349 349
  ///
350 350
  /// Apart form that this map can be used in many other cases since it
351 351
  /// is based on \c std::map, which is a general associative container.
352 352
  /// However keep in mind that it is usually not as efficient as other
353 353
  /// maps.
354 354
  ///
355 355
  /// The simplest way of using this map is through the sparseMap()
356 356
  /// function.
357 357
  template <typename K, typename V, typename Compare = std::less<K> >
358 358
  class SparseMap : public MapBase<K, V> {
359 359
    template <typename K1, typename V1, typename C1>
360 360
    friend class SparseMap;
361 361
  public:
362 362

	
363 363
    typedef MapBase<K, V> Parent;
364 364
    /// Key type
365 365
    typedef typename Parent::Key Key;
366 366
    /// Value type
367 367
    typedef typename Parent::Value Value;
368 368
    /// Reference type
369 369
    typedef Value& Reference;
370 370
    /// Const reference type
371 371
    typedef const Value& ConstReference;
372 372

	
373 373
    typedef True ReferenceMapTag;
374 374

	
375 375
  private:
376 376

	
377 377
    typedef std::map<K, V, Compare> Map;
378 378
    Map _map;
379 379
    Value _value;
380 380

	
381 381
  public:
382 382

	
383 383
    /// \brief Constructor with specified default value.
384 384
    SparseMap(const Value &value = Value()) : _value(value) {}
385 385
    /// \brief Constructs the map from an appropriate \c std::map, and
386 386
    /// explicitly specifies a default value.
387 387
    template <typename V1, typename Comp1>
388 388
    SparseMap(const std::map<Key, V1, Comp1> &map,
389 389
              const Value &value = Value())
390 390
      : _map(map.begin(), map.end()), _value(value) {}
391 391

	
392 392
    /// \brief Constructs the map from another \ref SparseMap.
393 393
    template<typename V1, typename Comp1>
394 394
    SparseMap(const SparseMap<Key, V1, Comp1> &c)
395 395
      : _map(c._map.begin(), c._map.end()), _value(c._value) {}
396 396

	
397 397
  private:
398 398

	
399 399
    SparseMap& operator=(const SparseMap&);
400 400

	
401 401
  public:
402 402

	
403 403
    ///\e
404 404
    Reference operator[](const Key &k) {
405 405
      typename Map::iterator it = _map.lower_bound(k);
406 406
      if (it != _map.end() && !_map.key_comp()(k, it->first))
407 407
	return it->second;
408 408
      else
409 409
	return _map.insert(it, std::make_pair(k, _value))->second;
410 410
    }
411 411

	
412 412
    ///\e
413 413
    ConstReference operator[](const Key &k) const {
414 414
      typename Map::const_iterator it = _map.find(k);
415 415
      if (it != _map.end())
416 416
	return it->second;
417 417
      else
418 418
	return _value;
419 419
    }
420 420

	
421 421
    ///\e
422 422
    void set(const Key &k, const Value &v) {
423 423
      typename Map::iterator it = _map.lower_bound(k);
424 424
      if (it != _map.end() && !_map.key_comp()(k, it->first))
425 425
	it->second = v;
426 426
      else
427 427
	_map.insert(it, std::make_pair(k, v));
428 428
    }
429 429

	
430 430
    ///\e
431 431
    void setAll(const Value &v) {
432 432
      _value = v;
433 433
      _map.clear();
434 434
    }
435 435
  };
436 436

	
437 437
  /// Returns a \ref SparseMap class
438 438

	
439 439
  /// This function just returns a \ref SparseMap class with specified
440 440
  /// default value.
441 441
  /// \relates SparseMap
442 442
  template<typename K, typename V, typename Compare>
443 443
  inline SparseMap<K, V, Compare> sparseMap(const V& value = V()) {
444 444
    return SparseMap<K, V, Compare>(value);
445 445
  }
446 446

	
447 447
  template<typename K, typename V>
448 448
  inline SparseMap<K, V, std::less<K> > sparseMap(const V& value = V()) {
449 449
    return SparseMap<K, V, std::less<K> >(value);
450 450
  }
451 451

	
452 452
  /// \brief Returns a \ref SparseMap class created from an appropriate
453 453
  /// \c std::map
454 454

	
455 455
  /// This function just returns a \ref SparseMap class created from an
456 456
  /// appropriate \c std::map.
457 457
  /// \relates SparseMap
458 458
  template<typename K, typename V, typename Compare>
459 459
  inline SparseMap<K, V, Compare>
460 460
    sparseMap(const std::map<K, V, Compare> &map, const V& value = V())
461 461
  {
462 462
    return SparseMap<K, V, Compare>(map, value);
463 463
  }
464 464

	
465 465
  /// @}
466 466

	
467 467
  /// \addtogroup map_adaptors
468 468
  /// @{
469 469

	
470 470
  /// Composition of two maps
471 471

	
472 472
  /// This \ref concepts::ReadMap "read-only map" returns the
473 473
  /// composition of two given maps. That is to say, if \c m1 is of
474 474
  /// type \c M1 and \c m2 is of \c M2, then for
475 475
  /// \code
476 476
  ///   ComposeMap<M1, M2> cm(m1,m2);
477 477
  /// \endcode
478 478
  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
479 479
  ///
480 480
  /// The \c Key type of the map is inherited from \c M2 and the
481 481
  /// \c Value type is from \c M1.
482 482
  /// \c M2::Value must be convertible to \c M1::Key.
483 483
  ///
484 484
  /// The simplest way of using this map is through the composeMap()
485 485
  /// function.
486 486
  ///
487 487
  /// \sa CombineMap
488 488
  ///
489 489
  /// \todo Check the requirements.
490 490
  template <typename M1, typename M2>
491 491
  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
492 492
    const M1 &_m1;
493 493
    const M2 &_m2;
494 494
  public:
495 495
    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
496 496
    typedef typename Parent::Key Key;
497 497
    typedef typename Parent::Value Value;
498 498

	
499 499
    /// Constructor
500 500
    ComposeMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
501 501

	
502 502
    /// \e
503 503
    typename MapTraits<M1>::ConstReturnValue
504 504
    operator[](const Key &k) const { return _m1[_m2[k]]; }
505 505
  };
506 506

	
507 507
  /// Returns a \ref ComposeMap class
508 508

	
509 509
  /// This function just returns a \ref ComposeMap class.
510 510
  ///
511 511
  /// If \c m1 and \c m2 are maps and the \c Value type of \c m2 is
512 512
  /// convertible to the \c Key of \c m1, then <tt>composeMap(m1,m2)[x]</tt>
513 513
  /// will be equal to <tt>m1[m2[x]]</tt>.
514 514
  ///
515 515
  /// \relates ComposeMap
516 516
  template <typename M1, typename M2>
517 517
  inline ComposeMap<M1, M2> composeMap(const M1 &m1, const M2 &m2) {
518 518
    return ComposeMap<M1, M2>(m1, m2);
519 519
  }
520 520

	
521 521

	
522 522
  /// Combination of two maps using an STL (binary) functor.
523 523

	
524 524
  /// This \ref concepts::ReadMap "read-only map" takes two maps and a
525 525
  /// binary functor and returns the combination of the two given maps
526 526
  /// using the functor.
527 527
  /// That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2
528 528
  /// and \c f is of \c F, then for
529 529
  /// \code
530 530
  ///   CombineMap<M1,M2,F,V> cm(m1,m2,f);
531 531
  /// \endcode
532 532
  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>.
533 533
  ///
534 534
  /// The \c Key type of the map is inherited from \c M1 (\c M1::Key
535 535
  /// must be convertible to \c M2::Key) and the \c Value type is \c V.
536 536
  /// \c M2::Value and \c M1::Value must be convertible to the
537 537
  /// corresponding input parameter of \c F and the return type of \c F
538 538
  /// must be convertible to \c V.
539 539
  ///
540 540
  /// The simplest way of using this map is through the combineMap()
541 541
  /// function.
542 542
  ///
543 543
  /// \sa ComposeMap
544 544
  ///
545 545
  /// \todo Check the requirements.
546 546
  template<typename M1, typename M2, typename F,
547 547
	   typename V = typename F::result_type>
548 548
  class CombineMap : public MapBase<typename M1::Key, V> {
549 549
    const M1 &_m1;
550 550
    const M2 &_m2;
551 551
    F _f;
552 552
  public:
553 553
    typedef MapBase<typename M1::Key, V> Parent;
554 554
    typedef typename Parent::Key Key;
555 555
    typedef typename Parent::Value Value;
556 556

	
557 557
    /// Constructor
558 558
    CombineMap(const M1 &m1, const M2 &m2, const F &f = F())
559 559
      : _m1(m1), _m2(m2), _f(f) {}
560 560
    /// \e
561 561
    Value operator[](const Key &k) const { return _f(_m1[k],_m2[k]); }
562 562
  };
563 563

	
564 564
  /// Returns a \ref CombineMap class
565 565

	
566 566
  /// This function just returns a \ref CombineMap class.
567 567
  ///
568 568
  /// For example, if \c m1 and \c m2 are both maps with \c double
569 569
  /// values, then
570 570
  /// \code
571 571
  ///   combineMap(m1,m2,std::plus<double>())
572 572
  /// \endcode
573 573
  /// is equivalent to
574 574
  /// \code
575 575
  ///   addMap(m1,m2)
576 576
  /// \endcode
577 577
  ///
578 578
  /// This function is specialized for adaptable binary function
579 579
  /// classes and C++ functions.
580 580
  ///
581 581
  /// \relates CombineMap
582 582
  template<typename M1, typename M2, typename F, typename V>
583 583
  inline CombineMap<M1, M2, F, V>
584 584
  combineMap(const M1 &m1, const M2 &m2, const F &f) {
585 585
    return CombineMap<M1, M2, F, V>(m1,m2,f);
586 586
  }
587 587

	
588 588
  template<typename M1, typename M2, typename F>
589 589
  inline CombineMap<M1, M2, F, typename F::result_type>
590 590
  combineMap(const M1 &m1, const M2 &m2, const F &f) {
591 591
    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
592 592
  }
593 593

	
594 594
  template<typename M1, typename M2, typename K1, typename K2, typename V>
595 595
  inline CombineMap<M1, M2, V (*)(K1, K2), V>
596 596
  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
597 597
    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
598 598
  }
599 599

	
600 600

	
601 601
  /// Converts an STL style (unary) functor to a map
602 602

	
603 603
  /// This \ref concepts::ReadMap "read-only map" returns the value
604 604
  /// of a given functor. Actually, it just wraps the functor and
605 605
  /// provides the \c Key and \c Value typedefs.
606 606
  ///
607 607
  /// Template parameters \c K and \c V will become its \c Key and
608 608
  /// \c Value. In most cases they have to be given explicitly because
609 609
  /// a functor typically does not provide \c argument_type and
610 610
  /// \c result_type typedefs.
611 611
  /// Parameter \c F is the type of the used functor.
612 612
  ///
613 613
  /// The simplest way of using this map is through the functorToMap()
614 614
  /// function.
615 615
  ///
616 616
  /// \sa MapToFunctor
617 617
  template<typename F,
618 618
	   typename K = typename F::argument_type,
619 619
	   typename V = typename F::result_type>
620 620
  class FunctorToMap : public MapBase<K, V> {
621 621
    F _f;
622 622
  public:
623 623
    typedef MapBase<K, V> Parent;
624 624
    typedef typename Parent::Key Key;
625 625
    typedef typename Parent::Value Value;
626 626

	
627 627
    /// Constructor
628 628
    FunctorToMap(const F &f = F()) : _f(f) {}
629 629
    /// \e
630 630
    Value operator[](const Key &k) const { return _f(k); }
631 631
  };
632 632

	
633 633
  /// Returns a \ref FunctorToMap class
634 634

	
635 635
  /// This function just returns a \ref FunctorToMap class.
636 636
  ///
637 637
  /// This function is specialized for adaptable binary function
638 638
  /// classes and C++ functions.
639 639
  ///
640 640
  /// \relates FunctorToMap
641 641
  template<typename K, typename V, typename F>
642 642
  inline FunctorToMap<F, K, V> functorToMap(const F &f) {
643 643
    return FunctorToMap<F, K, V>(f);
644 644
  }
645 645

	
646 646
  template <typename F>
647 647
  inline FunctorToMap<F, typename F::argument_type, typename F::result_type>
648 648
    functorToMap(const F &f)
649 649
  {
650 650
    return FunctorToMap<F, typename F::argument_type,
651 651
      typename F::result_type>(f);
652 652
  }
653 653

	
654 654
  template <typename K, typename V>
655 655
  inline FunctorToMap<V (*)(K), K, V> functorToMap(V (*f)(K)) {
656 656
    return FunctorToMap<V (*)(K), K, V>(f);
657 657
  }
658 658

	
659 659

	
660 660
  /// Converts a map to an STL style (unary) functor
661 661

	
662 662
  /// This class converts a map to an STL style (unary) functor.
663 663
  /// That is it provides an <tt>operator()</tt> to read its values.
664 664
  ///
665 665
  /// For the sake of convenience it also works as a usual
666 666
  /// \ref concepts::ReadMap "readable map", i.e. <tt>operator[]</tt>
667 667
  /// and the \c Key and \c Value typedefs also exist.
668 668
  ///
669 669
  /// The simplest way of using this map is through the mapToFunctor()
670 670
  /// function.
671 671
  ///
672 672
  ///\sa FunctorToMap
673 673
  template <typename M>
674 674
  class MapToFunctor : public MapBase<typename M::Key, typename M::Value> {
675 675
    const M &_m;
676 676
  public:
677 677
    typedef MapBase<typename M::Key, typename M::Value> Parent;
678 678
    typedef typename Parent::Key Key;
679 679
    typedef typename Parent::Value Value;
680 680

	
681 681
    typedef typename Parent::Key argument_type;
682 682
    typedef typename Parent::Value result_type;
683 683

	
684 684
    /// Constructor
685 685
    MapToFunctor(const M &m) : _m(m) {}
686 686
    /// \e
687 687
    Value operator()(const Key &k) const { return _m[k]; }
688 688
    /// \e
689 689
    Value operator[](const Key &k) const { return _m[k]; }
690 690
  };
691 691

	
692 692
  /// Returns a \ref MapToFunctor class
693 693

	
694 694
  /// This function just returns a \ref MapToFunctor class.
695 695
  /// \relates MapToFunctor
696 696
  template<typename M>
697 697
  inline MapToFunctor<M> mapToFunctor(const M &m) {
698 698
    return MapToFunctor<M>(m);
699 699
  }
700 700

	
701 701

	
702 702
  /// \brief Map adaptor to convert the \c Value type of a map to
703 703
  /// another type using the default conversion.
704 704

	
705 705
  /// Map adaptor to convert the \c Value type of a \ref concepts::ReadMap
706 706
  /// "readable map" to another type using the default conversion.
707 707
  /// The \c Key type of it is inherited from \c M and the \c Value
708 708
  /// type is \c V.
709 709
  /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
710 710
  ///
711 711
  /// The simplest way of using this map is through the convertMap()
712 712
  /// function.
713 713
  template <typename M, typename V>
714 714
  class ConvertMap : public MapBase<typename M::Key, V> {
715 715
    const M &_m;
716 716
  public:
717 717
    typedef MapBase<typename M::Key, V> Parent;
718 718
    typedef typename Parent::Key Key;
719 719
    typedef typename Parent::Value Value;
720 720

	
721 721
    /// Constructor
722 722

	
723 723
    /// Constructor.
724 724
    /// \param m The underlying map.
725 725
    ConvertMap(const M &m) : _m(m) {}
726 726

	
727 727
    /// \e
728 728
    Value operator[](const Key &k) const { return _m[k]; }
729 729
  };
730 730

	
731 731
  /// Returns a \ref ConvertMap class
732 732

	
733 733
  /// This function just returns a \ref ConvertMap class.
734 734
  /// \relates ConvertMap
735 735
  template<typename V, typename M>
736 736
  inline ConvertMap<M, V> convertMap(const M &map) {
737 737
    return ConvertMap<M, V>(map);
738 738
  }
739 739

	
740 740

	
741 741
  /// Applies all map setting operations to two maps
742 742

	
743 743
  /// This map has two \ref concepts::WriteMap "writable map" parameters
744 744
  /// and each write request will be passed to both of them.
745 745
  /// If \c M1 is also \ref concepts::ReadMap "readable", then the read
746 746
  /// operations will return the corresponding values of \c M1.
747 747
  ///
748 748
  /// The \c Key and \c Value types are inherited from \c M1.
749 749
  /// The \c Key and \c Value of \c M2 must be convertible from those
750 750
  /// of \c M1.
751 751
  ///
752 752
  /// The simplest way of using this map is through the forkMap()
753 753
  /// function.
754 754
  template<typename  M1, typename M2>
755 755
  class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
756 756
    M1 &_m1;
757 757
    M2 &_m2;
758 758
  public:
759 759
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
760 760
    typedef typename Parent::Key Key;
761 761
    typedef typename Parent::Value Value;
762 762

	
763 763
    /// Constructor
764 764
    ForkMap(M1 &m1, M2 &m2) : _m1(m1), _m2(m2) {}
765 765
    /// Returns the value associated with the given key in the first map.
766 766
    Value operator[](const Key &k) const { return _m1[k]; }
767 767
    /// Sets the value associated with the given key in both maps.
768 768
    void set(const Key &k, const Value &v) { _m1.set(k,v); _m2.set(k,v); }
769 769
  };
770 770

	
771 771
  /// Returns a \ref ForkMap class
772 772

	
773 773
  /// This function just returns a \ref ForkMap class.
774 774
  /// \relates ForkMap
775 775
  template <typename M1, typename M2>
776 776
  inline ForkMap<M1,M2> forkMap(M1 &m1, M2 &m2) {
777 777
    return ForkMap<M1,M2>(m1,m2);
778 778
  }
779 779

	
780 780

	
781 781
  /// Sum of two maps
782 782

	
783 783
  /// This \ref concepts::ReadMap "read-only map" returns the sum
784 784
  /// of the values of the two given maps.
785 785
  /// Its \c Key and \c Value types are inherited from \c M1.
786 786
  /// The \c Key and \c Value of \c M2 must be convertible to those of
787 787
  /// \c M1.
788 788
  ///
789 789
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
790 790
  /// \code
791 791
  ///   AddMap<M1,M2> am(m1,m2);
792 792
  /// \endcode
793 793
  /// <tt>am[x]</tt> will be equal to <tt>m1[x]+m2[x]</tt>.
794 794
  ///
795 795
  /// The simplest way of using this map is through the addMap()
796 796
  /// function.
797 797
  ///
798 798
  /// \sa SubMap, MulMap, DivMap
799 799
  /// \sa ShiftMap, ShiftWriteMap
800 800
  template<typename M1, typename M2>
801 801
  class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
802 802
    const M1 &_m1;
803 803
    const M2 &_m2;
804 804
  public:
805 805
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
806 806
    typedef typename Parent::Key Key;
807 807
    typedef typename Parent::Value Value;
808 808

	
809 809
    /// Constructor
810 810
    AddMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
811 811
    /// \e
812 812
    Value operator[](const Key &k) const { return _m1[k]+_m2[k]; }
813 813
  };
814 814

	
815 815
  /// Returns an \ref AddMap class
816 816

	
817 817
  /// This function just returns an \ref AddMap class.
818 818
  ///
819 819
  /// For example, if \c m1 and \c m2 are both maps with \c double
820 820
  /// values, then <tt>addMap(m1,m2)[x]</tt> will be equal to
821 821
  /// <tt>m1[x]+m2[x]</tt>.
822 822
  ///
823 823
  /// \relates AddMap
824 824
  template<typename M1, typename M2>
825 825
  inline AddMap<M1, M2> addMap(const M1 &m1, const M2 &m2) {
826 826
    return AddMap<M1, M2>(m1,m2);
827 827
  }
828 828

	
829 829

	
830 830
  /// Difference of two maps
831 831

	
832 832
  /// This \ref concepts::ReadMap "read-only map" returns the difference
833 833
  /// of the values of the two given maps.
834 834
  /// Its \c Key and \c Value types are inherited from \c M1.
835 835
  /// The \c Key and \c Value of \c M2 must be convertible to those of
836 836
  /// \c M1.
837 837
  ///
838 838
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
839 839
  /// \code
840 840
  ///   SubMap<M1,M2> sm(m1,m2);
841 841
  /// \endcode
842 842
  /// <tt>sm[x]</tt> will be equal to <tt>m1[x]-m2[x]</tt>.
843 843
  ///
844 844
  /// The simplest way of using this map is through the subMap()
845 845
  /// function.
846 846
  ///
847 847
  /// \sa AddMap, MulMap, DivMap
848 848
  template<typename M1, typename M2>
849 849
  class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
850 850
    const M1 &_m1;
851 851
    const M2 &_m2;
852 852
  public:
853 853
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
854 854
    typedef typename Parent::Key Key;
855 855
    typedef typename Parent::Value Value;
856 856

	
857 857
    /// Constructor
858 858
    SubMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
859 859
    /// \e
860 860
    Value operator[](const Key &k) const { return _m1[k]-_m2[k]; }
861 861
  };
862 862

	
863 863
  /// Returns a \ref SubMap class
864 864

	
865 865
  /// This function just returns a \ref SubMap class.
866 866
  ///
867 867
  /// For example, if \c m1 and \c m2 are both maps with \c double
868 868
  /// values, then <tt>subMap(m1,m2)[x]</tt> will be equal to
869 869
  /// <tt>m1[x]-m2[x]</tt>.
870 870
  ///
871 871
  /// \relates SubMap
872 872
  template<typename M1, typename M2>
873 873
  inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
874 874
    return SubMap<M1, M2>(m1,m2);
875 875
  }
876 876

	
877 877

	
878 878
  /// Product of two maps
879 879

	
880 880
  /// This \ref concepts::ReadMap "read-only map" returns the product
881 881
  /// of the values of the two given maps.
882 882
  /// Its \c Key and \c Value types are inherited from \c M1.
883 883
  /// The \c Key and \c Value of \c M2 must be convertible to those of
884 884
  /// \c M1.
885 885
  ///
886 886
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
887 887
  /// \code
888 888
  ///   MulMap<M1,M2> mm(m1,m2);
889 889
  /// \endcode
890 890
  /// <tt>mm[x]</tt> will be equal to <tt>m1[x]*m2[x]</tt>.
891 891
  ///
892 892
  /// The simplest way of using this map is through the mulMap()
893 893
  /// function.
894 894
  ///
895 895
  /// \sa AddMap, SubMap, DivMap
896 896
  /// \sa ScaleMap, ScaleWriteMap
897 897
  template<typename M1, typename M2>
898 898
  class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
899 899
    const M1 &_m1;
900 900
    const M2 &_m2;
901 901
  public:
902 902
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
903 903
    typedef typename Parent::Key Key;
904 904
    typedef typename Parent::Value Value;
905 905

	
906 906
    /// Constructor
907 907
    MulMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
908 908
    /// \e
909 909
    Value operator[](const Key &k) const { return _m1[k]*_m2[k]; }
910 910
  };
911 911

	
912 912
  /// Returns a \ref MulMap class
913 913

	
914 914
  /// This function just returns a \ref MulMap class.
915 915
  ///
916 916
  /// For example, if \c m1 and \c m2 are both maps with \c double
917 917
  /// values, then <tt>mulMap(m1,m2)[x]</tt> will be equal to
918 918
  /// <tt>m1[x]*m2[x]</tt>.
919 919
  ///
920 920
  /// \relates MulMap
921 921
  template<typename M1, typename M2>
922 922
  inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
923 923
    return MulMap<M1, M2>(m1,m2);
924 924
  }
925 925

	
926 926

	
927 927
  /// Quotient of two maps
928 928

	
929 929
  /// This \ref concepts::ReadMap "read-only map" returns the quotient
930 930
  /// of the values of the two given maps.
931 931
  /// Its \c Key and \c Value types are inherited from \c M1.
932 932
  /// The \c Key and \c Value of \c M2 must be convertible to those of
933 933
  /// \c M1.
934 934
  ///
935 935
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
936 936
  /// \code
937 937
  ///   DivMap<M1,M2> dm(m1,m2);
938 938
  /// \endcode
939 939
  /// <tt>dm[x]</tt> will be equal to <tt>m1[x]/m2[x]</tt>.
940 940
  ///
941 941
  /// The simplest way of using this map is through the divMap()
942 942
  /// function.
943 943
  ///
944 944
  /// \sa AddMap, SubMap, MulMap
945 945
  template<typename M1, typename M2>
946 946
  class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
947 947
    const M1 &_m1;
948 948
    const M2 &_m2;
949 949
  public:
950 950
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
951 951
    typedef typename Parent::Key Key;
952 952
    typedef typename Parent::Value Value;
953 953

	
954 954
    /// Constructor
955 955
    DivMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
956 956
    /// \e
957 957
    Value operator[](const Key &k) const { return _m1[k]/_m2[k]; }
958 958
  };
959 959

	
960 960
  /// Returns a \ref DivMap class
961 961

	
962 962
  /// This function just returns a \ref DivMap class.
963 963
  ///
964 964
  /// For example, if \c m1 and \c m2 are both maps with \c double
965 965
  /// values, then <tt>divMap(m1,m2)[x]</tt> will be equal to
966 966
  /// <tt>m1[x]/m2[x]</tt>.
967 967
  ///
968 968
  /// \relates DivMap
969 969
  template<typename M1, typename M2>
970 970
  inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
971 971
    return DivMap<M1, M2>(m1,m2);
972 972
  }
973 973

	
974 974

	
975 975
  /// Shifts a map with a constant.
976 976

	
977 977
  /// This \ref concepts::ReadMap "read-only map" returns the sum of
978 978
  /// the given map and a constant value (i.e. it shifts the map with
979 979
  /// the constant). Its \c Key and \c Value are inherited from \c M.
980 980
  ///
981 981
  /// Actually,
982 982
  /// \code
983 983
  ///   ShiftMap<M> sh(m,v);
984 984
  /// \endcode
985 985
  /// is equivalent to
986 986
  /// \code
987 987
  ///   ConstMap<M::Key, M::Value> cm(v);
988 988
  ///   AddMap<M, ConstMap<M::Key, M::Value> > sh(m,cm);
989 989
  /// \endcode
990 990
  ///
991 991
  /// The simplest way of using this map is through the shiftMap()
992 992
  /// function.
993 993
  ///
994 994
  /// \sa ShiftWriteMap
995 995
  template<typename M, typename C = typename M::Value>
996 996
  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
997 997
    const M &_m;
998 998
    C _v;
999 999
  public:
1000 1000
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1001 1001
    typedef typename Parent::Key Key;
1002 1002
    typedef typename Parent::Value Value;
1003 1003

	
1004 1004
    /// Constructor
1005 1005

	
1006 1006
    /// Constructor.
1007 1007
    /// \param m The undelying map.
1008 1008
    /// \param v The constant value.
1009 1009
    ShiftMap(const M &m, const C &v) : _m(m), _v(v) {}
1010 1010
    /// \e
1011 1011
    Value operator[](const Key &k) const { return _m[k]+_v; }
1012 1012
  };
1013 1013

	
1014 1014
  /// Shifts a map with a constant (read-write version).
1015 1015

	
1016 1016
  /// This \ref concepts::ReadWriteMap "read-write map" returns the sum
1017 1017
  /// of the given map and a constant value (i.e. it shifts the map with
1018 1018
  /// the constant). Its \c Key and \c Value are inherited from \c M.
1019 1019
  /// It makes also possible to write the map.
1020 1020
  ///
1021 1021
  /// The simplest way of using this map is through the shiftWriteMap()
1022 1022
  /// function.
1023 1023
  ///
1024 1024
  /// \sa ShiftMap
1025 1025
  template<typename M, typename C = typename M::Value>
1026 1026
  class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
1027 1027
    M &_m;
1028 1028
    C _v;
1029 1029
  public:
1030 1030
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1031 1031
    typedef typename Parent::Key Key;
1032 1032
    typedef typename Parent::Value Value;
1033 1033

	
1034 1034
    /// Constructor
1035 1035

	
1036 1036
    /// Constructor.
1037 1037
    /// \param m The undelying map.
1038 1038
    /// \param v The constant value.
1039 1039
    ShiftWriteMap(M &m, const C &v) : _m(m), _v(v) {}
1040 1040
    /// \e
1041 1041
    Value operator[](const Key &k) const { return _m[k]+_v; }
1042 1042
    /// \e
1043 1043
    void set(const Key &k, const Value &v) { _m.set(k, v-_v); }
1044 1044
  };
1045 1045

	
1046 1046
  /// Returns a \ref ShiftMap class
1047 1047

	
1048 1048
  /// This function just returns a \ref ShiftMap class.
1049 1049
  ///
1050 1050
  /// For example, if \c m is a map with \c double values and \c v is
1051 1051
  /// \c double, then <tt>shiftMap(m,v)[x]</tt> will be equal to
1052 1052
  /// <tt>m[x]+v</tt>.
1053 1053
  ///
1054 1054
  /// \relates ShiftMap
1055 1055
  template<typename M, typename C>
1056 1056
  inline ShiftMap<M, C> shiftMap(const M &m, const C &v) {
1057 1057
    return ShiftMap<M, C>(m,v);
1058 1058
  }
1059 1059

	
1060 1060
  /// Returns a \ref ShiftWriteMap class
1061 1061

	
1062 1062
  /// This function just returns a \ref ShiftWriteMap class.
1063 1063
  ///
1064 1064
  /// For example, if \c m is a map with \c double values and \c v is
1065 1065
  /// \c double, then <tt>shiftWriteMap(m,v)[x]</tt> will be equal to
1066 1066
  /// <tt>m[x]+v</tt>.
1067 1067
  /// Moreover it makes also possible to write the map.
1068 1068
  ///
1069 1069
  /// \relates ShiftWriteMap
1070 1070
  template<typename M, typename C>
1071 1071
  inline ShiftWriteMap<M, C> shiftWriteMap(M &m, const C &v) {
1072 1072
    return ShiftWriteMap<M, C>(m,v);
1073 1073
  }
1074 1074

	
1075 1075

	
1076 1076
  /// Scales a map with a constant.
1077 1077

	
1078 1078
  /// This \ref concepts::ReadMap "read-only map" returns the value of
1079 1079
  /// the given map multiplied from the left side with a constant value.
1080 1080
  /// Its \c Key and \c Value are inherited from \c M.
1081 1081
  ///
1082 1082
  /// Actually,
1083 1083
  /// \code
1084 1084
  ///   ScaleMap<M> sc(m,v);
1085 1085
  /// \endcode
1086 1086
  /// is equivalent to
1087 1087
  /// \code
1088 1088
  ///   ConstMap<M::Key, M::Value> cm(v);
1089 1089
  ///   MulMap<ConstMap<M::Key, M::Value>, M> sc(cm,m);
1090 1090
  /// \endcode
1091 1091
  ///
1092 1092
  /// The simplest way of using this map is through the scaleMap()
1093 1093
  /// function.
1094 1094
  ///
1095 1095
  /// \sa ScaleWriteMap
1096 1096
  template<typename M, typename C = typename M::Value>
1097 1097
  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
1098 1098
    const M &_m;
1099 1099
    C _v;
1100 1100
  public:
1101 1101
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1102 1102
    typedef typename Parent::Key Key;
1103 1103
    typedef typename Parent::Value Value;
1104 1104

	
1105 1105
    /// Constructor
1106 1106

	
1107 1107
    /// Constructor.
1108 1108
    /// \param m The undelying map.
1109 1109
    /// \param v The constant value.
1110 1110
    ScaleMap(const M &m, const C &v) : _m(m), _v(v) {}
1111 1111
    /// \e
1112 1112
    Value operator[](const Key &k) const { return _v*_m[k]; }
1113 1113
  };
1114 1114

	
1115 1115
  /// Scales a map with a constant (read-write version).
1116 1116

	
1117 1117
  /// This \ref concepts::ReadWriteMap "read-write map" returns the value of
1118 1118
  /// the given map multiplied from the left side with a constant value.
1119 1119
  /// Its \c Key and \c Value are inherited from \c M.
1120 1120
  /// It can also be used as write map if the \c / operator is defined
1121 1121
  /// between \c Value and \c C and the given multiplier is not zero.
1122 1122
  ///
1123 1123
  /// The simplest way of using this map is through the scaleWriteMap()
1124 1124
  /// function.
1125 1125
  ///
1126 1126
  /// \sa ScaleMap
1127 1127
  template<typename M, typename C = typename M::Value>
1128 1128
  class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
1129 1129
    M &_m;
1130 1130
    C _v;
1131 1131
  public:
1132 1132
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1133 1133
    typedef typename Parent::Key Key;
1134 1134
    typedef typename Parent::Value Value;
1135 1135

	
1136 1136
    /// Constructor
1137 1137

	
1138 1138
    /// Constructor.
1139 1139
    /// \param m The undelying map.
1140 1140
    /// \param v The constant value.
1141 1141
    ScaleWriteMap(M &m, const C &v) : _m(m), _v(v) {}
1142 1142
    /// \e
1143 1143
    Value operator[](const Key &k) const { return _v*_m[k]; }
1144 1144
    /// \e
1145 1145
    void set(const Key &k, const Value &v) { _m.set(k, v/_v); }
1146 1146
  };
1147 1147

	
1148 1148
  /// Returns a \ref ScaleMap class
1149 1149

	
1150 1150
  /// This function just returns a \ref ScaleMap class.
1151 1151
  ///
1152 1152
  /// For example, if \c m is a map with \c double values and \c v is
1153 1153
  /// \c double, then <tt>scaleMap(m,v)[x]</tt> will be equal to
1154 1154
  /// <tt>v*m[x]</tt>.
1155 1155
  ///
1156 1156
  /// \relates ScaleMap
1157 1157
  template<typename M, typename C>
1158 1158
  inline ScaleMap<M, C> scaleMap(const M &m, const C &v) {
1159 1159
    return ScaleMap<M, C>(m,v);
1160 1160
  }
1161 1161

	
1162 1162
  /// Returns a \ref ScaleWriteMap class
1163 1163

	
1164 1164
  /// This function just returns a \ref ScaleWriteMap class.
1165 1165
  ///
1166 1166
  /// For example, if \c m is a map with \c double values and \c v is
1167 1167
  /// \c double, then <tt>scaleWriteMap(m,v)[x]</tt> will be equal to
1168 1168
  /// <tt>v*m[x]</tt>.
1169 1169
  /// Moreover it makes also possible to write the map.
1170 1170
  ///
1171 1171
  /// \relates ScaleWriteMap
1172 1172
  template<typename M, typename C>
1173 1173
  inline ScaleWriteMap<M, C> scaleWriteMap(M &m, const C &v) {
1174 1174
    return ScaleWriteMap<M, C>(m,v);
1175 1175
  }
1176 1176

	
1177 1177

	
1178 1178
  /// Negative of a map
1179 1179

	
1180 1180
  /// This \ref concepts::ReadMap "read-only map" returns the negative
1181 1181
  /// of the values of the given map (using the unary \c - operator).
1182 1182
  /// Its \c Key and \c Value are inherited from \c M.
1183 1183
  ///
1184 1184
  /// If M::Value is \c int, \c double etc., then
1185 1185
  /// \code
1186 1186
  ///   NegMap<M> neg(m);
1187 1187
  /// \endcode
1188 1188
  /// is equivalent to
1189 1189
  /// \code
1190 1190
  ///   ScaleMap<M> neg(m,-1);
1191 1191
  /// \endcode
1192 1192
  ///
1193 1193
  /// The simplest way of using this map is through the negMap()
1194 1194
  /// function.
1195 1195
  ///
1196 1196
  /// \sa NegWriteMap
1197 1197
  template<typename M>
1198 1198
  class NegMap : public MapBase<typename M::Key, typename M::Value> {
1199 1199
    const M& _m;
1200 1200
  public:
1201 1201
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1202 1202
    typedef typename Parent::Key Key;
1203 1203
    typedef typename Parent::Value Value;
1204 1204

	
1205 1205
    /// Constructor
1206 1206
    NegMap(const M &m) : _m(m) {}
1207 1207
    /// \e
1208 1208
    Value operator[](const Key &k) const { return -_m[k]; }
1209 1209
  };
1210 1210

	
1211 1211
  /// Negative of a map (read-write version)
1212 1212

	
1213 1213
  /// This \ref concepts::ReadWriteMap "read-write map" returns the
1214 1214
  /// negative of the values of the given map (using the unary \c -
1215 1215
  /// operator).
1216 1216
  /// Its \c Key and \c Value are inherited from \c M.
1217 1217
  /// It makes also possible to write the map.
1218 1218
  ///
1219 1219
  /// If M::Value is \c int, \c double etc., then
1220 1220
  /// \code
1221 1221
  ///   NegWriteMap<M> neg(m);
1222 1222
  /// \endcode
1223 1223
  /// is equivalent to
1224 1224
  /// \code
1225 1225
  ///   ScaleWriteMap<M> neg(m,-1);
1226 1226
  /// \endcode
1227 1227
  ///
1228 1228
  /// The simplest way of using this map is through the negWriteMap()
1229 1229
  /// function.
1230 1230
  ///
1231 1231
  /// \sa NegMap
1232 1232
  template<typename M>
1233 1233
  class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
1234 1234
    M &_m;
1235 1235
  public:
1236 1236
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1237 1237
    typedef typename Parent::Key Key;
1238 1238
    typedef typename Parent::Value Value;
1239 1239

	
1240 1240
    /// Constructor
1241 1241
    NegWriteMap(M &m) : _m(m) {}
1242 1242
    /// \e
1243 1243
    Value operator[](const Key &k) const { return -_m[k]; }
1244 1244
    /// \e
1245 1245
    void set(const Key &k, const Value &v) { _m.set(k, -v); }
1246 1246
  };
1247 1247

	
1248 1248
  /// Returns a \ref NegMap class
1249 1249

	
1250 1250
  /// This function just returns a \ref NegMap class.
1251 1251
  ///
1252 1252
  /// For example, if \c m is a map with \c double values, then
1253 1253
  /// <tt>negMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>.
1254 1254
  ///
1255 1255
  /// \relates NegMap
1256 1256
  template <typename M>
1257 1257
  inline NegMap<M> negMap(const M &m) {
1258 1258
    return NegMap<M>(m);
1259 1259
  }
1260 1260

	
1261 1261
  /// Returns a \ref NegWriteMap class
1262 1262

	
1263 1263
  /// This function just returns a \ref NegWriteMap class.
1264 1264
  ///
1265 1265
  /// For example, if \c m is a map with \c double values, then
1266 1266
  /// <tt>negWriteMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>.
1267 1267
  /// Moreover it makes also possible to write the map.
1268 1268
  ///
1269 1269
  /// \relates NegWriteMap
1270 1270
  template <typename M>
1271 1271
  inline NegWriteMap<M> negWriteMap(M &m) {
1272 1272
    return NegWriteMap<M>(m);
1273 1273
  }
1274 1274

	
1275 1275

	
1276 1276
  /// Absolute value of a map
1277 1277

	
1278 1278
  /// This \ref concepts::ReadMap "read-only map" returns the absolute
1279 1279
  /// value of the values of the given map.
1280 1280
  /// Its \c Key and \c Value are inherited from \c M.
1281 1281
  /// \c Value must be comparable to \c 0 and the unary \c -
1282 1282
  /// operator must be defined for it, of course.
1283 1283
  ///
1284 1284
  /// The simplest way of using this map is through the absMap()
1285 1285
  /// function.
1286 1286
  template<typename M>
1287 1287
  class AbsMap : public MapBase<typename M::Key, typename M::Value> {
1288 1288
    const M &_m;
1289 1289
  public:
1290 1290
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1291 1291
    typedef typename Parent::Key Key;
1292 1292
    typedef typename Parent::Value Value;
1293 1293

	
1294 1294
    /// Constructor
1295 1295
    AbsMap(const M &m) : _m(m) {}
1296 1296
    /// \e
1297 1297
    Value operator[](const Key &k) const {
1298 1298
      Value tmp = _m[k];
1299 1299
      return tmp >= 0 ? tmp : -tmp;
1300 1300
    }
1301 1301

	
1302 1302
  };
1303 1303

	
1304 1304
  /// Returns an \ref AbsMap class
1305 1305

	
1306 1306
  /// This function just returns an \ref AbsMap class.
1307 1307
  ///
1308 1308
  /// For example, if \c m is a map with \c double values, then
1309 1309
  /// <tt>absMap(m)[x]</tt> will be equal to <tt>m[x]</tt> if
1310 1310
  /// it is positive or zero and <tt>-m[x]</tt> if <tt>m[x]</tt> is
1311 1311
  /// negative.
1312 1312
  ///
1313 1313
  /// \relates AbsMap
1314 1314
  template<typename M>
1315 1315
  inline AbsMap<M> absMap(const M &m) {
1316 1316
    return AbsMap<M>(m);
1317 1317
  }
1318 1318

	
1319 1319
  /// @}
1320 1320
  
1321 1321
  // Logical maps and map adaptors:
1322 1322

	
1323 1323
  /// \addtogroup maps
1324 1324
  /// @{
1325 1325

	
1326 1326
  /// Constant \c true map.
1327 1327

	
1328 1328
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1329 1329
  /// each key.
1330 1330
  ///
1331 1331
  /// Note that
1332 1332
  /// \code
1333 1333
  ///   TrueMap<K> tm;
1334 1334
  /// \endcode
1335 1335
  /// is equivalent to
1336 1336
  /// \code
1337 1337
  ///   ConstMap<K,bool> tm(true);
1338 1338
  /// \endcode
1339 1339
  ///
1340 1340
  /// \sa FalseMap
1341 1341
  /// \sa ConstMap
1342 1342
  template <typename K>
1343 1343
  class TrueMap : public MapBase<K, bool> {
1344 1344
  public:
1345 1345
    typedef MapBase<K, bool> Parent;
1346 1346
    typedef typename Parent::Key Key;
1347 1347
    typedef typename Parent::Value Value;
1348 1348

	
1349 1349
    /// Gives back \c true.
1350 1350
    Value operator[](const Key&) const { return true; }
1351 1351
  };
1352 1352

	
1353 1353
  /// Returns a \ref TrueMap class
1354 1354

	
1355 1355
  /// This function just returns a \ref TrueMap class.
1356 1356
  /// \relates TrueMap
1357 1357
  template<typename K>
1358 1358
  inline TrueMap<K> trueMap() {
1359 1359
    return TrueMap<K>();
1360 1360
  }
1361 1361

	
1362 1362

	
1363 1363
  /// Constant \c false map.
1364 1364

	
1365 1365
  /// This \ref concepts::ReadMap "read-only map" assigns \c false to
1366 1366
  /// each key.
1367 1367
  ///
1368 1368
  /// Note that
1369 1369
  /// \code
1370 1370
  ///   FalseMap<K> fm;
1371 1371
  /// \endcode
1372 1372
  /// is equivalent to
1373 1373
  /// \code
1374 1374
  ///   ConstMap<K,bool> fm(false);
1375 1375
  /// \endcode
1376 1376
  ///
1377 1377
  /// \sa TrueMap
1378 1378
  /// \sa ConstMap
1379 1379
  template <typename K>
1380 1380
  class FalseMap : public MapBase<K, bool> {
1381 1381
  public:
1382 1382
    typedef MapBase<K, bool> Parent;
1383 1383
    typedef typename Parent::Key Key;
1384 1384
    typedef typename Parent::Value Value;
1385 1385

	
1386 1386
    /// Gives back \c false.
1387 1387
    Value operator[](const Key&) const { return false; }
1388 1388
  };
1389 1389

	
1390 1390
  /// Returns a \ref FalseMap class
1391 1391

	
1392 1392
  /// This function just returns a \ref FalseMap class.
1393 1393
  /// \relates FalseMap
1394 1394
  template<typename K>
1395 1395
  inline FalseMap<K> falseMap() {
1396 1396
    return FalseMap<K>();
1397 1397
  }
1398 1398

	
1399 1399
  /// @}
1400 1400

	
1401 1401
  /// \addtogroup map_adaptors
1402 1402
  /// @{
1403 1403

	
1404 1404
  /// Logical 'and' of two maps
1405 1405

	
1406 1406
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1407 1407
  /// 'and' of the values of the two given maps.
1408 1408
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1409 1409
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1410 1410
  ///
1411 1411
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1412 1412
  /// \code
1413 1413
  ///   AndMap<M1,M2> am(m1,m2);
1414 1414
  /// \endcode
1415 1415
  /// <tt>am[x]</tt> will be equal to <tt>m1[x]&&m2[x]</tt>.
1416 1416
  ///
1417 1417
  /// The simplest way of using this map is through the andMap()
1418 1418
  /// function.
1419 1419
  ///
1420 1420
  /// \sa OrMap
1421 1421
  /// \sa NotMap, NotWriteMap
1422 1422
  template<typename M1, typename M2>
1423 1423
  class AndMap : public MapBase<typename M1::Key, bool> {
1424 1424
    const M1 &_m1;
1425 1425
    const M2 &_m2;
1426 1426
  public:
1427 1427
    typedef MapBase<typename M1::Key, bool> Parent;
1428 1428
    typedef typename Parent::Key Key;
1429 1429
    typedef typename Parent::Value Value;
1430 1430

	
1431 1431
    /// Constructor
1432 1432
    AndMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1433 1433
    /// \e
1434 1434
    Value operator[](const Key &k) const { return _m1[k]&&_m2[k]; }
1435 1435
  };
1436 1436

	
1437 1437
  /// Returns an \ref AndMap class
1438 1438

	
1439 1439
  /// This function just returns an \ref AndMap class.
1440 1440
  ///
1441 1441
  /// For example, if \c m1 and \c m2 are both maps with \c bool values,
1442 1442
  /// then <tt>andMap(m1,m2)[x]</tt> will be equal to
1443 1443
  /// <tt>m1[x]&&m2[x]</tt>.
1444 1444
  ///
1445 1445
  /// \relates AndMap
1446 1446
  template<typename M1, typename M2>
1447 1447
  inline AndMap<M1, M2> andMap(const M1 &m1, const M2 &m2) {
1448 1448
    return AndMap<M1, M2>(m1,m2);
1449 1449
  }
1450 1450

	
1451 1451

	
1452 1452
  /// Logical 'or' of two maps
1453 1453

	
1454 1454
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1455 1455
  /// 'or' of the values of the two given maps.
1456 1456
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1457 1457
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1458 1458
  ///
1459 1459
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1460 1460
  /// \code
1461 1461
  ///   OrMap<M1,M2> om(m1,m2);
1462 1462
  /// \endcode
1463 1463
  /// <tt>om[x]</tt> will be equal to <tt>m1[x]||m2[x]</tt>.
1464 1464
  ///
1465 1465
  /// The simplest way of using this map is through the orMap()
1466 1466
  /// function.
1467 1467
  ///
1468 1468
  /// \sa AndMap
1469 1469
  /// \sa NotMap, NotWriteMap
1470 1470
  template<typename M1, typename M2>
1471 1471
  class OrMap : public MapBase<typename M1::Key, bool> {
1472 1472
    const M1 &_m1;
1473 1473
    const M2 &_m2;
1474 1474
  public:
1475 1475
    typedef MapBase<typename M1::Key, bool> Parent;
1476 1476
    typedef typename Parent::Key Key;
1477 1477
    typedef typename Parent::Value Value;
1478 1478

	
1479 1479
    /// Constructor
1480 1480
    OrMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1481 1481
    /// \e
1482 1482
    Value operator[](const Key &k) const { return _m1[k]||_m2[k]; }
1483 1483
  };
1484 1484

	
1485 1485
  /// Returns an \ref OrMap class
1486 1486

	
1487 1487
  /// This function just returns an \ref OrMap class.
1488 1488
  ///
1489 1489
  /// For example, if \c m1 and \c m2 are both maps with \c bool values,
1490 1490
  /// then <tt>orMap(m1,m2)[x]</tt> will be equal to
1491 1491
  /// <tt>m1[x]||m2[x]</tt>.
1492 1492
  ///
1493 1493
  /// \relates OrMap
1494 1494
  template<typename M1, typename M2>
1495 1495
  inline OrMap<M1, M2> orMap(const M1 &m1, const M2 &m2) {
1496 1496
    return OrMap<M1, M2>(m1,m2);
1497 1497
  }
1498 1498

	
1499 1499

	
1500 1500
  /// Logical 'not' of a map
1501 1501

	
1502 1502
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1503 1503
  /// negation of the values of the given map.
1504 1504
  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
1505 1505
  ///
1506 1506
  /// The simplest way of using this map is through the notMap()
1507 1507
  /// function.
1508 1508
  ///
1509 1509
  /// \sa NotWriteMap
1510 1510
  template <typename M>
1511 1511
  class NotMap : public MapBase<typename M::Key, bool> {
1512 1512
    const M &_m;
1513 1513
  public:
1514 1514
    typedef MapBase<typename M::Key, bool> Parent;
1515 1515
    typedef typename Parent::Key Key;
1516 1516
    typedef typename Parent::Value Value;
1517 1517

	
1518 1518
    /// Constructor
1519 1519
    NotMap(const M &m) : _m(m) {}
1520 1520
    /// \e
1521 1521
    Value operator[](const Key &k) const { return !_m[k]; }
1522 1522
  };
1523 1523

	
1524 1524
  /// Logical 'not' of a map (read-write version)
1525 1525

	
1526 1526
  /// This \ref concepts::ReadWriteMap "read-write map" returns the
1527 1527
  /// logical negation of the values of the given map.
1528 1528
  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
1529 1529
  /// It makes also possible to write the map. When a value is set,
1530 1530
  /// the opposite value is set to the original map.
1531 1531
  ///
1532 1532
  /// The simplest way of using this map is through the notWriteMap()
1533 1533
  /// function.
1534 1534
  ///
1535 1535
  /// \sa NotMap
1536 1536
  template <typename M>
1537 1537
  class NotWriteMap : public MapBase<typename M::Key, bool> {
1538 1538
    M &_m;
1539 1539
  public:
1540 1540
    typedef MapBase<typename M::Key, bool> Parent;
1541 1541
    typedef typename Parent::Key Key;
1542 1542
    typedef typename Parent::Value Value;
1543 1543

	
1544 1544
    /// Constructor
1545 1545
    NotWriteMap(M &m) : _m(m) {}
1546 1546
    /// \e
1547 1547
    Value operator[](const Key &k) const { return !_m[k]; }
1548 1548
    /// \e
1549 1549
    void set(const Key &k, bool v) { _m.set(k, !v); }
1550 1550
  };
1551 1551

	
1552 1552
  /// Returns a \ref NotMap class
1553 1553

	
1554 1554
  /// This function just returns a \ref NotMap class.
1555 1555
  ///
1556 1556
  /// For example, if \c m is a map with \c bool values, then
1557 1557
  /// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>.
1558 1558
  ///
1559 1559
  /// \relates NotMap
1560 1560
  template <typename M>
1561 1561
  inline NotMap<M> notMap(const M &m) {
1562 1562
    return NotMap<M>(m);
1563 1563
  }
1564 1564

	
1565 1565
  /// Returns a \ref NotWriteMap class
1566 1566

	
1567 1567
  /// This function just returns a \ref NotWriteMap class.
1568 1568
  ///
1569 1569
  /// For example, if \c m is a map with \c bool values, then
1570 1570
  /// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>.
1571 1571
  /// Moreover it makes also possible to write the map.
1572 1572
  ///
1573 1573
  /// \relates NotWriteMap
1574 1574
  template <typename M>
1575 1575
  inline NotWriteMap<M> notWriteMap(M &m) {
1576 1576
    return NotWriteMap<M>(m);
1577 1577
  }
1578 1578

	
1579 1579

	
1580 1580
  /// Combination of two maps using the \c == operator
1581 1581

	
1582 1582
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1583 1583
  /// the keys for which the corresponding values of the two maps are
1584 1584
  /// equal.
1585 1585
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1586 1586
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1587 1587
  ///
1588 1588
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1589 1589
  /// \code
1590 1590
  ///   EqualMap<M1,M2> em(m1,m2);
1591 1591
  /// \endcode
1592 1592
  /// <tt>em[x]</tt> will be equal to <tt>m1[x]==m2[x]</tt>.
1593 1593
  ///
1594 1594
  /// The simplest way of using this map is through the equalMap()
1595 1595
  /// function.
1596 1596
  ///
1597 1597
  /// \sa LessMap
1598 1598
  template<typename M1, typename M2>
1599 1599
  class EqualMap : public MapBase<typename M1::Key, bool> {
1600 1600
    const M1 &_m1;
1601 1601
    const M2 &_m2;
1602 1602
  public:
1603 1603
    typedef MapBase<typename M1::Key, bool> Parent;
1604 1604
    typedef typename Parent::Key Key;
1605 1605
    typedef typename Parent::Value Value;
1606 1606

	
1607 1607
    /// Constructor
1608 1608
    EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1609 1609
    /// \e
1610 1610
    Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
1611 1611
  };
1612 1612

	
1613 1613
  /// Returns an \ref EqualMap class
1614 1614

	
1615 1615
  /// This function just returns an \ref EqualMap class.
1616 1616
  ///
1617 1617
  /// For example, if \c m1 and \c m2 are maps with keys and values of
1618 1618
  /// the same type, then <tt>equalMap(m1,m2)[x]</tt> will be equal to
1619 1619
  /// <tt>m1[x]==m2[x]</tt>.
1620 1620
  ///
1621 1621
  /// \relates EqualMap
1622 1622
  template<typename M1, typename M2>
1623 1623
  inline EqualMap<M1, M2> equalMap(const M1 &m1, const M2 &m2) {
1624 1624
    return EqualMap<M1, M2>(m1,m2);
1625 1625
  }
1626 1626

	
1627 1627

	
1628 1628
  /// Combination of two maps using the \c < operator
1629 1629

	
1630 1630
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1631 1631
  /// the keys for which the corresponding value of the first map is
1632 1632
  /// less then the value of the second map.
1633 1633
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1634 1634
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1635 1635
  ///
1636 1636
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1637 1637
  /// \code
1638 1638
  ///   LessMap<M1,M2> lm(m1,m2);
1639 1639
  /// \endcode
1640 1640
  /// <tt>lm[x]</tt> will be equal to <tt>m1[x]<m2[x]</tt>.
1641 1641
  ///
1642 1642
  /// The simplest way of using this map is through the lessMap()
1643 1643
  /// function.
1644 1644
  ///
1645 1645
  /// \sa EqualMap
1646 1646
  template<typename M1, typename M2>
1647 1647
  class LessMap : public MapBase<typename M1::Key, bool> {
1648 1648
    const M1 &_m1;
1649 1649
    const M2 &_m2;
1650 1650
  public:
1651 1651
    typedef MapBase<typename M1::Key, bool> Parent;
1652 1652
    typedef typename Parent::Key Key;
1653 1653
    typedef typename Parent::Value Value;
1654 1654

	
1655 1655
    /// Constructor
1656 1656
    LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1657 1657
    /// \e
1658 1658
    Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
1659 1659
  };
1660 1660

	
1661 1661
  /// Returns an \ref LessMap class
1662 1662

	
1663 1663
  /// This function just returns an \ref LessMap class.
1664 1664
  ///
1665 1665
  /// For example, if \c m1 and \c m2 are maps with keys and values of
1666 1666
  /// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to
1667 1667
  /// <tt>m1[x]<m2[x]</tt>.
1668 1668
  ///
1669 1669
  /// \relates LessMap
1670 1670
  template<typename M1, typename M2>
1671 1671
  inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
1672 1672
    return LessMap<M1, M2>(m1,m2);
1673 1673
  }
1674 1674

	
1675 1675
  namespace _maps_bits {
1676 1676

	
1677 1677
    template <typename _Iterator, typename Enable = void>
1678 1678
    struct IteratorTraits {
1679 1679
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1680 1680
    };
1681 1681

	
1682 1682
    template <typename _Iterator>
1683 1683
    struct IteratorTraits<_Iterator,
1684 1684
      typename exists<typename _Iterator::container_type>::type>
1685 1685
    {
1686 1686
      typedef typename _Iterator::container_type::value_type Value;
1687 1687
    };
1688 1688

	
1689 1689
  }
1690 1690

	
1691 1691
  /// \brief Writable bool map for logging each \c true assigned element
1692 1692
  ///
1693 1693
  /// A \ref concepts::WriteMap "writable" bool map for logging
1694 1694
  /// each \c true assigned element, i.e it copies subsequently each
1695 1695
  /// keys set to \c true to the given iterator.
1696 1696
  /// The most important usage of it is storing certain nodes or arcs
1697 1697
  /// that were marked \c true by an algorithm.
1698 1698
  ///
1699 1699
  /// There are several algorithms that provide solutions through bool
1700 1700
  /// maps and most of them assign \c true at most once for each key.
1701 1701
  /// In these cases it is a natural request to store each \c true
1702 1702
  /// assigned elements (in order of the assignment), which can be
1703
  /// easily done with StoreBoolMap.
1703
  /// easily done with LoggerBoolMap.
1704 1704
  ///
1705
  /// The simplest way of using this map is through the storeBoolMap()
1705
  /// The simplest way of using this map is through the loggerBoolMap()
1706 1706
  /// function.
1707 1707
  ///
1708 1708
  /// \tparam It The type of the iterator.
1709 1709
  /// \tparam Ke The key type of the map. The default value set
1710 1710
  /// according to the iterator type should work in most cases.
1711 1711
  ///
1712 1712
  /// \note The container of the iterator must contain enough space
1713 1713
  /// for the elements or the iterator should be an inserter iterator.
1714 1714
#ifdef DOXYGEN
1715 1715
  template <typename It, typename Ke>
1716 1716
#else
1717 1717
  template <typename It,
1718 1718
	    typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
1719 1719
#endif
1720
  class StoreBoolMap {
1720
  class LoggerBoolMap {
1721 1721
  public:
1722 1722
    typedef It Iterator;
1723 1723

	
1724 1724
    typedef Ke Key;
1725 1725
    typedef bool Value;
1726 1726

	
1727 1727
    /// Constructor
1728
    StoreBoolMap(Iterator it)
1728
    LoggerBoolMap(Iterator it)
1729 1729
      : _begin(it), _end(it) {}
1730 1730

	
1731 1731
    /// Gives back the given iterator set for the first key
1732 1732
    Iterator begin() const {
1733 1733
      return _begin;
1734 1734
    }
1735 1735

	
1736 1736
    /// Gives back the the 'after the last' iterator
1737 1737
    Iterator end() const {
1738 1738
      return _end;
1739 1739
    }
1740 1740

	
1741 1741
    /// The set function of the map
1742 1742
    void set(const Key& key, Value value) {
1743 1743
      if (value) {
1744 1744
	*_end++ = key;
1745 1745
      }
1746 1746
    }
1747 1747

	
1748 1748
  private:
1749 1749
    Iterator _begin;
1750 1750
    Iterator _end;
1751 1751
  };
1752 1752
  
1753
  /// Returns a \ref StoreBoolMap class
1753
  /// Returns a \ref LoggerBoolMap class
1754 1754

	
1755
  /// This function just returns a \ref StoreBoolMap class.
1755
  /// This function just returns a \ref LoggerBoolMap class.
1756 1756
  ///
1757 1757
  /// The most important usage of it is storing certain nodes or arcs
1758 1758
  /// that were marked \c true by an algorithm.
1759 1759
  /// For example it makes easier to store the nodes in the processing
1760 1760
  /// order of Dfs algorithm, as the following examples show.
1761 1761
  /// \code
1762 1762
  ///   std::vector<Node> v;
1763
  ///   dfs(g,s).processedMap(storeBoolMap(std::back_inserter(v))).run();
1763
  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
1764 1764
  /// \endcode
1765 1765
  /// \code
1766 1766
  ///   std::vector<Node> v(countNodes(g));
1767
  ///   dfs(g,s).processedMap(storeBoolMap(v.begin())).run();
1767
  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
1768 1768
  /// \endcode
1769 1769
  ///
1770 1770
  /// \note The container of the iterator must contain enough space
1771 1771
  /// for the elements or the iterator should be an inserter iterator.
1772 1772
  ///
1773
  /// \note StoreBoolMap is just \ref concepts::WriteMap "writable", so
1773
  /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
1774 1774
  /// it cannot be used when a readable map is needed, for example as
1775
  /// \c ReachedMap for Bfs, Dfs and Dijkstra algorithms.
1775
  /// \c ReachedMap for \ref Bfs, \ref Dfs and \ref Dijkstra algorithms.
1776 1776
  ///
1777
  /// \relates StoreBoolMap
1777
  /// \relates LoggerBoolMap
1778 1778
  template<typename Iterator>
1779
  inline StoreBoolMap<Iterator> storeBoolMap(Iterator it) {
1780
    return StoreBoolMap<Iterator>(it);
1779
  inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
1780
    return LoggerBoolMap<Iterator>(it);
1781 1781
  }
1782 1782

	
1783 1783
  /// @}
1784 1784
}
1785 1785

	
1786 1786
#endif // LEMON_MAPS_H
Ignore white space 6 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <deque>
20 20
#include <set>
21 21

	
22 22
#include <lemon/concept_check.h>
23 23
#include <lemon/concepts/maps.h>
24 24
#include <lemon/maps.h>
25 25

	
26 26
#include "test_tools.h"
27 27

	
28 28
using namespace lemon;
29 29
using namespace lemon::concepts;
30 30

	
31 31
struct A {};
32 32
inline bool operator<(A, A) { return true; }
33 33
struct B {};
34 34

	
35 35
class C {
36 36
  int x;
37 37
public:
38 38
  C(int _x) : x(_x) {}
39 39
};
40 40

	
41 41
class F {
42 42
public:
43 43
  typedef A argument_type;
44 44
  typedef B result_type;
45 45

	
46 46
  B operator()(const A&) const { return B(); }
47 47
private:
48 48
  F& operator=(const F&);
49 49
};
50 50

	
51 51
int func(A) { return 3; }
52 52

	
53 53
int binc(int a, B) { return a+1; }
54 54

	
55 55
typedef ReadMap<A, double> DoubleMap;
56 56
typedef ReadWriteMap<A, double> DoubleWriteMap;
57 57
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
58 58

	
59 59
typedef ReadMap<A, bool> BoolMap;
60 60
typedef ReadWriteMap<A, bool> BoolWriteMap;
61 61
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
62 62

	
63 63
int main()
64 64
{
65 65
  // Map concepts
66 66
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
67 67
  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
68 68
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
69 69
  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
70 70
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
71 71
  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
72 72
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
73 73
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
74 74

	
75 75
  // NullMap
76 76
  {
77 77
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
78 78
    NullMap<A,B> map1;
79 79
    NullMap<A,B> map2 = map1;
80 80
    map1 = nullMap<A,B>();
81 81
  }
82 82

	
83 83
  // ConstMap
84 84
  {
85 85
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
86 86
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
87 87
    ConstMap<A,B> map1;
88 88
    ConstMap<A,B> map2 = B();
89 89
    ConstMap<A,B> map3 = map1;
90 90
    map1 = constMap<A>(B());
91 91
    map1 = constMap<A,B>();
92 92
    map1.setAll(B());
93 93
    ConstMap<A,C> map4(C(1));
94 94
    ConstMap<A,C> map5 = map4;
95 95
    map4 = constMap<A>(C(2));
96 96
    map4.setAll(C(3));
97 97

	
98 98
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
99 99
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
100 100

	
101 101
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
102 102
    ConstMap<A,Const<int,10> > map6;
103 103
    ConstMap<A,Const<int,10> > map7 = map6;
104 104
    map6 = constMap<A,int,10>();
105 105
    map7 = constMap<A,Const<int,10> >();
106 106
    check(map6[A()] == 10 && map7[A()] == 10, "Something is wrong with ConstMap");
107 107
  }
108 108

	
109 109
  // IdentityMap
110 110
  {
111 111
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
112 112
    IdentityMap<A> map1;
113 113
    IdentityMap<A> map2 = map1;
114 114
    map1 = identityMap<A>();
115 115

	
116 116
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
117 117
    check(identityMap<double>()[1.0] == 1.0 && identityMap<double>()[3.14] == 3.14,
118 118
          "Something is wrong with IdentityMap");
119 119
  }
120 120

	
121 121
  // RangeMap
122 122
  {
123 123
    checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
124 124
    RangeMap<B> map1;
125 125
    RangeMap<B> map2(10);
126 126
    RangeMap<B> map3(10,B());
127 127
    RangeMap<B> map4 = map1;
128 128
    RangeMap<B> map5 = rangeMap<B>();
129 129
    RangeMap<B> map6 = rangeMap<B>(10);
130 130
    RangeMap<B> map7 = rangeMap(10,B());
131 131

	
132 132
    checkConcept< ReferenceMap<int, double, double&, const double&>,
133 133
                  RangeMap<double> >();
134 134
    std::vector<double> v(10, 0);
135 135
    v[5] = 100;
136 136
    RangeMap<double> map8(v);
137 137
    RangeMap<double> map9 = rangeMap(v);
138 138
    check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
139 139
          "Something is wrong with RangeMap");
140 140
  }
141 141

	
142 142
  // SparseMap
143 143
  {
144 144
    checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
145 145
    SparseMap<A,B> map1;
146 146
    SparseMap<A,B> map2 = B();
147 147
    SparseMap<A,B> map3 = sparseMap<A,B>();
148 148
    SparseMap<A,B> map4 = sparseMap<A>(B());
149 149

	
150 150
    checkConcept< ReferenceMap<double, int, int&, const int&>,
151 151
                  SparseMap<double, int> >();
152 152
    std::map<double, int> m;
153 153
    SparseMap<double, int> map5(m);
154 154
    SparseMap<double, int> map6(m,10);
155 155
    SparseMap<double, int> map7 = sparseMap(m);
156 156
    SparseMap<double, int> map8 = sparseMap(m,10);
157 157

	
158 158
    check(map5[1.0] == 0 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 10,
159 159
          "Something is wrong with SparseMap");
160 160
    map5[1.0] = map6[3.14] = 100;
161 161
    check(map5[1.0] == 100 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 100,
162 162
          "Something is wrong with SparseMap");
163 163
  }
164 164

	
165 165
  // ComposeMap
166 166
  {
167 167
    typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
168 168
    checkConcept<ReadMap<B,double>, CompMap>();
169 169
    CompMap map1(DoubleMap(),ReadMap<B,A>());
170 170
    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
171 171

	
172 172
    SparseMap<double, bool> m1(false); m1[3.14] = true;
173 173
    RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
174 174
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap")
175 175
  }
176 176

	
177 177
  // CombineMap
178 178
  {
179 179
    typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
180 180
    checkConcept<ReadMap<A,double>, CombMap>();
181 181
    CombMap map1(DoubleMap(), DoubleMap());
182 182
    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
183 183

	
184 184
    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
185 185
          "Something is wrong with CombineMap");
186 186
  }
187 187

	
188 188
  // FunctorToMap, MapToFunctor
189 189
  {
190 190
    checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
191 191
    checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
192 192
    FunctorToMap<F> map1;
193 193
    FunctorToMap<F> map2(F());
194 194
    B b = functorToMap(F())[A()];
195 195

	
196 196
    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
197 197
    MapToFunctor<ReadMap<A,B> > map(ReadMap<A,B>());
198 198

	
199 199
    check(functorToMap(&func)[A()] == 3, "Something is wrong with FunctorToMap");
200 200
    check(mapToFunctor(constMap<A,int>(2))(A()) == 2, "Something is wrong with MapToFunctor");
201 201
    check(mapToFunctor(functorToMap(&func))(A()) == 3 && mapToFunctor(functorToMap(&func))[A()] == 3,
202 202
          "Something is wrong with FunctorToMap or MapToFunctor");
203 203
    check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
204 204
          "Something is wrong with FunctorToMap or MapToFunctor");
205 205
  }
206 206

	
207 207
  // ConvertMap
208 208
  {
209 209
    checkConcept<ReadMap<double,double>, ConvertMap<ReadMap<double, int>, double> >();
210 210
    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
211 211
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
212 212
  }
213 213

	
214 214
  // ForkMap
215 215
  {
216 216
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
217 217

	
218 218
    typedef RangeMap<double> RM;
219 219
    typedef SparseMap<int, double> SM;
220 220
    RM m1(10, -1);
221 221
    SM m2(-1);
222 222
    checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
223 223
    checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
224 224
    ForkMap<RM, SM> map1(m1,m2);
225 225
    ForkMap<SM, RM> map2 = forkMap(m2,m1);
226 226
    map2.set(5, 10);
227 227
    check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
228 228
          "Something is wrong with ForkMap");
229 229
  }
230 230

	
231 231
  // Arithmetic maps:
232 232
  // - AddMap, SubMap, MulMap, DivMap
233 233
  // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
234 234
  // - NegMap, NegWriteMap, AbsMap
235 235
  {
236 236
    checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
237 237
    checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
238 238
    checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
239 239
    checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
240 240

	
241 241
    ConstMap<int, double> c1(1.0), c2(3.14);
242 242
    IdentityMap<int> im;
243 243
    ConvertMap<IdentityMap<int>, double> id(im);
244 244
    check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap");
245 245
    check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,  "Something is wrong with SubMap");
246 246
    check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28, "Something is wrong with MulMap");
247 247
    check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57, "Something is wrong with DivMap");
248 248

	
249 249
    checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
250 250
    checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
251 251
    checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
252 252
    checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
253 253
    checkConcept<DoubleMap, NegMap<DoubleMap> >();
254 254
    checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
255 255
    checkConcept<DoubleMap, AbsMap<DoubleMap> >();
256 256

	
257 257
    check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
258 258
          "Something is wrong with ShiftMap");
259 259
    check(shiftWriteMap(id, 2.0)[1] == 3.0 && shiftWriteMap(id, 2.0)[10] == 12.0,
260 260
          "Something is wrong with ShiftWriteMap");
261 261
    check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
262 262
          "Something is wrong with ScaleMap");
263 263
    check(scaleWriteMap(id, 2.0)[1] == 2.0 && scaleWriteMap(id, 2.0)[10] == 20.0,
264 264
          "Something is wrong with ScaleWriteMap");
265 265
    check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
266 266
          "Something is wrong with NegMap");
267 267
    check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
268 268
          "Something is wrong with NegWriteMap");
269 269
    check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
270 270
          "Something is wrong with AbsMap");
271 271
  }
272 272

	
273 273
  // Logical maps:
274 274
  // - TrueMap, FalseMap
275 275
  // - AndMap, OrMap
276 276
  // - NotMap, NotWriteMap
277 277
  // - EqualMap, LessMap
278 278
  {
279 279
    checkConcept<BoolMap, TrueMap<A> >();
280 280
    checkConcept<BoolMap, FalseMap<A> >();
281 281
    checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
282 282
    checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
283 283
    checkConcept<BoolMap, NotMap<BoolMap> >();
284 284
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
285 285
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
286 286
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
287 287

	
288 288
    TrueMap<int> tm;
289 289
    FalseMap<int> fm;
290 290
    RangeMap<bool> rm(2);
291 291
    rm[0] = true; rm[1] = false;
292 292
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
293 293
          "Something is wrong with AndMap");
294 294
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && orMap(fm,rm)[0] && !orMap(fm,rm)[1],
295 295
          "Something is wrong with OrMap");
296 296
    check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap");
297 297
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap");
298 298

	
299 299
    ConstMap<int, double> cm(2.0);
300 300
    IdentityMap<int> im;
301 301
    ConvertMap<IdentityMap<int>, double> id(im);
302 302
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
303 303
          "Something is wrong with LessMap");
304 304
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
305 305
          "Something is wrong with EqualMap");
306 306
  }
307 307
  
308
  // StoreBoolMap
308
  // LoggerBoolMap
309 309
  {
310 310
    typedef std::vector<int> vec;
311 311
    vec v1;
312 312
    vec v2(10);
313
    StoreBoolMap<std::back_insert_iterator<vec> > map1(std::back_inserter(v1));
314
    StoreBoolMap<vec::iterator> map2(v2.begin());
313
    LoggerBoolMap<std::back_insert_iterator<vec> > map1(std::back_inserter(v1));
314
    LoggerBoolMap<vec::iterator> map2(v2.begin());
315 315
    map1.set(10, false);
316 316
    map1.set(20, true);   map2.set(20, true);
317 317
    map1.set(30, false);  map2.set(40, false);
318 318
    map1.set(50, true);   map2.set(50, true);
319 319
    map1.set(60, true);   map2.set(60, true);
320 320
    check(v1.size() == 3 && v2.size() == 10 &&
321 321
          v1[0]==20 && v1[1]==50 && v1[2]==60 && v2[0]==20 && v2[1]==50 && v2[2]==60,
322
          "Something is wrong with StoreBoolMap");
322
          "Something is wrong with LoggerBoolMap");
323 323
          
324 324
    int i = 0;
325
    for ( StoreBoolMap<vec::iterator>::Iterator it = map2.begin();
325
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
326 326
          it != map2.end(); ++it )
327
      check(v1[i++] == *it, "Something is wrong with StoreBoolMap");
327
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
328 328
  }
329 329

	
330 330
  return 0;
331 331
}
0 comments (0 inline)