[Lemon-commits] Peter Kovacs: Fixes in the map concepts
Lemon HG
hg at lemon.cs.elte.hu
Tue Mar 18 15:25:57 CET 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/a4688e4138ec
changeset: 94:a4688e4138ec
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Tue Mar 18 13:57:15 2008 +0100
description:
Fixes in the map concepts
- Now Value type needn't be default constructible.
- Extend the test file to check this.
diffstat:
2 files changed, 22 insertions(+), 9 deletions(-)
lemon/concepts/maps.h | 21 ++++++++++++---------
test/maps_test.cc | 10 ++++++++++
diffs (80 lines):
diff -r f857981306ea -r a4688e4138ec lemon/concepts/maps.h
--- a/lemon/concepts/maps.h Mon Mar 17 19:21:27 2008 +0000
+++ b/lemon/concepts/maps.h Tue Mar 18 13:57:15 2008 +0100
@@ -47,10 +47,9 @@ namespace lemon {
typedef T Value;
/// Returns the value associated with the given key.
-
- /// Returns the value associated with the given key.
- /// \bug Value shouldn't need to be default constructible.
- Value operator[](const Key &) const { return Value(); }
+ Value operator[](const Key &) const {
+ return *static_cast<Value *>(0);
+ }
template<typename _ReadMap>
struct Constraints {
@@ -126,7 +125,9 @@ namespace lemon {
typedef T Value;
/// Returns the value associated with the given key.
- Value operator[](const Key &) const { return Value(); }
+ Value operator[](const Key &) const {
+ return *static_cast<Value *>(0);
+ }
/// Sets the value associated with the given key.
void set(const Key &, const Value &) {}
@@ -160,15 +161,17 @@ namespace lemon {
/// The const reference type of the map.
typedef CR ConstReference;
- protected:
- Value tmp;
public:
/// Returns a reference to the value associated with the given key.
- Reference operator[](const Key &) { return tmp; }
+ Reference operator[](const Key &) {
+ return *static_cast<Value *>(0);
+ }
/// Returns a const reference to the value associated with the given key.
- ConstReference operator[](const Key &) const { return tmp; }
+ ConstReference operator[](const Key &) const {
+ return *static_cast<Value *>(0);
+ }
/// Sets the value associated with the given key.
void set(const Key &k,const Value &t) { operator[](k)=t; }
diff -r f857981306ea -r a4688e4138ec test/maps_test.cc
--- a/test/maps_test.cc Mon Mar 17 19:21:27 2008 +0000
+++ b/test/maps_test.cc Tue Mar 18 13:57:15 2008 +0100
@@ -32,6 +32,12 @@ inline bool operator<(A, A) { return tru
inline bool operator<(A, A) { return true; }
struct B {};
+class C {
+ int x;
+public:
+ C(int _x) : x(_x) {}
+};
+
class F {
public:
typedef A argument_type;
@@ -58,9 +64,13 @@ int main()
{
// Map concepts
checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
+ checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
+ checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
+ checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
+ checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
// NullMap
{
More information about the Lemon-commits
mailing list