gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Added missing inheritances and map-creator functions.
0 1 0
default
1 file changed with 60 insertions and 8 deletions:
↑ Collapse diff ↑
Ignore white space 1536 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-2007
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.
43 43
  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
44 44
  template<typename K, typename T>
45 45
  class MapBase {
46 46
  public:
47 47
    /// The key type of the map.
48 48
    typedef K Key;
49 49
    /// The value type of the map. (The type of objects associated with the keys).
50 50
    typedef T Value;
51 51
  };
52 52

	
53 53
  /// Null map. (a.k.a. DoNothingMap)
54 54

	
55 55
  /// This map can be used if you have to provide a map only for
56 56
  /// its type definitions, or if you have to provide a writable map, 
57 57
  /// but data written to it is not required (i.e. it will be sent to 
58 58
  /// <tt>/dev/null</tt>).
59 59
  template<typename K, typename T>
60 60
  class NullMap : public MapBase<K, T> {
61 61
  public:
62 62
    typedef MapBase<K, T> Parent;
63 63
    typedef typename Parent::Key Key;
64 64
    typedef typename Parent::Value Value;
65 65
    
66 66
    /// Gives back a default constructed element.
67 67
    T operator[](const K&) const { return T(); }
68 68
    /// Absorbs the value.
69 69
    void set(const K&, const T&) {}
70 70
  };
71 71

	
72 72
  ///Returns a \c NullMap class
73 73

	
74 74
  ///This function just returns a \c NullMap class.
75 75
  ///\relates NullMap
76 76
  template <typename K, typename V> 
77 77
  NullMap<K, V> nullMap() {
78 78
    return NullMap<K, V>();
79 79
  }
80 80

	
81 81

	
82 82
  /// Constant map.
83 83

	
84 84
  /// This is a readable map which assigns a specified value to each key.
85 85
  /// In other aspects it is equivalent to the \c NullMap.
86 86
  template<typename K, typename T>
87 87
  class ConstMap : public MapBase<K, T> {
88 88
  private:
89 89
    T v;
90 90
  public:
91 91

	
92 92
    typedef MapBase<K, T> Parent;
93 93
    typedef typename Parent::Key Key;
94 94
    typedef typename Parent::Value Value;
95 95

	
96 96
    /// Default constructor
97 97

	
98 98
    /// Default constructor.
99 99
    /// The value of the map will be uninitialized. 
100 100
    /// (More exactly it will be default constructed.)
101 101
    ConstMap() {}
102 102
    
103 103
    /// Constructor with specified initial value
104 104

	
105 105
    /// Constructor with specified initial value.
106 106
    /// \param _v is the initial value of the map.
107 107
    ConstMap(const T &_v) : v(_v) {}
108 108
    
109 109
    ///\e
110 110
    T operator[](const K&) const { return v; }
111 111

	
112 112
    ///\e
113 113
    void setAll(const T &t) {
114 114
      v = t;
115 115
    }    
116 116

	
117 117
    template<typename T1>
118 118
    ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
119 119
  };
120 120

	
121 121
  ///Returns a \c ConstMap class
122 122

	
123 123
  ///This function just returns a \c ConstMap class.
124 124
  ///\relates ConstMap
125 125
  template<typename K, typename V> 
126 126
  inline ConstMap<K, V> constMap(const V &v) {
127 127
    return ConstMap<K, V>(v);
128 128
  }
129 129

	
130 130

	
131 131
  template<typename T, T v>
132 132
  struct Const { };
133 133

	
134 134
  /// Constant map with inlined constant value.
135 135

	
136 136
  /// This is a readable map which assigns a specified value to each key.
137 137
  /// In other aspects it is equivalent to the \c NullMap.
138 138
  template<typename K, typename V, V v>
139 139
  class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
140 140
  public:
141 141
    typedef MapBase<K, V> Parent;
142 142
    typedef typename Parent::Key Key;
143 143
    typedef typename Parent::Value Value;
144 144

	
145 145
    ConstMap() { }
146 146
    ///\e
147 147
    V operator[](const K&) const { return v; }
148 148
    ///\e
149 149
    void set(const K&, const V&) { }
150 150
  };
151 151

	
152 152
  ///Returns a \c ConstMap class
153 153

	
154 154
  ///This function just returns a \c ConstMap class with inlined value.
155 155
  ///\relates ConstMap
156 156
  template<typename K, typename V, V v> 
157 157
  inline ConstMap<K, Const<V, v> > constMap() {
158 158
    return ConstMap<K, Const<V, v> >();
159 159
  }
160 160

	
161 161
  ///Map based on std::map
162 162

	
163 163
  ///This is essentially a wrapper for \c std::map with addition that
164 164
  ///you can specify a default value different from \c Value().
165 165
  template <typename K, typename T, typename Compare = std::less<K> >
166
  class StdMap {
166
  class StdMap : public MapBase<K, T> {
167 167
    template <typename K1, typename T1, typename C1>
168 168
    friend class StdMap;
169 169
  public:
170 170

	
171
    typedef True ReferenceMapTag;
171
    typedef MapBase<K, T> Parent;
172 172
    ///\e
173
    typedef K Key;
173
    typedef typename Parent::Key Key;
174 174
    ///\e
175
    typedef T Value;
175
    typedef typename Parent::Value Value;
176 176
    ///\e
177 177
    typedef T& Reference;
178 178
    ///\e
179 179
    typedef const T& ConstReference;
180 180

	
181
    typedef True ReferenceMapTag;
182

	
181 183
  private:
182 184
    
183 185
    typedef std::map<K, T, Compare> Map;
184 186
    Value _value;
185 187
    Map _map;
186 188

	
187 189
  public:
188 190

	
189 191
    /// Constructor with specified default value
190 192
    StdMap(const T& value = T()) : _value(value) {}
191 193
    /// \brief Constructs the map from an appropriate std::map, and explicitly
192 194
    /// specifies a default value.
193 195
    template <typename T1, typename Comp1>
194 196
    StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 
195 197
      : _map(map.begin(), map.end()), _value(value) {}
196 198
    
197 199
    /// \brief Constructs a map from an other StdMap.
198 200
    template<typename T1, typename Comp1>
199 201
    StdMap(const StdMap<Key, T1, Comp1> &c) 
200 202
      : _map(c._map.begin(), c._map.end()), _value(c._value) {}
201 203

	
202 204
  private:
203 205

	
204 206
    StdMap& operator=(const StdMap&);
205 207

	
206 208
  public:
207 209

	
208 210
    ///\e
209 211
    Reference operator[](const Key &k) {
210 212
      typename Map::iterator it = _map.lower_bound(k);
211 213
      if (it != _map.end() && !_map.key_comp()(k, it->first))
212 214
	return it->second;
213 215
      else
214 216
	return _map.insert(it, std::make_pair(k, _value))->second;
215 217
    }
216 218

	
217 219
    /// \e 
218 220
    ConstReference operator[](const Key &k) const {
219 221
      typename Map::const_iterator it = _map.find(k);
220 222
      if (it != _map.end())
221 223
	return it->second;
222 224
      else
223 225
	return _value;
224 226
    }
225 227

	
226 228
    /// \e 
227 229
    void set(const Key &k, const T &t) {
228 230
      typename Map::iterator it = _map.lower_bound(k);
229 231
      if (it != _map.end() && !_map.key_comp()(k, it->first))
230 232
	it->second = t;
231 233
      else
232 234
	_map.insert(it, std::make_pair(k, t));
233 235
    }
234 236

	
235 237
    /// \e
236 238
    void setAll(const T &t) {
237 239
      _value = t;
238 240
      _map.clear();
239 241
    }    
240 242

	
241 243
  };
244
  
245
  ///Returns a \ref StdMap class
246

	
247
  ///This function just returns a \ref StdMap class with specified 
248
  ///default value.
249
  ///\relates StdMap
250
  template<typename K, typename V, typename Compare = std::less<K> > 
251
  inline StdMap<K, V, Compare> stdMap(const V& value = V()) {
252
    return StdMap<K, V, Compare>(value);
253
  }
254

	
255
  ///Returns a \ref StdMap class created from an appropriate std::map
256

	
257
  ///This function just returns a \ref StdMap class created from an 
258
  ///appropriate std::map.
259
  ///\relates StdMap
260
  template<typename K, typename V, typename Compare = std::less<K> > 
261
  inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, 
262
                                       const V& value = V() ) {
263
    return StdMap<K, V, Compare>(map, value);
264
  }
242 265

	
243 266
  /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
244 267
  ///
245 268
  /// The current map has the <tt>[0..size-1]</tt> keyset and the values
246 269
  /// are stored in a \c std::vector<T>  container. It can be used with
247 270
  /// some data structures, for example \c UnionFind, \c BinHeap, when 
248 271
  /// the used items are small integer numbers. 
249 272
  ///
250 273
  /// \todo Revise its name
251 274
  template <typename T>
252
  class IntegerMap {
275
  class IntegerMap : public MapBase<int, T> {
253 276

	
254 277
    template <typename T1>
255 278
    friend class IntegerMap;
256 279

	
257 280
  public:
258 281

	
259
    typedef True ReferenceMapTag;
282
    typedef MapBase<int, T> Parent;
260 283
    ///\e
261
    typedef int Key;
284
    typedef typename Parent::Key Key;
262 285
    ///\e
263
    typedef T Value;
286
    typedef typename Parent::Value Value;
264 287
    ///\e
265 288
    typedef T& Reference;
266 289
    ///\e
267 290
    typedef const T& ConstReference;
268 291

	
292
    typedef True ReferenceMapTag;
293

	
269 294
  private:
270 295
    
271 296
    typedef std::vector<T> Vector;
272 297
    Vector _vector;
273 298

	
274 299
  public:
275 300

	
276 301
    /// Constructor with specified default value
277 302
    IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {}
278 303

	
279 304
    /// \brief Constructs the map from an appropriate std::vector.
280 305
    template <typename T1>
281 306
    IntegerMap(const std::vector<T1>& vector) 
282 307
      : _vector(vector.begin(), vector.end()) {}
283 308
    
284 309
    /// \brief Constructs a map from an other IntegerMap.
285 310
    template <typename T1>
286 311
    IntegerMap(const IntegerMap<T1> &c) 
287 312
      : _vector(c._vector.begin(), c._vector.end()) {}
288 313

	
289 314
    /// \brief Resize the container
290 315
    void resize(int size, const T& value = T()) {
291 316
      _vector.resize(size, value);
292 317
    }
293 318

	
294 319
  private:
295 320

	
296 321
    IntegerMap& operator=(const IntegerMap&);
297 322

	
298 323
  public:
299 324

	
300 325
    ///\e
301 326
    Reference operator[](Key k) {
302 327
      return _vector[k];
303 328
    }
304 329

	
305 330
    /// \e 
306 331
    ConstReference operator[](Key k) const {
307 332
      return _vector[k];
308 333
    }
309 334

	
310 335
    /// \e 
311 336
    void set(const Key &k, const T& t) {
312 337
      _vector[k] = t;
313 338
    }
314 339

	
315 340
  };
341
  
342
  ///Returns an \ref IntegerMap class
343

	
344
  ///This function just returns an \ref IntegerMap class.
345
  ///\relates IntegerMap
346
  template<typename T>
347
  inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {
348
    return IntegerMap<T>(size, value);
349
  }
316 350

	
317 351
  /// @}
318 352

	
319 353
  /// \addtogroup map_adaptors
320 354
  /// @{
321 355

	
322 356
  /// \brief Identity map.
323 357
  ///
324 358
  /// This map gives back the given key as value without any
325 359
  /// modification. 
326 360
  template <typename T>
327 361
  class IdentityMap : public MapBase<T, T> {
328 362
  public:
329 363
    typedef MapBase<T, T> Parent;
330 364
    typedef typename Parent::Key Key;
331 365
    typedef typename Parent::Value Value;
332 366

	
333 367
    /// \e
334 368
    const T& operator[](const T& t) const {
335 369
      return t;
336 370
    }
337 371
  };
338 372

	
339 373
  ///Returns an \c IdentityMap class
340 374

	
341 375
  ///This function just returns an \c IdentityMap class.
342 376
  ///\relates IdentityMap
343 377
  template<typename T>
344 378
  inline IdentityMap<T> identityMap() {
345 379
    return IdentityMap<T>();
346 380
  }
347 381
  
348 382

	
349 383
  ///\brief Convert the \c Value of a map to another type using
350 384
  ///the default conversion.
351 385
  ///
352 386
  ///This \c concepts::ReadMap "read only map"
353 387
  ///converts the \c Value of a map to type \c T.
354 388
  ///Its \c Key is inherited from \c M.
355 389
  template <typename M, typename T> 
356 390
  class ConvertMap : public MapBase<typename M::Key, T> {
357 391
    const M& m;
358 392
  public:
359 393
    typedef MapBase<typename M::Key, T> Parent;
360 394
    typedef typename Parent::Key Key;
361 395
    typedef typename Parent::Value Value;
362 396

	
363 397
    ///Constructor
364 398

	
365 399
    ///Constructor.
366 400
    ///\param _m is the underlying map.
367 401
    ConvertMap(const M &_m) : m(_m) {};
368 402

	
369 403
    /// \brief The subscript operator.
370 404
    ///
371 405
    /// The subscript operator.
372 406
    Value operator[](const Key& k) const {return m[k];}
373 407
  };
374 408
  
375 409
  ///Returns a \c ConvertMap class
376 410

	
377 411
  ///This function just returns a \c ConvertMap class.
378 412
  ///\relates ConvertMap
379 413
  template<typename T, typename M>
380 414
  inline ConvertMap<M, T> convertMap(const M &m) {
381 415
    return ConvertMap<M, T>(m);
382 416
  }
383 417

	
384 418
  ///Simple wrapping of a map
385 419

	
386 420
  ///This \ref concepts::ReadMap "read only map" returns the simple
387 421
  ///wrapping of the given map. Sometimes the reference maps cannot be
388 422
  ///combined with simple read maps. This map adaptor wraps the given
389 423
  ///map to simple read map.
390 424
  ///
391 425
  ///\sa SimpleWriteMap
392 426
  ///
393 427
  /// \todo Revise the misleading name 
394 428
  template<typename M> 
395 429
  class SimpleMap : public MapBase<typename M::Key, typename M::Value> {
396 430
    const M& m;
397 431

	
398 432
  public:
399 433
    typedef MapBase<typename M::Key, typename M::Value> Parent;
400 434
    typedef typename Parent::Key Key;
401 435
    typedef typename Parent::Value Value;
402 436

	
403 437
    ///Constructor
404 438
    SimpleMap(const M &_m) : m(_m) {};
405 439
    ///\e
406 440
    Value operator[](Key k) const {return m[k];}
407 441
  };
442
  
443
  ///Returns a \ref SimpleMap class
444

	
445
  ///This function just returns a \ref SimpleMap class.
446
  ///\relates SimpleMap
447
  template<typename M>
448
  inline SimpleMap<M> simpleMap(const M &m) {
449
    return SimpleMap<M>(m);
450
  }
408 451

	
409 452
  ///Simple writable wrapping of a map
410 453

	
411 454
  ///This \ref concepts::WriteMap "write map" returns the simple
412 455
  ///wrapping of the given map. Sometimes the reference maps cannot be
413 456
  ///combined with simple read-write maps. This map adaptor wraps the
414 457
  ///given map to simple read-write map.
415 458
  ///
416 459
  ///\sa SimpleMap
417 460
  ///
418 461
  /// \todo Revise the misleading name
419 462
  template<typename M> 
420 463
  class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> {
421 464
    M& m;
422 465

	
423 466
  public:
424 467
    typedef MapBase<typename M::Key, typename M::Value> Parent;
425 468
    typedef typename Parent::Key Key;
426 469
    typedef typename Parent::Value Value;
427 470

	
428 471
    ///Constructor
429 472
    SimpleWriteMap(M &_m) : m(_m) {};
430 473
    ///\e
431 474
    Value operator[](Key k) const {return m[k];}
432 475
    ///\e
433 476
    void set(Key k, const Value& c) { m.set(k, c); }
434 477
  };
435 478

	
479
  ///Returns a \ref SimpleWriteMap class
480

	
481
  ///This function just returns a \ref SimpleWriteMap class.
482
  ///\relates SimpleWriteMap
483
  template<typename M>
484
  inline SimpleWriteMap<M> simpleWriteMap(M &m) {
485
    return SimpleWriteMap<M>(m);
486
  }
487

	
436 488
  ///Sum of two maps
437 489

	
438 490
  ///This \c concepts::ReadMap "read only map" returns the sum of the two
439 491
  ///given maps.
440 492
  ///Its \c Key and \c Value are inherited from \c M1.
441 493
  ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
442 494
  template<typename M1, typename M2> 
443 495
  class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
444 496
    const M1& m1;
445 497
    const M2& m2;
446 498

	
447 499
  public:
448 500
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
449 501
    typedef typename Parent::Key Key;
450 502
    typedef typename Parent::Value Value;
451 503

	
452 504
    ///Constructor
453 505
    AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
454 506
    ///\e
455 507
    Value operator[](Key k) const {return m1[k]+m2[k];}
456 508
  };
457 509
  
458 510
  ///Returns an \c AddMap class
459 511

	
460 512
  ///This function just returns an \c AddMap class.
461 513
  ///\todo How to call these type of functions?
462 514
  ///
463 515
  ///\relates AddMap
464 516
  template<typename M1, typename M2> 
465 517
  inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) {
466 518
    return AddMap<M1, M2>(m1,m2);
467 519
  }
468 520

	
469 521
  ///Shift a map with a constant.
470 522

	
471 523
  ///This \c concepts::ReadMap "read only map" returns the sum of the
472 524
  ///given map and a constant value.
473 525
  ///Its \c Key and \c Value are inherited from \c M.
474 526
  ///
475 527
  ///Actually,
476 528
  ///\code
477 529
  ///  ShiftMap<X> sh(x,v);
478 530
  ///\endcode
479 531
  ///is equivalent to
480 532
  ///\code
481 533
  ///  ConstMap<X::Key, X::Value> c_tmp(v);
482 534
  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
483 535
  ///\endcode
484 536
  ///
485 537
  ///\sa ShiftWriteMap
486 538
  template<typename M, typename C = typename M::Value> 
487 539
  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
488 540
    const M& m;
489 541
    C v;
490 542
  public:
491 543
    typedef MapBase<typename M::Key, typename M::Value> Parent;
492 544
    typedef typename Parent::Key Key;
493 545
    typedef typename Parent::Value Value;
494 546

	
495 547
    ///Constructor
496 548

	
497 549
    ///Constructor.
498 550
    ///\param _m is the undelying map.
499 551
    ///\param _v is the shift value.
500 552
    ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
501 553
    ///\e
502 554
    Value operator[](Key k) const {return m[k] + v;}
503 555
  };
504 556

	
505 557
  ///Shift a map with a constant (ReadWrite version).
506 558

	
507 559
  ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the
508 560
  ///given map and a constant value. It makes also possible to write the map.
509 561
  ///Its \c Key and \c Value are inherited from \c M.
510 562
  ///
511 563
  ///\sa ShiftMap
512 564
  template<typename M, typename C = typename M::Value> 
513 565
  class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
514 566
    M& m;
515 567
    C v;
516 568
  public:
517 569
    typedef MapBase<typename M::Key, typename M::Value> Parent;
518 570
    typedef typename Parent::Key Key;
519 571
    typedef typename Parent::Value Value;
520 572

	
521 573
    ///Constructor
522 574

	
523 575
    ///Constructor.
524 576
    ///\param _m is the undelying map.
525 577
    ///\param _v is the shift value.
526 578
    ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
527 579
    /// \e
528 580
    Value operator[](Key k) const {return m[k] + v;}
529 581
    /// \e
530 582
    void set(Key k, const Value& c) { m.set(k, c - v); }
531 583
  };
532 584
  
533 585
  ///Returns a \c ShiftMap class
534 586

	
535 587
  ///This function just returns a \c ShiftMap class.
536 588
  ///\relates ShiftMap
537 589
  template<typename M, typename C> 
538 590
  inline ShiftMap<M, C> shiftMap(const M &m,const C &v) {
539 591
    return ShiftMap<M, C>(m,v);
540 592
  }
541 593

	
542 594
  ///Returns a \c ShiftWriteMap class
543 595

	
544 596
  ///This function just returns a \c ShiftWriteMap class.
545 597
  ///\relates ShiftWriteMap
546 598
  template<typename M, typename C> 
547 599
  inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) {
548 600
    return ShiftWriteMap<M, C>(m,v);
549 601
  }
550 602

	
551 603
  ///Difference of two maps
552 604

	
553 605
  ///This \c concepts::ReadMap "read only map" returns the difference
554 606
  ///of the values of the two given maps.
555 607
  ///Its \c Key and \c Value are inherited from \c M1.
556 608
  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
557 609
  ///
558 610
  /// \todo Revise the misleading name
559 611
  template<typename M1, typename M2> 
560 612
  class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
561 613
    const M1& m1;
562 614
    const M2& m2;
563 615
  public:
564 616
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
565 617
    typedef typename Parent::Key Key;
566 618
    typedef typename Parent::Value Value;
567 619

	
568 620
    ///Constructor
569 621
    SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
570 622
    /// \e
571 623
    Value operator[](Key k) const {return m1[k]-m2[k];}
572 624
  };
573 625
  
574 626
  ///Returns a \c SubMap class
575 627

	
576 628
  ///This function just returns a \c SubMap class.
577 629
  ///
578 630
  ///\relates SubMap
579 631
  template<typename M1, typename M2> 
580 632
  inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
581 633
    return SubMap<M1, M2>(m1, m2);
582 634
  }
583 635

	
584 636
  ///Product of two maps
585 637

	
586 638
  ///This \c concepts::ReadMap "read only map" returns the product of the
587 639
  ///values of the two given maps.
588 640
  ///Its \c Key and \c Value are inherited from \c M1.
589 641
  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
590 642
  template<typename M1, typename M2> 
591 643
  class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
592 644
    const M1& m1;
593 645
    const M2& m2;
594 646
  public:
595 647
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
596 648
    typedef typename Parent::Key Key;
597 649
    typedef typename Parent::Value Value;
598 650

	
599 651
    ///Constructor
600 652
    MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
601 653
    /// \e
602 654
    Value operator[](Key k) const {return m1[k]*m2[k];}
603 655
  };
604 656
  
605 657
  ///Returns a \c MulMap class
606 658

	
607 659
  ///This function just returns a \c MulMap class.
608 660
  ///\relates MulMap
609 661
  template<typename M1, typename M2> 
610 662
  inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
611 663
    return MulMap<M1, M2>(m1,m2);
612 664
  }
613 665
 
614 666
  ///Scales a map with a constant.
615 667

	
616 668
  ///This \c concepts::ReadMap "read only map" returns the value of the
617 669
  ///given map multiplied from the left side with a constant value.
618 670
  ///Its \c Key and \c Value are inherited from \c M.
619 671
  ///
620 672
  ///Actually,
621 673
  ///\code
622 674
  ///  ScaleMap<X> sc(x,v);
623 675
  ///\endcode
624 676
  ///is equivalent to
625 677
  ///\code
626 678
  ///  ConstMap<X::Key, X::Value> c_tmp(v);
627 679
  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
628 680
  ///\endcode
629 681
  ///
630 682
  ///\sa ScaleWriteMap
631 683
  template<typename M, typename C = typename M::Value> 
632 684
  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
633 685
    const M& m;
634 686
    C v;
635 687
  public:
636 688
    typedef MapBase<typename M::Key, typename M::Value> Parent;
637 689
    typedef typename Parent::Key Key;
638 690
    typedef typename Parent::Value Value;
639 691

	
640 692
    ///Constructor
641 693

	
642 694
    ///Constructor.
643 695
    ///\param _m is the undelying map.
644 696
    ///\param _v is the scaling value.
645 697
    ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {};
646 698
    /// \e
647 699
    Value operator[](Key k) const {return v * m[k];}
648 700
  };
649 701

	
650 702
  ///Scales a map with a constant (ReadWrite version).
651 703

	
652 704
  ///This \c concepts::ReadWriteMap "read-write map" returns the value of the
653 705
  ///given map multiplied from the left side with a constant value. It can
654 706
  ///also be used as write map if the \c / operator is defined between
655 707
  ///\c Value and \c C and the given multiplier is not zero.
656 708
  ///Its \c Key and \c Value are inherited from \c M.
657 709
  ///
658 710
  ///\sa ScaleMap
659 711
  template<typename M, typename C = typename M::Value> 
660 712
  class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
661 713
    M& m;
662 714
    C v;
663 715
  public:
664 716
    typedef MapBase<typename M::Key, typename M::Value> Parent;
665 717
    typedef typename Parent::Key Key;
666 718
    typedef typename Parent::Value Value;
667 719

	
668 720
    ///Constructor
669 721

	
670 722
    ///Constructor.
671 723
    ///\param _m is the undelying map.
672 724
    ///\param _v is the scaling value.
673 725
    ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {};
674 726
    /// \e
675 727
    Value operator[](Key k) const {return v * m[k];}
676 728
    /// \e
677 729
    void set(Key k, const Value& c) { m.set(k, c / v);}
678 730
  };
679 731
  
680 732
  ///Returns a \c ScaleMap class
681 733

	
682 734
  ///This function just returns a \c ScaleMap class.
683 735
  ///\relates ScaleMap
684 736
  template<typename M, typename C> 
685 737
  inline ScaleMap<M, C> scaleMap(const M &m,const C &v) {
686 738
    return ScaleMap<M, C>(m,v);
687 739
  }
688 740

	
689 741
  ///Returns a \c ScaleWriteMap class
690 742

	
691 743
  ///This function just returns a \c ScaleWriteMap class.
692 744
  ///\relates ScaleWriteMap
693 745
  template<typename M, typename C> 
694 746
  inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) {
695 747
    return ScaleWriteMap<M, C>(m,v);
696 748
  }
697 749

	
698 750
  ///Quotient of two maps
699 751

	
700 752
  ///This \c concepts::ReadMap "read only map" returns the quotient of the
701 753
  ///values of the two given maps.
702 754
  ///Its \c Key and \c Value are inherited from \c M1.
703 755
  ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
704 756
  template<typename M1, typename M2> 
705 757
  class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
706 758
    const M1& m1;
707 759
    const M2& m2;
708 760
  public:
709 761
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
710 762
    typedef typename Parent::Key Key;
711 763
    typedef typename Parent::Value Value;
712 764

	
713 765
    ///Constructor
714 766
    DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
715 767
    /// \e
716 768
    Value operator[](Key k) const {return m1[k]/m2[k];}
717 769
  };
718 770
  
719 771
  ///Returns a \c DivMap class
720 772

	
721 773
  ///This function just returns a \c DivMap class.
722 774
  ///\relates DivMap
723 775
  template<typename M1, typename M2> 
724 776
  inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
725 777
    return DivMap<M1, M2>(m1,m2);
726 778
  }
727 779
  
728 780
  ///Composition of two maps
729 781

	
730 782
  ///This \c concepts::ReadMap "read only map" returns the composition of
731 783
  ///two given maps.
732 784
  ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2,
733 785
  ///then for
734 786
  ///\code
735 787
  ///  ComposeMap<M1, M2> cm(m1,m2);
736 788
  ///\endcode
737 789
  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
738 790
  ///
739 791
  ///Its \c Key is inherited from \c M2 and its \c Value is from \c M1.
740 792
  ///\c M2::Value must be convertible to \c M1::Key.
741 793
  ///
742 794
  ///\sa CombineMap
743 795
  ///
744 796
  ///\todo Check the requirements.
745 797
  template <typename M1, typename M2> 
746 798
  class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> {
747 799
    const M1& m1;
748 800
    const M2& m2;
749 801
  public:
750 802
    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
751 803
    typedef typename Parent::Key Key;
752 804
    typedef typename Parent::Value Value;
753 805

	
754 806
    ///Constructor
755 807
    ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
756 808
    
757 809
    /// \e
758 810

	
759 811

	
760 812
    /// \todo Use the  MapTraits once it is ported.
761 813
    ///
762 814

	
763 815
    //typename MapTraits<M1>::ConstReturnValue
764 816
    typename M1::Value
765 817
    operator[](Key k) const {return m1[m2[k]];}
766 818
  };
767 819

	
768 820
  ///Returns a \c ComposeMap class
769 821

	
770 822
  ///This function just returns a \c ComposeMap class.
771 823
  ///\relates ComposeMap
772 824
  template <typename M1, typename M2> 
773 825
  inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) {
774 826
    return ComposeMap<M1, M2>(m1,m2);
775 827
  }
776 828
  
777 829
  ///Combine of two maps using an STL (binary) functor.
778 830

	
779 831
  ///Combine of two maps using an STL (binary) functor.
780 832
  ///
781 833
  ///This \c concepts::ReadMap "read only map" takes two maps and a
782 834
  ///binary functor and returns the composition of the two
783 835
  ///given maps unsing the functor. 
784 836
  ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
785 837
  ///and \c f is of \c F, then for
786 838
  ///\code
787 839
  ///  CombineMap<M1,M2,F,V> cm(m1,m2,f);
788 840
  ///\endcode
789 841
  /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
790 842
  ///
791 843
  ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
792 844
  ///\c M2::Value and \c M1::Value must be convertible to the corresponding
793 845
  ///input parameter of \c F and the return type of \c F must be convertible
794 846
  ///to \c V.
795 847
  ///
796 848
  ///\sa ComposeMap
797 849
  ///
798 850
  ///\todo Check the requirements.
799 851
  template<typename M1, typename M2, typename F,
800 852
	   typename V = typename F::result_type> 
801 853
  class CombineMap : public MapBase<typename M1::Key, V> {
802 854
    const M1& m1;
803 855
    const M2& m2;
804 856
    F f;
805 857
  public:
806 858
    typedef MapBase<typename M1::Key, V> Parent;
807 859
    typedef typename Parent::Key Key;
808 860
    typedef typename Parent::Value Value;
809 861

	
810 862
    ///Constructor
811 863
    CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
812 864
      : m1(_m1), m2(_m2), f(_f) {};
813 865
    /// \e
814 866
    Value operator[](Key k) const {return f(m1[k],m2[k]);}
815 867
  };
816 868
  
817 869
  ///Returns a \c CombineMap class
818 870

	
819 871
  ///This function just returns a \c CombineMap class.
820 872
  ///
821 873
  ///For example if \c m1 and \c m2 are both \c double valued maps, then 
822 874
  ///\code
823 875
  ///combineMap(m1,m2,std::plus<double>())
824 876
  ///\endcode
825 877
  ///is equivalent to
826 878
  ///\code
827 879
  ///addMap(m1,m2)
828 880
  ///\endcode
829 881
  ///
830 882
  ///This function is specialized for adaptable binary function
831 883
  ///classes and C++ functions.
832 884
  ///
833 885
  ///\relates CombineMap
834 886
  template<typename M1, typename M2, typename F, typename V> 
835 887
  inline CombineMap<M1, M2, F, V> 
836 888
  combineMap(const M1& m1,const M2& m2, const F& f) {
837 889
    return CombineMap<M1, M2, F, V>(m1,m2,f);
838 890
  }
839 891

	
840 892
  template<typename M1, typename M2, typename F> 
841 893
  inline CombineMap<M1, M2, F, typename F::result_type> 
842 894
  combineMap(const M1& m1, const M2& m2, const F& f) {
843 895
    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
844 896
  }
845 897

	
846 898
  template<typename M1, typename M2, typename K1, typename K2, typename V> 
847 899
  inline CombineMap<M1, M2, V (*)(K1, K2), V> 
848 900
  combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
849 901
    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
850 902
  }
851 903

	
852 904
  ///Negative value of a map
853 905

	
854 906
  ///This \c concepts::ReadMap "read only map" returns the negative
855 907
  ///value of the value returned by the given map.
856 908
  ///Its \c Key and \c Value are inherited from \c M.
857 909
  ///The unary \c - operator must be defined for \c Value, of course.
858 910
  ///
859 911
  ///\sa NegWriteMap
860 912
  template<typename M> 
861 913
  class NegMap : public MapBase<typename M::Key, typename M::Value> {
862 914
    const M& m;
863 915
  public:
864 916
    typedef MapBase<typename M::Key, typename M::Value> Parent;
865 917
    typedef typename Parent::Key Key;
866 918
    typedef typename Parent::Value Value;
867 919

	
868 920
    ///Constructor
869 921
    NegMap(const M &_m) : m(_m) {};
870 922
    /// \e
871 923
    Value operator[](Key k) const {return -m[k];}
872 924
  };
873 925
  
874 926
  ///Negative value of a map (ReadWrite version)
875 927

	
876 928
  ///This \c concepts::ReadWriteMap "read-write map" returns the negative
877 929
  ///value of the value returned by the given map.
878 930
  ///Its \c Key and \c Value are inherited from \c M.
879 931
  ///The unary \c - operator must be defined for \c Value, of course.
880 932
  ///
881 933
  /// \sa NegMap
882 934
  template<typename M> 
883 935
  class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
884 936
    M& m;
885 937
  public:
886 938
    typedef MapBase<typename M::Key, typename M::Value> Parent;
887 939
    typedef typename Parent::Key Key;
888 940
    typedef typename Parent::Value Value;
889 941

	
890 942
    ///Constructor
891 943
    NegWriteMap(M &_m) : m(_m) {};
892 944
    /// \e
893 945
    Value operator[](Key k) const {return -m[k];}
894 946
    /// \e
895 947
    void set(Key k, const Value& v) { m.set(k, -v); }
896 948
  };
897 949

	
898 950
  ///Returns a \c NegMap class
899 951

	
900 952
  ///This function just returns a \c NegMap class.
901 953
  ///\relates NegMap
902 954
  template <typename M> 
903 955
  inline NegMap<M> negMap(const M &m) {
904 956
    return NegMap<M>(m);
905 957
  }
906 958

	
907 959
  ///Returns a \c NegWriteMap class
908 960

	
909 961
  ///This function just returns a \c NegWriteMap class.
910 962
  ///\relates NegWriteMap
911 963
  template <typename M> 
912 964
  inline NegWriteMap<M> negMap(M &m) {
913 965
    return NegWriteMap<M>(m);
914 966
  }
915 967

	
916 968
  ///Absolute value of a map
917 969

	
918 970
  ///This \c concepts::ReadMap "read only map" returns the absolute value
919 971
  ///of the value returned by the given map.
920 972
  ///Its \c Key and \c Value are inherited from \c M. 
921 973
  ///\c Value must be comparable to \c 0 and the unary \c -
922 974
  ///operator must be defined for it, of course.
923 975
  template<typename M> 
924 976
  class AbsMap : public MapBase<typename M::Key, typename M::Value> {
925 977
    const M& m;
926 978
  public:
927 979
    typedef MapBase<typename M::Key, typename M::Value> Parent;
928 980
    typedef typename Parent::Key Key;
929 981
    typedef typename Parent::Value Value;
930 982

	
931 983
    ///Constructor
932 984
    AbsMap(const M &_m) : m(_m) {};
933 985
    /// \e
934 986
    Value operator[](Key k) const {
935 987
      Value tmp = m[k]; 
936 988
      return tmp >= 0 ? tmp : -tmp;
937 989
    }
938 990

	
939 991
  };
940 992
  
941 993
  ///Returns an \c AbsMap class
942 994

	
943 995
  ///This function just returns an \c AbsMap class.
944 996
  ///\relates AbsMap
945 997
  template<typename M> 
946 998
  inline AbsMap<M> absMap(const M &m) {
947 999
    return AbsMap<M>(m);
948 1000
  }
949 1001

	
950 1002
  ///Converts an STL style functor to a map
951 1003

	
952 1004
  ///This \c concepts::ReadMap "read only map" returns the value
953 1005
  ///of a given functor.
954 1006
  ///
955 1007
  ///Template parameters \c K and \c V will become its
956 1008
  ///\c Key and \c Value. 
957 1009
  ///In most cases they have to be given explicitly because a 
958 1010
  ///functor typically does not provide such typedefs.
959 1011
  ///
960 1012
  ///Parameter \c F is the type of the used functor.
961 1013
  ///
962 1014
  ///\sa MapFunctor
963 1015
  template<typename F, 
964 1016
	   typename K = typename F::argument_type, 
965 1017
	   typename V = typename F::result_type> 
966 1018
  class FunctorMap : public MapBase<K, V> {
967 1019
    F f;
968 1020
  public:
969 1021
    typedef MapBase<K, V> Parent;
970 1022
    typedef typename Parent::Key Key;
971 1023
    typedef typename Parent::Value Value;
972 1024

	
973 1025
    ///Constructor
974 1026
    FunctorMap(const F &_f = F()) : f(_f) {}
975 1027
    /// \e
976 1028
    Value operator[](Key k) const { return f(k);}
977 1029
  };
978 1030
  
979 1031
  ///Returns a \c FunctorMap class
980 1032

	
981 1033
  ///This function just returns a \c FunctorMap class.
982 1034
  ///
983 1035
  ///It is specialized for adaptable function classes and
984 1036
  ///C++ functions.
985 1037
  ///\relates FunctorMap
986 1038
  template<typename K, typename V, typename F> inline 
987 1039
  FunctorMap<F, K, V> functorMap(const F &f) {
988 1040
    return FunctorMap<F, K, V>(f);
989 1041
  }
990 1042

	
991 1043
  template <typename F> inline 
992 1044
  FunctorMap<F, typename F::argument_type, typename F::result_type> 
993 1045
  functorMap(const F &f) {
994 1046
    return FunctorMap<F, typename F::argument_type, 
995 1047
      typename F::result_type>(f);
996 1048
  }
997 1049

	
998 1050
  template <typename K, typename V> inline 
999 1051
  FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) {
1000 1052
    return FunctorMap<V (*)(K), K, V>(f);
1001 1053
  }
1002 1054

	
1003 1055

	
1004 1056
  ///Converts a map to an STL style (unary) functor
1005 1057

	
1006 1058
  ///This class Converts a map to an STL style (unary) functor.
1007 1059
  ///that is it provides an <tt>operator()</tt> to read its values.
1008 1060
  ///
1009 1061
  ///For the sake of convenience it also works as
1010 1062
  ///a ususal \c concepts::ReadMap "readable map",
1011 1063
  ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
1012 1064
  ///
1013 1065
  ///\sa FunctorMap
1014 1066
  template <typename M> 
1015 1067
  class MapFunctor : public MapBase<typename M::Key, typename M::Value> {
1016 1068
    const M& m;
1017 1069
  public:
1018 1070
    typedef MapBase<typename M::Key, typename M::Value> Parent;
1019 1071
    typedef typename Parent::Key Key;
1020 1072
    typedef typename Parent::Value Value;
1021 1073

	
1022 1074
    typedef typename M::Key argument_type;
1023 1075
    typedef typename M::Value result_type;
1024 1076

	
1025 1077
    ///Constructor
1026 1078
    MapFunctor(const M &_m) : m(_m) {};
1027 1079
    ///\e
1028 1080
    Value operator()(Key k) const {return m[k];}
1029 1081
    ///\e
1030 1082
    Value operator[](Key k) const {return m[k];}
1031 1083
  };
1032 1084
  
1033 1085
  ///Returns a \c MapFunctor class
1034 1086

	
1035 1087
  ///This function just returns a \c MapFunctor class.
1036 1088
  ///\relates MapFunctor
1037 1089
  template<typename M> 
1038 1090
  inline MapFunctor<M> mapFunctor(const M &m) {
1039 1091
    return MapFunctor<M>(m);
1040 1092
  }
1041 1093

	
1042 1094
  ///Applies all map setting operations to two maps
1043 1095

	
1044 1096
  ///This map has two \c concepts::ReadMap "readable map"
1045 1097
  ///parameters and each read request will be passed just to the
1046 1098
  ///first map. This class is the just readable map type of the ForkWriteMap.
1047 1099
  ///
1048 1100
  ///The \c Key and \c Value are inherited from \c M1.
1049 1101
  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1050 1102
  ///
1051 1103
  ///\sa ForkWriteMap
1052 1104
  ///
1053 1105
  /// \todo Why is it needed?
1054 1106
  template<typename  M1, typename M2> 
1055 1107
  class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
1056 1108
    const M1& m1;
1057 1109
    const M2& m2;
1058 1110
  public:
1059 1111
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
1060 1112
    typedef typename Parent::Key Key;
1061 1113
    typedef typename Parent::Value Value;
1062 1114

	
1063 1115
    ///Constructor
1064 1116
    ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {};
1065 1117
    /// \e
1066 1118
    Value operator[](Key k) const {return m1[k];}
1067 1119
  };
1068 1120

	
1069 1121

	
1070 1122
  ///Applies all map setting operations to two maps
1071 1123

	
1072 1124
  ///This map has two \c concepts::WriteMap "writable map"
1073 1125
  ///parameters and each write request will be passed to both of them.
1074 1126
  ///If \c M1 is also \c concepts::ReadMap "readable",
1075 1127
  ///then the read operations will return the
1076 1128
  ///corresponding values of \c M1.
1077 1129
  ///
1078 1130
  ///The \c Key and \c Value are inherited from \c M1.
1079 1131
  ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
1080 1132
  ///
1081 1133
  ///\sa ForkMap
1082 1134
  template<typename  M1, typename M2> 
1083 1135
  class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> {
1084 1136
    M1& m1;
1085 1137
    M2& m2;
1086 1138
  public:
1087 1139
    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
1088 1140
    typedef typename Parent::Key Key;
1089 1141
    typedef typename Parent::Value Value;
1090 1142

	
1091 1143
    ///Constructor
1092 1144
    ForkWriteMap(M1 &_m1, M2 &_m2) : m1(_m1), m2(_m2) {};
1093 1145
    ///\e
1094 1146
    Value operator[](Key k) const {return m1[k];}
1095 1147
    ///\e
1096 1148
    void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
1097 1149
  };
1098 1150
  
1099 1151
  ///Returns a \c ForkMap class
1100 1152

	
1101 1153
  ///This function just returns a \c ForkMap class.
1102 1154
  ///\relates ForkMap
1103 1155
  template <typename M1, typename M2> 
1104 1156
  inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) {
1105 1157
    return ForkMap<M1, M2>(m1,m2);
1106 1158
  }
1107 1159

	
1108 1160
  ///Returns a \c ForkWriteMap class
1109 1161

	
1110 1162
  ///This function just returns a \c ForkWriteMap class.
1111 1163
  ///\relates ForkWriteMap
1112 1164
  template <typename M1, typename M2> 
1113 1165
  inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) {
1114 1166
    return ForkWriteMap<M1, M2>(m1,m2);
1115 1167
  }
1116 1168

	
1117 1169

	
1118 1170
  
1119 1171
  /* ************* BOOL MAPS ******************* */
1120 1172
  
1121 1173
  ///Logical 'not' of a map
1122 1174
  
1123 1175
  ///This bool \c concepts::ReadMap "read only map" returns the 
1124 1176
  ///logical negation of the value returned by the given map.
1125 1177
  ///Its \c Key is inherited from \c M, its Value is \c bool.
1126 1178
  ///
1127 1179
  ///\sa NotWriteMap
1128 1180
  template <typename M> 
1129 1181
  class NotMap : public MapBase<typename M::Key, bool> {
1130 1182
    const M& m;
1131 1183
  public:
1132 1184
    typedef MapBase<typename M::Key, bool> Parent;
1133 1185
    typedef typename Parent::Key Key;
1134 1186
    typedef typename Parent::Value Value;
1135 1187

	
1136 1188
    /// Constructor
1137 1189
    NotMap(const M &_m) : m(_m) {};
1138 1190
    ///\e
1139 1191
    Value operator[](Key k) const {return !m[k];}
1140 1192
  };
1141 1193

	
1142 1194
  ///Logical 'not' of a map (ReadWrie version)
1143 1195
  
1144 1196
  ///This bool \c concepts::ReadWriteMap "read-write map" returns the 
1145 1197
  ///logical negation of the value returned by the given map. When it is set,
1146 1198
  ///the opposite value is set to the original map.
1147 1199
  ///Its \c Key is inherited from \c M, its Value is \c bool.
1148 1200
  ///
1149 1201
  ///\sa NotMap
1150 1202
  template <typename M> 
1151 1203
  class NotWriteMap : public MapBase<typename M::Key, bool> {
1152 1204
    M& m;
1153 1205
  public:
1154 1206
    typedef MapBase<typename M::Key, bool> Parent;
1155 1207
    typedef typename Parent::Key Key;
1156 1208
    typedef typename Parent::Value Value;
1157 1209

	
1158 1210
    /// Constructor
1159 1211
    NotWriteMap(M &_m) : m(_m) {};
1160 1212
    ///\e
1161 1213
    Value operator[](Key k) const {return !m[k];}
1162 1214
    ///\e
1163 1215
    void set(Key k, bool v) { m.set(k, !v); }
1164 1216
  };
1165 1217
  
1166 1218
  ///Returns a \c NotMap class
1167 1219
  
1168 1220
  ///This function just returns a \c NotMap class.
1169 1221
  ///\relates NotMap
1170 1222
  template <typename M> 
1171 1223
  inline NotMap<M> notMap(const M &m) {
1172 1224
    return NotMap<M>(m);
1173 1225
  }
1174 1226
  
1175 1227
  ///Returns a \c NotWriteMap class
1176 1228
  
1177 1229
  ///This function just returns a \c NotWriteMap class.
1178 1230
  ///\relates NotWriteMap
1179 1231
  template <typename M> 
1180 1232
  inline NotWriteMap<M> notMap(M &m) {
1181 1233
    return NotWriteMap<M>(m);
1182 1234
  }
1183 1235

	
1184 1236
  namespace _maps_bits {
1185 1237

	
1186 1238
    template <typename Value>
1187 1239
    struct Identity {
1188 1240
      typedef Value argument_type;
1189 1241
      typedef Value result_type;
1190 1242
      Value operator()(const Value& val) const {
1191 1243
	return val;
1192 1244
      }
1193 1245
    };
1194 1246

	
1195 1247
    template <typename _Iterator, typename Enable = void>
1196 1248
    struct IteratorTraits {
1197 1249
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1198 1250
    };
1199 1251

	
1200 1252
    template <typename _Iterator>
1201 1253
    struct IteratorTraits<_Iterator,
1202 1254
      typename exists<typename _Iterator::container_type>::type> 
1203 1255
    {
0 comments (0 inline)