gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Add basic logical maps and doc improvements - Add the following new logical maps and map adaptors: * TrueMap, FalseMap * AndMap, OrMap * EqualMap, LessMap - Improve the documentation for other classes.
0 2 0
default
2 files changed with 334 insertions and 34 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -83,14 +83,14 @@
83 83
    return NullMap<K, V>();
84 84
  }
85 85

	
86 86

	
87 87
  /// Constant map.
88 88

	
89
  /// This is a \ref concepts::ReadMap "readable" map which assigns a
90
  /// specified value to each key.
89
  /// This \ref concepts::ReadMap "readable map" assigns a specified
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()
... ...
@@ -146,14 +146,14 @@
146 146

	
147 147
  template<typename T, T v>
148 148
  struct Const {};
149 149

	
150 150
  /// Constant map with inlined constant value.
151 151

	
152
  /// This is a \ref concepts::ReadMap "readable" map which assigns a
153
  /// specified value to each key.
152
  /// This \ref concepts::ReadMap "readable map" assigns a specified
153
  /// value to each key.
154 154
  ///
155 155
  /// In other aspects it is equivalent to \ref NullMap.
156 156
  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
157 157
  /// concept, but it absorbs the data written to it.
158 158
  ///
159 159
  /// The simplest way of using this map is through the constMap()
... ...
@@ -186,28 +186,28 @@
186 186
  template<typename K, typename V, V v>
187 187
  inline ConstMap<K, Const<V, v> > constMap() {
188 188
    return ConstMap<K, Const<V, v> >();
189 189
  }
190 190

	
191 191

	
192
  /// \brief Identity map.
193
  ///
194
  /// This map gives back the given key as value without any
195
  /// modification.
192
  /// Identity map.
193

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

	
205 205
    /// Gives back the given value without any modification.
206
    const T& operator[](const T& t) const {
207
      return t;
206
    Value operator[](const Key &k) const {
207
      return k;
208 208
    }
209 209
  };
210 210

	
211 211
  /// Returns an \ref IdentityMap class
212 212

	
213 213
  /// This function just returns an \ref IdentityMap class.
... ...
@@ -461,13 +461,13 @@
461 461

	
462 462
  /// \addtogroup map_adaptors
463 463
  /// @{
464 464

	
465 465
  /// Composition of two maps
466 466

	
467
  /// This \ref concepts::ReadMap "read only map" returns the
467
  /// This \ref concepts::ReadMap "read-only map" returns the
468 468
  /// composition of two given maps. That is to say, if \c m1 is of
469 469
  /// type \c M1 and \c m2 is of \c M2, then for
470 470
  /// \code
471 471
  ///   ComposeMap<M1, M2> cm(m1,m2);
472 472
  /// \endcode
473 473
  /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>.
... ...
@@ -513,13 +513,13 @@
513 513
    return ComposeMap<M1, M2>(m1, m2);
514 514
  }
515 515

	
516 516

	
517 517
  /// Combination of two maps using an STL (binary) functor.
518 518

	
519
  /// This \ref concepts::ReadMap "read only map" takes two maps and a
519
  /// This \ref concepts::ReadMap "read-only map" takes two maps and a
520 520
  /// binary functor and returns the combination of the two given maps
521 521
  /// using the functor.
522 522
  /// That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2
523 523
  /// and \c f is of \c F, then for
524 524
  /// \code
525 525
  ///   CombineMap<M1,M2,F,V> cm(m1,m2,f);
... ...
@@ -592,13 +592,13 @@
592 592
    return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
593 593
  }
594 594

	
595 595

	
596 596
  /// Converts an STL style (unary) functor to a map
597 597

	
598
  /// This \ref concepts::ReadMap "read only map" returns the value
598
  /// This \ref concepts::ReadMap "read-only map" returns the value
599 599
  /// of a given functor. Actually, it just wraps the functor and
600 600
  /// provides the \c Key and \c Value typedefs.
601 601
  ///
602 602
  /// Template parameters \c K and \c V will become its \c Key and
603 603
  /// \c Value. In most cases they have to be given explicitly because
604 604
  /// a functor typically does not provide \c argument_type and
... ...
@@ -772,13 +772,13 @@
772 772
    return ForkMap<M1,M2>(m1,m2);
773 773
  }
774 774

	
775 775

	
776 776
  /// Sum of two maps
777 777

	
778
  /// This \ref concepts::ReadMap "read only map" returns the sum
778
  /// This \ref concepts::ReadMap "read-only map" returns the sum
779 779
  /// of the values of the two given maps.
780 780
  /// Its \c Key and \c Value types are inherited from \c M1.
781 781
  /// The \c Key and \c Value of \c M2 must be convertible to those of
782 782
  /// \c M1.
783 783
  ///
784 784
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
... ...
@@ -821,13 +821,13 @@
821 821
    return AddMap<M1, M2>(m1,m2);
822 822
  }
823 823

	
824 824

	
825 825
  /// Difference of two maps
826 826

	
827
  /// This \ref concepts::ReadMap "read only map" returns the difference
827
  /// This \ref concepts::ReadMap "read-only map" returns the difference
828 828
  /// of the values of the two given maps.
829 829
  /// Its \c Key and \c Value types are inherited from \c M1.
830 830
  /// The \c Key and \c Value of \c M2 must be convertible to those of
831 831
  /// \c M1.
832 832
  ///
833 833
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
... ...
@@ -869,13 +869,13 @@
869 869
    return SubMap<M1, M2>(m1,m2);
870 870
  }
871 871

	
872 872

	
873 873
  /// Product of two maps
874 874

	
875
  /// This \ref concepts::ReadMap "read only map" returns the product
875
  /// This \ref concepts::ReadMap "read-only map" returns the product
876 876
  /// of the values of the two given maps.
877 877
  /// Its \c Key and \c Value types are inherited from \c M1.
878 878
  /// The \c Key and \c Value of \c M2 must be convertible to those of
879 879
  /// \c M1.
880 880
  ///
881 881
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
... ...
@@ -918,13 +918,13 @@
918 918
    return MulMap<M1, M2>(m1,m2);
919 919
  }
920 920

	
921 921

	
922 922
  /// Quotient of two maps
923 923

	
924
  /// This \ref concepts::ReadMap "read only map" returns the quotient
924
  /// This \ref concepts::ReadMap "read-only map" returns the quotient
925 925
  /// of the values of the two given maps.
926 926
  /// Its \c Key and \c Value types are inherited from \c M1.
927 927
  /// The \c Key and \c Value of \c M2 must be convertible to those of
928 928
  /// \c M1.
929 929
  ///
930 930
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
... ...
@@ -966,13 +966,13 @@
966 966
    return DivMap<M1, M2>(m1,m2);
967 967
  }
968 968

	
969 969

	
970 970
  /// Shifts a map with a constant.
971 971

	
972
  /// This \ref concepts::ReadMap "read only map" returns the sum of
972
  /// This \ref concepts::ReadMap "read-only map" returns the sum of
973 973
  /// the given map and a constant value (i.e. it shifts the map with
974 974
  /// the constant). Its \c Key and \c Value are inherited from \c M.
975 975
  ///
976 976
  /// Actually,
977 977
  /// \code
978 978
  ///   ShiftMap<M> sh(m,v);
... ...
@@ -1067,13 +1067,13 @@
1067 1067
    return ShiftWriteMap<M, C>(m,v);
1068 1068
  }
1069 1069

	
1070 1070

	
1071 1071
  /// Scales a map with a constant.
1072 1072

	
1073
  /// This \ref concepts::ReadMap "read only map" returns the value of
1073
  /// This \ref concepts::ReadMap "read-only map" returns the value of
1074 1074
  /// the given map multiplied from the left side with a constant value.
1075 1075
  /// Its \c Key and \c Value are inherited from \c M.
1076 1076
  ///
1077 1077
  /// Actually,
1078 1078
  /// \code
1079 1079
  ///   ScaleMap<M> sc(m,v);
... ...
@@ -1169,13 +1169,13 @@
1169 1169
    return ScaleWriteMap<M, C>(m,v);
1170 1170
  }
1171 1171

	
1172 1172

	
1173 1173
  /// Negative of a map
1174 1174

	
1175
  /// This \ref concepts::ReadMap "read only map" returns the negative
1175
  /// This \ref concepts::ReadMap "read-only map" returns the negative
1176 1176
  /// of the values of the given map (using the unary \c - operator).
1177 1177
  /// Its \c Key and \c Value are inherited from \c M.
1178 1178
  ///
1179 1179
  /// If M::Value is \c int, \c double etc., then
1180 1180
  /// \code
1181 1181
  ///   NegMap<M> neg(m);
... ...
@@ -1267,13 +1267,13 @@
1267 1267
    return NegWriteMap<M>(m);
1268 1268
  }
1269 1269

	
1270 1270

	
1271 1271
  /// Absolute value of a map
1272 1272

	
1273
  /// This \ref concepts::ReadMap "read only map" returns the absolute
1273
  /// This \ref concepts::ReadMap "read-only map" returns the absolute
1274 1274
  /// value of the values of the given map.
1275 1275
  /// Its \c Key and \c Value are inherited from \c M.
1276 1276
  /// \c Value must be comparable to \c 0 and the unary \c -
1277 1277
  /// operator must be defined for it, of course.
1278 1278
  ///
1279 1279
  /// The simplest way of using this map is through the absMap()
... ...
@@ -1308,16 +1308,196 @@
1308 1308
  /// \relates AbsMap
1309 1309
  template<typename M>
1310 1310
  inline AbsMap<M> absMap(const M &m) {
1311 1311
    return AbsMap<M>(m);
1312 1312
  }
1313 1313

	
1314
  /// @}
1315
  
1316
  // Logical maps and map adaptors:
1317

	
1318
  /// \addtogroup maps
1319
  /// @{
1320

	
1321
  /// Constant \c true map.
1322

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

	
1344
    /// Gives back \c true.
1345
    Value operator[](const Key&) const { return true; }
1346
  };
1347

	
1348
  /// Returns a \ref TrueMap class
1349

	
1350
  /// This function just returns a \ref TrueMap class.
1351
  /// \relates TrueMap
1352
  template<typename K>
1353
  inline TrueMap<K> trueMap() {
1354
    return TrueMap<K>();
1355
  }
1356

	
1357

	
1358
  /// Constant \c false map.
1359

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

	
1381
    /// Gives back \c false.
1382
    Value operator[](const Key&) const { return false; }
1383
  };
1384

	
1385
  /// Returns a \ref FalseMap class
1386

	
1387
  /// This function just returns a \ref FalseMap class.
1388
  /// \relates FalseMap
1389
  template<typename K>
1390
  inline FalseMap<K> falseMap() {
1391
    return FalseMap<K>();
1392
  }
1393

	
1394
  /// @}
1395

	
1396
  /// \addtogroup map_adaptors
1397
  /// @{
1398

	
1399
  /// Logical 'and' of two maps
1400

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

	
1426
    /// Constructor
1427
    AndMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1428
    /// \e
1429
    Value operator[](const Key &k) const { return _m1[k]&&_m2[k]; }
1430
  };
1431

	
1432
  /// Returns an \ref AndMap class
1433

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

	
1446

	
1447
  /// Logical 'or' of two maps
1448

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

	
1474
    /// Constructor
1475
    OrMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1476
    /// \e
1477
    Value operator[](const Key &k) const { return _m1[k]||_m2[k]; }
1478
  };
1479

	
1480
  /// Returns an \ref OrMap class
1481

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

	
1314 1494

	
1315 1495
  /// Logical 'not' of a map
1316 1496

	
1317
  /// This \ref concepts::ReadMap "read only map" returns the logical
1497
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1318 1498
  /// negation of the values of the given map.
1319 1499
  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
1320 1500
  ///
1321 1501
  /// The simplest way of using this map is through the notMap()
1322 1502
  /// function.
1323 1503
  ///
... ...
@@ -1388,10 +1568,106 @@
1388 1568
  /// \relates NotWriteMap
1389 1569
  template <typename M>
1390 1570
  inline NotWriteMap<M> notWriteMap(M &m) {
1391 1571
    return NotWriteMap<M>(m);
1392 1572
  }
1393 1573

	
1574

	
1575
  /// Combination of two maps using the \c == operator
1576

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

	
1602
    /// Constructor
1603
    EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1604
    /// \e
1605
    Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
1606
  };
1607

	
1608
  /// Returns an \ref EqualMap class
1609

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

	
1622

	
1623
  /// Combination of two maps using the \c < operator
1624

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

	
1650
    /// Constructor
1651
    LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1652
    /// \e
1653
    Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
1654
  };
1655

	
1656
  /// Returns an \ref LessMap class
1657

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

	
1394 1670
  /// @}
1395 1671
}
1396 1672

	
1397 1673
#endif // LEMON_MAPS_H
Ignore white space 12 line context
... ...
@@ -75,13 +75,13 @@
75 75
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
76 76
    ConstMap<A,B> map1;
77 77
    ConstMap<A,B> map2(B());
78 78
    ConstMap<A,B> map3 = map1;
79 79
    map1 = constMap<A>(B());
80 80
    map1.setAll(B());
81
    
81

	
82 82
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
83 83
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
84 84

	
85 85
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
86 86
    ConstMap<A,Const<int,10> > map4;
87 87
    ConstMap<A,Const<int,10> > map5 = map4;
... ...
@@ -92,13 +92,13 @@
92 92
  // IdentityMap
93 93
  {
94 94
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
95 95
    IdentityMap<A> map1;
96 96
    IdentityMap<A> map2 = map1;
97 97
    map1 = identityMap<A>();
98
    
98

	
99 99
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
100 100
    check(identityMap<double>()[1.0] == 1.0 && identityMap<double>()[3.14] == 3.14,
101 101
          "Something is wrong with IdentityMap");
102 102
  }
103 103

	
104 104
  // RangeMap
... ...
@@ -148,13 +148,13 @@
148 148
  // ComposeMap
149 149
  {
150 150
    typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
151 151
    checkConcept<ReadMap<B,double>, CompMap>();
152 152
    CompMap map1(DoubleMap(),ReadMap<B,A>());
153 153
    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
154
    
154

	
155 155
    SparseMap<double, bool> m1(false); m1[3.14] = true;
156 156
    RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
157 157
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap")
158 158
  }
159 159

	
160 160
  // CombineMap
... ...
@@ -194,44 +194,44 @@
194 194
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
195 195
  }
196 196

	
197 197
  // ForkMap
198 198
  {
199 199
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
200
    
200

	
201 201
    typedef RangeMap<double> RM;
202 202
    typedef SparseMap<int, double> SM;
203 203
    RM m1(10, -1);
204 204
    SM m2(-1);
205 205
    checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
206 206
    checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
207 207
    ForkMap<RM, SM> map1(m1,m2);
208 208
    ForkMap<SM, RM> map2 = forkMap(m2,m1);
209 209
    map2.set(5, 10);
210 210
    check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
211 211
          "Something is wrong with ForkMap");
212 212
  }
213
  
213

	
214 214
  // Arithmetic maps:
215 215
  // - AddMap, SubMap, MulMap, DivMap
216 216
  // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
217 217
  // - NegMap, NegWriteMap, AbsMap
218 218
  {
219 219
    checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
220 220
    checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
221 221
    checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
222 222
    checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
223
    
223

	
224 224
    ConstMap<int, double> c1(1.0), c2(3.14);
225 225
    IdentityMap<int> im;
226 226
    ConvertMap<IdentityMap<int>, double> id(im);
227 227
    check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap");
228 228
    check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,  "Something is wrong with SubMap");
229 229
    check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28, "Something is wrong with MulMap");
230 230
    check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57, "Something is wrong with DivMap");
231
    
231

	
232 232
    checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
233 233
    checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
234 234
    checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
235 235
    checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
236 236
    checkConcept<DoubleMap, NegMap<DoubleMap> >();
237 237
    checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
... ...
@@ -249,20 +249,44 @@
249 249
          "Something is wrong with NegMap");
250 250
    check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
251 251
          "Something is wrong with NegWriteMap");
252 252
    check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
253 253
          "Something is wrong with AbsMap");
254 254
  }
255
  
256
  // Logical maps
255

	
256
  // Logical maps:
257
  // - TrueMap, FalseMap
258
  // - AndMap, OrMap
259
  // - NotMap, NotWriteMap
260
  // - EqualMap, LessMap
257 261
  {
262
    checkConcept<BoolMap, TrueMap<A> >();
263
    checkConcept<BoolMap, FalseMap<A> >();
264
    checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
265
    checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
258 266
    checkConcept<BoolMap, NotMap<BoolMap> >();
259 267
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
260
    
268
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
269
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
270

	
271
    TrueMap<int> tm;
272
    FalseMap<int> fm;
261 273
    RangeMap<bool> rm(2);
262 274
    rm[0] = true; rm[1] = false;
263
    check(!(notMap(rm)[0]) && notMap(rm)[1], "Something is wrong with NotMap");
264
    check(!(notWriteMap(rm)[0]) && notWriteMap(rm)[1], "Something is wrong with NotWriteMap");
275
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
276
          "Something is wrong with AndMap");
277
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && orMap(fm,rm)[0] && !orMap(fm,rm)[1],
278
          "Something is wrong with OrMap");
279
    check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap");
280
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap");
281

	
282
    ConstMap<int, double> cm(2.0);
283
    IdentityMap<int> im;
284
    ConvertMap<IdentityMap<int>, double> id(im);
285
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
286
          "Something is wrong with LessMap");
287
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
288
          "Something is wrong with EqualMap");
265 289
  }
266 290

	
267 291
  return 0;
268 292
}
0 comments (0 inline)