[Lemon-commits] Peter Kovacs: Small improvements in maps.h
Lemon HG
hg at lemon.cs.elte.hu
Sat Apr 12 21:41:52 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/8899d1891a3c
changeset: 123:8899d1891a3c
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Tue Apr 08 22:51:26 2008 +0200
description:
Small improvements in maps.h
- Add a new version of constMap() function.
- Fix in FunctorToMap class.
diffstat:
2 files changed, 18 insertions(+), 6 deletions(-)
lemon/maps.h | 9 +++++++--
test/maps_test.cc | 15 +++++++++++----
diffs (68 lines):
diff -r b6bede534255 -r 8899d1891a3c lemon/maps.h
--- a/lemon/maps.h Thu Apr 03 13:00:18 2008 +0100
+++ b/lemon/maps.h Tue Apr 08 22:51:26 2008 +0200
@@ -116,7 +116,7 @@
/// Constructor with specified initial value
/// Constructor with specified initial value.
- /// \param v is the initial value of the map.
+ /// \param v The initial value of the map.
ConstMap(const Value &v) : _value(v) {}
/// Gives back the specified value.
@@ -141,6 +141,11 @@
template<typename K, typename V>
inline ConstMap<K, V> constMap(const V &v) {
return ConstMap<K, V>(v);
+ }
+
+ template<typename K, typename V>
+ inline ConstMap<K, V> constMap() {
+ return ConstMap<K, V>();
}
@@ -613,7 +618,7 @@
typename K = typename F::argument_type,
typename V = typename F::result_type>
class FunctorToMap : public MapBase<K, V> {
- const F &_f;
+ F _f;
public:
typedef MapBase<K, V> Parent;
typedef typename Parent::Key Key;
diff -r b6bede534255 -r 8899d1891a3c test/maps_test.cc
--- a/test/maps_test.cc Thu Apr 03 13:00:18 2008 +0100
+++ b/test/maps_test.cc Tue Apr 08 22:51:26 2008 +0200
@@ -83,20 +83,27 @@
// ConstMap
{
checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
+ checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
ConstMap<A,B> map1;
ConstMap<A,B> map2(B());
ConstMap<A,B> map3 = map1;
map1 = constMap<A>(B());
+ map1 = constMap<A,B>();
map1.setAll(B());
+ ConstMap<A,C> map4(C(1));
+ ConstMap<A,C> map5 = map4;
+ map4 = constMap<A>(C(2));
+ map4.setAll(C(3));
checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
- ConstMap<A,Const<int,10> > map4;
- ConstMap<A,Const<int,10> > map5 = map4;
- map4 = map5;
- check(map4[A()] == 10 && map5[A()] == 10, "Something is wrong with ConstMap");
+ ConstMap<A,Const<int,10> > map6;
+ ConstMap<A,Const<int,10> > map7 = map6;
+ map6 = constMap<A,int,10>();
+ map7 = constMap<A,Const<int,10> >();
+ check(map6[A()] == 10 && map7[A()] == 10, "Something is wrong with ConstMap");
}
// IdentityMap
More information about the Lemon-commits
mailing list