[Lemon-commits] [lemon_svn] deba: r2193 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:50:49 CET 2006
Author: deba
Date: Thu Sep 8 16:34:50 2005
New Revision: 2193
Modified:
hugo/trunk/lemon/maps.h
hugo/trunk/test/map_test.h
hugo/trunk/test/maps_test.cc
Log:
Redesign of the map adaptors.
/smart reference handling only used by functions/
Better handling of the function objects and functions.
\\\todo May we use operators instead of the addMap, subMap...?
Modified: hugo/trunk/lemon/maps.h
==============================================================================
--- hugo/trunk/lemon/maps.h (original)
+++ hugo/trunk/lemon/maps.h Thu Sep 8 16:34:50 2005
@@ -39,10 +39,11 @@
/// Base class of maps.
/// It provides the necessary <tt>typedef</tt>s required by the map concept.
- template<typename K, typename T>
- class MapBase
- {
+ template<typename K, typename T, typename _NeedCopy = False>
+ class MapBase {
public:
+ /// \e
+ typedef _NeedCopy NeedCopy;
///\e
typedef K Key;
///\e
@@ -54,13 +55,13 @@
/// If you have to provide a map only for its type definitions,
/// or if you have to provide a writable map, but
/// data written to it will sent to <tt>/dev/null</tt>...
- template<typename K, typename T>
- class NullMap : public MapBase<K,T>
- {
+ template<typename K, typename T, typename NC = False>
+ class NullMap : public MapBase<K, T, NC> {
public:
+ typedef MapBase<K, T, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
- typedef True NeedCopy;
-
/// Gives back a default constructed element.
T operator[](const K&) const { return T(); }
/// Absorbs the value.
@@ -68,8 +69,8 @@
};
template <typename K, typename V>
- NullMap<K, V> nullMap() {
- return NullMap<K, V>();
+ NullMap<K, V, True> nullMap() {
+ return NullMap<K, V, True>();
}
@@ -78,13 +79,15 @@
/// This is a readable map which assigns a specified value to each key.
/// In other aspects it is equivalent to the \ref NullMap.
/// \todo set could be used to set the value.
- template<typename K, typename T>
- class ConstMap : public MapBase<K,T>
- {
+ template<typename K, typename T, typename NC = False>
+ class ConstMap : public MapBase<K, T, NC> {
+ private:
T v;
public:
- typedef True NeedCopy;
+ typedef MapBase<K, T, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
/// Default constructor
@@ -102,37 +105,49 @@
template<typename T1>
struct rebind {
- typedef ConstMap<K,T1> other;
+ typedef ConstMap<K, T1> other;
};
template<typename T1>
- ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
+ ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
};
///Returns a \ref ConstMap class
///This function just returns a \ref ConstMap class.
///\relates ConstMap
- template<class K,class V>
- inline ConstMap<K,V> constMap(const V &v)
- {
- return ConstMap<K,V>(v);
+ template<typename K, typename V>
+ inline ConstMap<K, V, True> constMap(const V &v) {
+ return ConstMap<K, V, True>(v);
}
//\todo to document later
template<typename T, T v>
struct Const { };
+
//\todo to document later
- template<typename K, typename V, V v>
- class ConstMap<K, Const<V, v> > : public MapBase<K, V>
- {
+ template<typename K, typename V, V v, typename NC>
+ class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> {
public:
+ typedef MapBase<K, V, False> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
+
ConstMap() { }
V operator[](const K&) const { return v; }
void set(const K&, const V&) { }
};
+ ///Returns a \ref ConstMap class
+
+ ///This function just returns a \ref ConstMap class.
+ ///\relates ConstMap
+ template<typename K, typename V, V v>
+ inline ConstMap<K, Const<V, v>, True> constMap() {
+ return ConstMap<K, Const<V, v>, True>();
+ }
+
/// \c std::map wrapper
/// This is essentially a wrapper for \c std::map. With addition that
@@ -140,8 +155,8 @@
///
/// \todo Provide allocator parameter...
template <typename K, typename T, typename Compare = std::less<K> >
- class StdMap : public std::map<K,T,Compare> {
- typedef std::map<K,T,Compare> parent;
+ class StdMap : public std::map<K, T, Compare> {
+ typedef std::map<K, T, Compare> parent;
T v;
typedef typename parent::value_type PairType;
@@ -171,13 +186,14 @@
StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
template<typename T1, typename Comp1>
- StdMap(const StdMap<Key,T1,Comp1> &m, const T &_v) {
+ StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) {
//FIXME;
}
Reference operator[](const Key &k) {
return insert(PairType(k,v)).first -> second;
}
+
ConstReference operator[](const Key &k) const {
typename parent::iterator i = lower_bound(k);
if (i == parent::end() || parent::key_comp()(k, (*i).first))
@@ -197,7 +213,7 @@
template<typename T1>
struct rebind {
- typedef StdMap<Key,T1,Compare> other;
+ typedef StdMap<Key, T1,Compare> other;
};
};
@@ -210,33 +226,40 @@
///
/// This mapping gives back the given key as value without any
/// modification.
- template <typename T>
- class IdentityMap {
+ template <typename T, typename NC = False>
+ class IdentityMap : public MapBase<T, T, NC> {
public:
- typedef T Key;
- typedef T Value;
+ typedef MapBase<T, T, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
- const Value& operator[](const Key& t) const {
+ const T& operator[](const T& t) const {
return t;
}
};
+ ///Returns an \ref IdentityMap class
+
+ ///This function just returns an \ref IdentityMap class.
+ ///\relates IdentityMap
+ template<typename T>
+ inline IdentityMap<T, True> identityMap() {
+ return IdentityMap<T, True>();
+ }
+
+
///Convert the \c Value of a map to another type.
///This \ref concept::ReadMap "read only map"
///converts the \c Value of a maps to type \c T.
///Its \c Key is inherited from \c M.
- template<class M, class T>
- class ConvertMap {
+ template <typename M, typename T, typename NC = False>
+ class ConvertMap : public MapBase<typename M::Key, T, NC> {
typename SmartConstReference<M>::Type m;
public:
-
- typedef True NeedCopy;
-
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef T Value;
+ typedef MapBase<typename M::Key, T, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
@@ -249,7 +272,7 @@
/// The subscript operator.
/// \param k The key
/// \return The target of the edge
- Value operator[](Key k) const {return m[k];}
+ Value operator[](const Key& k) const {return m[k];}
};
///Returns an \ref ConvertMap class
@@ -257,10 +280,9 @@
///This function just returns an \ref ConvertMap class.
///\relates ConvertMap
///\todo The order of the template parameters are changed.
- template<class T, class M>
- inline ConvertMap<M,T> convertMap(const M &m)
- {
- return ConvertMap<M,T>(m);
+ template<typename T, typename M>
+ inline ConvertMap<M, T, True> convertMap(const M &m) {
+ return ConvertMap<M, T, True>(m);
}
///Sum of two maps
@@ -269,20 +291,15 @@
///given maps. Its \c Key and \c Value will be inherited from \c M1.
///The \c Key and \c Value of M2 must be convertible to those of \c M1.
- template<class M1,class M2>
- class AddMap
- {
+ template<typename M1, typename M2, typename NC = False>
+ class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
public:
-
- typedef True NeedCopy;
-
- ///\e
- typedef typename M1::Key Key;
- ///\e
- typedef typename M1::Value Value;
+ typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
@@ -296,10 +313,9 @@
///
///\relates AddMap
///\todo Wrong scope in Doxygen when \c \\relates is used
- template<class M1,class M2>
- inline AddMap<M1,M2> addMap(const M1 &m1,const M2 &m2)
- {
- return AddMap<M1,M2>(m1,m2);
+ template<typename M1, typename M2>
+ inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) {
+ return AddMap<M1, M2, True>(m1,m2);
}
///Shift a map with a constant.
@@ -317,25 +333,21 @@
/// ConstMap<X::Key, X::Value> c_tmp(v);
/// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
///\endcode
- template<class M>
- class ShiftMap
- {
+ template<typename M, typename NC = False>
+ class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> {
typename SmartConstReference<M>::Type m;
typename M::Value v;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef typename M::Value Value;
+ typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
///Constructor
///\param _m is the undelying map
///\param _v is the shift value
- ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
+ ShiftMap(const M &_m, const Value &_v ) : m(_m), v(_v) {};
Value operator[](Key k) const {return m[k]+v;}
};
@@ -344,10 +356,9 @@
///This function just returns an \ref ShiftMap class.
///\relates ShiftMap
///\todo A better name is required.
- template<class M>
- inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v)
- {
- return ShiftMap<M>(m,v);
+ template<typename M>
+ inline ShiftMap<M, True> shiftMap(const M &m,const typename M::Value &v) {
+ return ShiftMap<M, True>(m,v);
}
///Difference of two maps
@@ -357,18 +368,14 @@
///given maps. Its \c Key and \c Value will be inherited from \c M1.
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
- template<class M1,class M2>
- class SubMap
- {
+ template<typename M1, typename M2, typename NC = False>
+ class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M1::Key Key;
- ///\e
- typedef typename M1::Value Value;
+ typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
@@ -380,10 +387,9 @@
///This function just returns a \ref SubMap class.
///
///\relates SubMap
- template<class M1,class M2>
- inline SubMap<M1,M2> subMap(const M1 &m1,const M2 &m2)
- {
- return SubMap<M1,M2>(m1,m2);
+ template<typename M1, typename M2>
+ inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) {
+ return SubMap<M1, M2, True>(m1, m2);
}
///Product of two maps
@@ -394,18 +400,14 @@
///maps. Its \c Key and \c Value will be inherited from \c M1.
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
- template<class M1,class M2>
- class MulMap
- {
+ template<typename M1, typename M2, typename NC = False>
+ class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M1::Key Key;
- ///\e
- typedef typename M1::Value Value;
+ typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
@@ -416,10 +418,9 @@
///This function just returns a \ref MulMap class.
///\relates MulMap
- template<class M1,class M2>
- inline MulMap<M1,M2> mulMap(const M1 &m1,const M2 &m2)
- {
- return MulMap<M1,M2>(m1,m2);
+ template<typename M1, typename M2>
+ inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) {
+ return MulMap<M1, M2, True>(m1,m2);
}
///Scales a maps with a constant.
@@ -437,18 +438,14 @@
/// ConstMap<X::Key, X::Value> c_tmp(v);
/// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
///\endcode
- template<class M>
- class ScaleMap
- {
+ template<typename M, typename NC = False>
+ class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> {
typename SmartConstReference<M>::Type m;
typename M::Value v;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef typename M::Value Value;
+ typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
@@ -464,10 +461,9 @@
///This function just returns an \ref ScaleMap class.
///\relates ScaleMap
///\todo A better name is required.
- template<class M>
- inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v)
- {
- return ScaleMap<M>(m,v);
+ template<typename M>
+ inline ScaleMap<M, True> scaleMap(const M &m,const typename M::Value &v) {
+ return ScaleMap<M, True>(m,v);
}
///Quotient of two maps
@@ -477,18 +473,14 @@
///given maps. Its \c Key and \c Value will be inherited from \c M1.
///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
- template<class M1,class M2>
- class DivMap
- {
+ template<typename M1, typename M2, typename NC = False>
+ class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M1::Key Key;
- ///\e
- typedef typename M1::Value Value;
+ typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
@@ -499,10 +491,9 @@
///This function just returns a \ref DivMap class.
///\relates DivMap
- template<class M1,class M2>
- inline DivMap<M1,M2> divMap(const M1 &m1,const M2 &m2)
- {
- return DivMap<M1,M2>(m1,m2);
+ template<typename M1, typename M2>
+ inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) {
+ return DivMap<M1, M2, True>(m1,m2);
}
///Composition of two maps
@@ -513,7 +504,7 @@
///of \c M2,
///then for
///\code
- /// ComposeMap<M1,M2> cm(m1,m2);
+ /// ComposeMap<M1, M2> cm(m1,m2);
///\endcode
/// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
///
@@ -522,18 +513,14 @@
///The \c M2::Value must be convertible to \c M1::Key.
///\todo Check the requirements.
- template<class M1,class M2>
- class ComposeMap
- {
+ template <typename M1, typename M2, typename NC = False>
+ class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M2::Key Key;
- ///\e
- typedef typename M1::Value Value;
+ typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
@@ -544,10 +531,9 @@
///This function just returns a \ref ComposeMap class.
///
///\relates ComposeMap
- template<class M1,class M2>
- inline ComposeMap<M1,M2> composeMap(const M1 &m1,const M2 &m2)
- {
- return ComposeMap<M1,M2>(m1,m2);
+ template <typename M1, typename M2>
+ inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) {
+ return ComposeMap<M1, M2, True>(m1,m2);
}
///Combines of two maps using an STL (binary) functor.
@@ -563,7 +549,7 @@
///and \c f is of \c F,
///then for
///\code
- /// CombineMap<M1,M2,F,V> cm(m1,m2,f);
+ /// CombineMap<M1, M2,F,V> cm(m1,m2,f);
///\endcode
/// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
///
@@ -573,19 +559,17 @@
///to \c V.
///\todo Check the requirements.
- template<class M1,class M2,class F,class V = typename F::result_type>
- class CombineMap
- {
+ template<typename M1, typename M2, typename F,
+ typename V = typename F::result_type,
+ typename NC = False>
+ class CombineMap : public MapBase<typename M1::Key, V, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
F f;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M1::Key Key;
- ///\e
- typedef V Value;
+ typedef MapBase<typename M1::Key, V, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
@@ -609,10 +593,22 @@
///\endcode
///
///\relates CombineMap
- template<class M1,class M2,class F>
- inline CombineMap<M1,M2,F> combineMap(const M1 &m1,const M2 &m2,const F &f)
- {
- return CombineMap<M1,M2,F>(m1,m2,f);
+ template<typename M1, typename M2, typename F, typename V>
+ inline CombineMap<M1, M2, F, V, True>
+ combineMap(const M1& m1,const M2& m2, const F& f) {
+ return CombineMap<M1, M2, F, V, True>(m1,m2,f);
+ }
+
+ template<typename M1, typename M2, typename F>
+ inline CombineMap<M1, M2, F, typename F::result_type, True>
+ combineMap(const M1& m1, const M2& m2, const F& f) {
+ return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
+ }
+
+ template<typename M1, typename M2, typename K1, typename K2, typename V>
+ inline CombineMap<M1, M2, V (*)(K1, K2), V, True>
+ combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
+ return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
}
///Negative value of a map
@@ -623,17 +619,13 @@
///given map. Its \c Key and \c Value will be inherited from \c M.
///The unary \c - operator must be defined for \c Value, of course.
- template<class M>
- class NegMap
- {
+ template<typename M, typename NC = False>
+ class NegMap : public MapBase<typename M::Key, typename M::Value, NC> {
typename SmartConstReference<M>::Type m;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef typename M::Value Value;
+ typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
NegMap(const M &_m) : m(_m) {};
@@ -644,10 +636,9 @@
///This function just returns a \ref NegMap class.
///\relates NegMap
- template<class M>
- inline NegMap<M> negMap(const M &m)
- {
- return NegMap<M>(m);
+ template <typename M>
+ inline NegMap<M, True> negMap(const M &m) {
+ return NegMap<M, True>(m);
}
@@ -674,31 +665,30 @@
///\endcode
- template<class M>
- class AbsMap
- {
+ template<typename M, typename NC = False>
+ class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> {
typename SmartConstReference<M>::Type m;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef typename M::Value Value;
+ typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
AbsMap(const M &_m) : m(_m) {};
- Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
+ Value operator[](Key k) const {
+ Value tmp = m[k];
+ return tmp >= 0 ? tmp : -tmp;
+ }
+
};
///Returns a \ref AbsMap class
///This function just returns a \ref AbsMap class.
///\relates AbsMap
- template<class M>
- inline AbsMap<M> absMap(const M &m)
- {
- return AbsMap<M>(m);
+ template<typename M>
+ inline AbsMap<M, True> absMap(const M &m) {
+ return AbsMap<M, True>(m);
}
///Converts an STL style functor to a map
@@ -714,17 +704,16 @@
///Parameter \c F is the type of the used functor.
- template<class K,class V,class F>
- class FunctorMap
- {
+ template<typename F,
+ typename K = typename F::argument_type,
+ typename V = typename F::result_type,
+ typename NC = False>
+ class FunctorMap : public MapBase<K, V, NC> {
const F &f;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef K Key;
- ///\e
- typedef V Value;
+ typedef MapBase<K, V, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
FunctorMap(const F &_f) : f(_f) {};
@@ -737,12 +726,24 @@
///
///The third template parameter isn't necessary to be given.
///\relates FunctorMap
- template<class K,class V, class F>
- inline FunctorMap<K,V,F> functorMap(const F &f)
- {
- return FunctorMap<K,V,F>(f);
+ template<typename K, typename V, typename F> inline
+ FunctorMap<F, K, V, True> functorMap(const F &f) {
+ return FunctorMap<F, K, V, True>(f);
}
+ template <typename F> inline
+ FunctorMap<F, typename F::argument_type, typename F::result_type, True>
+ functorMap(const F &f) {
+ return functorMap<typename F::argument_type,
+ typename F::result_type, F>(f);
+ }
+
+ template <typename K, typename V> inline
+ FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
+ return functorMap<K, V, V (*)(K)>(f);
+ }
+
+
///Converts a map to an STL style (unary) functor
///This class Converts a map to an STL style (unary) functor.
@@ -752,21 +753,18 @@
///a ususal \ref concept::ReadMap "readable map",
///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
- template<class M>
- class MapFunctor
- {
+ template <typename M, typename NC = False>
+ class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> {
typename SmartConstReference<M>::Type m;
public:
+ typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
- typedef True NeedCopy;
///\e
typedef typename M::Key argument_type;
///\e
typedef typename M::Value result_type;
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef typename M::Value Value;
///Constructor
MapFunctor(const M &_m) : m(_m) {};
@@ -780,10 +778,9 @@
///This function just returns a \ref MapFunctor class.
///\relates MapFunctor
- template<class M>
- inline MapFunctor<M> mapFunctor(const M &m)
- {
- return MapFunctor<M>(m);
+ template<typename M>
+ inline MapFunctor<M, True> mapFunctor(const M &m) {
+ return MapFunctor<M, True>(m);
}
@@ -798,23 +795,19 @@
///The \c Key and \c Value will be inherited from \c M1.
///The \c Key and \c Value of M2 must be convertible from those of \c M1.
- template<class M1,class M2>
- class ForkMap
- {
+ template<typename M1, typename M2, typename NC = False>
+ class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
typename SmartConstReference<M1>::Type m1;
typename SmartConstReference<M2>::Type m2;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M1::Key Key;
- ///\e
- typedef typename M1::Value Value;
+ typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
Value operator[](Key k) const {return m1[k];}
- void set(Key k,const Value &v) {m1.set(k,v); m2.set(k,v);}
+ // void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
};
///Returns an \ref ForkMap class
@@ -824,10 +817,9 @@
///
///\relates ForkMap
///\todo Wrong scope in Doxygen when \c \\relates is used
- template<class M1,class M2>
- inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2)
- {
- return ForkMap<M1,M2>(m1,m2);
+ template <typename M1, typename M2>
+ inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) {
+ return ForkMap<M1, M2, True>(m1,m2);
}
@@ -842,17 +834,13 @@
///given map. Its \c Key and will be inherited from \c M,
///its Value is <tt>bool</tt>.
- template<class M>
- class NotMap
- {
+ template <typename M, typename NC = False>
+ class NotMap : public MapBase<typename M::Key, bool, NC> {
typename SmartConstReference<M>::Type m;
public:
-
- typedef True NeedCopy;
- ///\e
- typedef typename M::Key Key;
- ///\e
- typedef bool Value;
+ typedef MapBase<typename M::Key, bool, NC> Parent;
+ typedef typename Parent::Key Key;
+ typedef typename Parent::Value Value;
///Constructor
NotMap(const M &_m) : m(_m) {};
@@ -863,22 +851,15 @@
///This function just returns a \ref NotMap class.
///\relates NotMap
- template<class M>
- inline NotMap<M> notMap(const M &m)
- {
- return NotMap<M>(m);
+ template <typename M>
+ inline NotMap<M, True> notMap(const M &m) {
+ return NotMap<M, True>(m);
}
-
-
-
-
-
-
/// @}
}
Modified: hugo/trunk/test/map_test.h
==============================================================================
--- hugo/trunk/test/map_test.h (original)
+++ hugo/trunk/test/map_test.h Thu Sep 8 16:34:50 2005
@@ -49,6 +49,10 @@
nodes.push_back(graph.addNode());
map[nodes.back()] = 23;
}
+ map = constMap<Node>(12);
+ for (int i = 0; i < (int)nodes.size(); ++i) {
+ check(map[nodes[i]] == 12, "Wrong map constructor.");
+ }
graph.clear();
nodes.clear();
}
@@ -86,6 +90,10 @@
map[edges.back()] = 23;
}
}
+ map = constMap<Edge>(12);
+ for (int i = 0; i < (int)edges.size(); ++i) {
+ check(map[edges[i]] == 12, "Wrong map constructor.");
+ }
graph.clear();
edges.clear();
}
Modified: hugo/trunk/test/maps_test.cc
==============================================================================
--- hugo/trunk/test/maps_test.cc (original)
+++ hugo/trunk/test/maps_test.cc Thu Sep 8 16:34:50 2005
@@ -9,14 +9,19 @@
struct A {};
struct B {};
-class F
-{
+
+class F {
public:
+ typedef A argument_type;
+ typedef B result_type;
+
B operator()(const A &) const {return B();}
};
int func(A) {return 3;}
+int binc(int, B) {return 4;}
+
typedef ReadMap<A,double> DoubleMap;
int main()
@@ -38,7 +43,7 @@
checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
- checkConcept<ReadMap<A,B>, FunctorMap<A,B,F> >();
+ checkConcept<ReadMap<A,B>, FunctorMap<F, A, B> >();
int a;
@@ -46,11 +51,15 @@
check(a==2,"Something is wrong with mapFunctor");
B b;
- b=functorMap<A,B>(F())[A()];
+ b=functorMap(F())[A()];
- a=functorMap<A,int>(&func)[A()];
+ a=functorMap(&func)[A()];
check(a==3,"Something is wrong with functorMap");
+ a=combineMap(constMap<B, int, 1>(), identityMap<B>(), &binc)[B()];
+ check(a==4,"Something is wrong with combineMap");
+
+
std::cout << __FILE__ ": All tests passed.\n";
return 0;
More information about the Lemon-commits
mailing list