iterable_maps.h header hes been added. Up to now it contains an iterable bool
map and specialized versions for Node and Edge maps.
2 * lemon/maps.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
20 #include <lemon/graph_utils.h>
21 #include <lemon/utility.h>
26 ///\brief Miscellaneous property maps
28 ///\todo This file has the same name as the concept file in concept/,
29 /// and this is not easily detectable in docs...
38 /// Base class of maps.
40 /// Base class of maps.
41 /// It provides the necessary <tt>typedef</tt>s required by the map concept.
42 template<typename K, typename T, typename _NeedCopy = False>
46 typedef _NeedCopy NeedCopy;
53 /// Null map. (a.k.a. DoNothingMap)
55 /// If you have to provide a map only for its type definitions,
56 /// or if you have to provide a writable map, but
57 /// data written to it will sent to <tt>/dev/null</tt>...
58 template<typename K, typename T, typename NC = False>
59 class NullMap : public MapBase<K, T, NC> {
61 typedef MapBase<K, T, NC> Parent;
62 typedef typename Parent::Key Key;
63 typedef typename Parent::Value Value;
65 /// Gives back a default constructed element.
66 T operator[](const K&) const { return T(); }
67 /// Absorbs the value.
68 void set(const K&, const T&) {}
71 template <typename K, typename V>
72 NullMap<K, V, True> nullMap() {
73 return NullMap<K, V, True>();
79 /// This is a readable map which assigns a specified value to each key.
80 /// In other aspects it is equivalent to the \ref NullMap.
81 /// \todo set could be used to set the value.
82 template<typename K, typename T, typename NC = False>
83 class ConstMap : public MapBase<K, T, NC> {
88 typedef MapBase<K, T, NC> Parent;
89 typedef typename Parent::Key Key;
90 typedef typename Parent::Value Value;
92 /// Default constructor
94 /// The value of the map will be uninitialized.
95 /// (More exactly it will be default constructed.)
99 /// \param _v The initial value of the map.
101 ConstMap(const T &_v) : v(_v) {}
103 T operator[](const K&) const { return v; }
104 void set(const K&, const T&) {}
106 template<typename T1>
108 typedef ConstMap<K, T1> other;
111 template<typename T1>
112 ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {}
115 ///Returns a \ref ConstMap class
117 ///This function just returns a \ref ConstMap class.
119 template<typename K, typename V>
120 inline ConstMap<K, V, True> constMap(const V &v) {
121 return ConstMap<K, V, True>(v);
125 //\todo to document later
126 template<typename T, T v>
129 //\todo to document later
130 template<typename K, typename V, V v, typename NC>
131 class ConstMap<K, Const<V, v>, NC > : public MapBase<K, V, NC> {
133 typedef MapBase<K, V, False> Parent;
134 typedef typename Parent::Key Key;
135 typedef typename Parent::Value Value;
138 V operator[](const K&) const { return v; }
139 void set(const K&, const V&) { }
142 ///Returns a \ref ConstMap class
144 ///This function just returns a \ref ConstMap class.
146 template<typename K, typename V, V v>
147 inline ConstMap<K, Const<V, v>, True> constMap() {
148 return ConstMap<K, Const<V, v>, True>();
151 /// \c std::map wrapper
153 /// This is essentially a wrapper for \c std::map. With addition that
154 /// you can specify a default value different from \c Value() .
156 /// \todo Provide allocator parameter...
157 template <typename K, typename T, typename Compare = std::less<K> >
158 class StdMap : public std::map<K, T, Compare> {
159 typedef std::map<K, T, Compare> parent;
161 typedef typename parent::value_type PairType;
169 typedef T& Reference;
171 typedef const T& ConstReference;
175 /// Constructor with specified default value
176 StdMap(const T& _v) : v(_v) {}
178 /// \brief Constructs the map from an appropriate std::map.
180 /// \warning Inefficient: copies the content of \c m !
181 StdMap(const parent &m) : parent(m) {}
182 /// \brief Constructs the map from an appropriate std::map, and explicitly
183 /// specifies a default value.
185 /// \warning Inefficient: copies the content of \c m !
186 StdMap(const parent &m, const T& _v) : parent(m), v(_v) {}
188 template<typename T1, typename Comp1>
189 StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) {
193 Reference operator[](const Key &k) {
194 return insert(PairType(k,v)).first -> second;
197 ConstReference operator[](const Key &k) const {
198 typename parent::iterator i = lower_bound(k);
199 if (i == parent::end() || parent::key_comp()(k, (*i).first))
203 void set(const Key &k, const T &t) {
204 parent::operator[](k) = t;
207 /// Changes the default value of the map.
208 /// \return Returns the previous default value.
210 /// \warning The value of some keys (which has already been queried, but
211 /// the value has been unchanged from the default) may change!
212 T setDefault(const T &_v) { T old=v; v=_v; return old; }
214 template<typename T1>
216 typedef StdMap<Key, T1,Compare> other;
222 /// \addtogroup map_adaptors
225 /// \brief Identity mapping.
227 /// This mapping gives back the given key as value without any
229 template <typename T, typename NC = False>
230 class IdentityMap : public MapBase<T, T, NC> {
232 typedef MapBase<T, T, NC> Parent;
233 typedef typename Parent::Key Key;
234 typedef typename Parent::Value Value;
236 const T& operator[](const T& t) const {
241 ///Returns an \ref IdentityMap class
243 ///This function just returns an \ref IdentityMap class.
244 ///\relates IdentityMap
246 inline IdentityMap<T, True> identityMap() {
247 return IdentityMap<T, True>();
251 ///Convert the \c Value of a map to another type.
253 ///This \ref concept::ReadMap "read only map"
254 ///converts the \c Value of a maps to type \c T.
255 ///Its \c Key is inherited from \c M.
256 template <typename M, typename T, typename NC = False>
257 class ConvertMap : public MapBase<typename M::Key, T, NC> {
258 typename SmartConstReference<M>::Type m;
260 typedef MapBase<typename M::Key, T, NC> Parent;
261 typedef typename Parent::Key Key;
262 typedef typename Parent::Value Value;
267 ///\param _m is the underlying map
268 ConvertMap(const M &_m) : m(_m) {};
270 /// \brief The subscript operator.
272 /// The subscript operator.
274 /// \return The target of the edge
275 Value operator[](const Key& k) const {return m[k];}
278 ///Returns an \ref ConvertMap class
280 ///This function just returns an \ref ConvertMap class.
281 ///\relates ConvertMap
282 ///\todo The order of the template parameters are changed.
283 template<typename T, typename M>
284 inline ConvertMap<M, T, True> convertMap(const M &m) {
285 return ConvertMap<M, T, True>(m);
290 ///This \ref concept::ReadMap "read only map" returns the sum of the two
291 ///given maps. Its \c Key and \c Value will be inherited from \c M1.
292 ///The \c Key and \c Value of M2 must be convertible to those of \c M1.
294 template<typename M1, typename M2, typename NC = False>
295 class AddMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
296 typename SmartConstReference<M1>::Type m1;
297 typename SmartConstReference<M2>::Type m2;
300 typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
301 typedef typename Parent::Key Key;
302 typedef typename Parent::Value Value;
305 AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
306 Value operator[](Key k) const {return m1[k]+m2[k];}
309 ///Returns an \ref AddMap class
311 ///This function just returns an \ref AddMap class.
312 ///\todo How to call these type of functions?
315 ///\todo Wrong scope in Doxygen when \c \\relates is used
316 template<typename M1, typename M2>
317 inline AddMap<M1, M2, True> addMap(const M1 &m1,const M2 &m2) {
318 return AddMap<M1, M2, True>(m1,m2);
321 ///Shift a map with a constant.
323 ///This \ref concept::ReadMap "read only map" returns the sum of the
324 ///given map and a constant value.
325 ///Its \c Key and \c Value is inherited from \c M.
329 /// ShiftMap<X> sh(x,v);
331 ///is equivalent with
333 /// ConstMap<X::Key, X::Value> c_tmp(v);
334 /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
336 template<typename M, typename NC = False>
337 class ShiftMap : public MapBase<typename M::Key, typename M::Value, NC> {
338 typename SmartConstReference<M>::Type m;
341 typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
342 typedef typename Parent::Key Key;
343 typedef typename Parent::Value Value;
348 ///\param _m is the undelying map
349 ///\param _v is the shift value
350 ShiftMap(const M &_m, const Value &_v ) : m(_m), v(_v) {};
351 Value operator[](Key k) const {return m[k]+v;}
354 ///Returns an \ref ShiftMap class
356 ///This function just returns an \ref ShiftMap class.
358 ///\todo A better name is required.
360 inline ShiftMap<M, True> shiftMap(const M &m,const typename M::Value &v) {
361 return ShiftMap<M, True>(m,v);
364 ///Difference of two maps
366 ///This \ref concept::ReadMap "read only map" returns the difference
367 ///of the values of the two
368 ///given maps. Its \c Key and \c Value will be inherited from \c M1.
369 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
371 template<typename M1, typename M2, typename NC = False>
372 class SubMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
373 typename SmartConstReference<M1>::Type m1;
374 typename SmartConstReference<M2>::Type m2;
376 typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
377 typedef typename Parent::Key Key;
378 typedef typename Parent::Value Value;
381 SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
382 Value operator[](Key k) const {return m1[k]-m2[k];}
385 ///Returns a \ref SubMap class
387 ///This function just returns a \ref SubMap class.
390 template<typename M1, typename M2>
391 inline SubMap<M1, M2, True> subMap(const M1 &m1, const M2 &m2) {
392 return SubMap<M1, M2, True>(m1, m2);
395 ///Product of two maps
397 ///This \ref concept::ReadMap "read only map" returns the product of the
400 ///maps. Its \c Key and \c Value will be inherited from \c M1.
401 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
403 template<typename M1, typename M2, typename NC = False>
404 class MulMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
405 typename SmartConstReference<M1>::Type m1;
406 typename SmartConstReference<M2>::Type m2;
408 typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
409 typedef typename Parent::Key Key;
410 typedef typename Parent::Value Value;
413 MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
414 Value operator[](Key k) const {return m1[k]*m2[k];}
417 ///Returns a \ref MulMap class
419 ///This function just returns a \ref MulMap class.
421 template<typename M1, typename M2>
422 inline MulMap<M1, M2, True> mulMap(const M1 &m1,const M2 &m2) {
423 return MulMap<M1, M2, True>(m1,m2);
426 ///Scales a maps with a constant.
428 ///This \ref concept::ReadMap "read only map" returns the value of the
429 ///given map multiplied with a constant value.
430 ///Its \c Key and \c Value is inherited from \c M.
434 /// ScaleMap<X> sc(x,v);
436 ///is equivalent with
438 /// ConstMap<X::Key, X::Value> c_tmp(v);
439 /// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
441 template<typename M, typename NC = False>
442 class ScaleMap : public MapBase<typename M::Key, typename M::Value, NC> {
443 typename SmartConstReference<M>::Type m;
446 typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
447 typedef typename Parent::Key Key;
448 typedef typename Parent::Value Value;
453 ///\param _m is the undelying map
454 ///\param _v is the scaling value
455 ScaleMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
456 Value operator[](Key k) const {return m[k]*v;}
459 ///Returns an \ref ScaleMap class
461 ///This function just returns an \ref ScaleMap class.
463 ///\todo A better name is required.
465 inline ScaleMap<M, True> scaleMap(const M &m,const typename M::Value &v) {
466 return ScaleMap<M, True>(m,v);
469 ///Quotient of two maps
471 ///This \ref concept::ReadMap "read only map" returns the quotient of the
473 ///given maps. Its \c Key and \c Value will be inherited from \c M1.
474 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1.
476 template<typename M1, typename M2, typename NC = False>
477 class DivMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
478 typename SmartConstReference<M1>::Type m1;
479 typename SmartConstReference<M2>::Type m2;
481 typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
482 typedef typename Parent::Key Key;
483 typedef typename Parent::Value Value;
486 DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
487 Value operator[](Key k) const {return m1[k]/m2[k];}
490 ///Returns a \ref DivMap class
492 ///This function just returns a \ref DivMap class.
494 template<typename M1, typename M2>
495 inline DivMap<M1, M2, True> divMap(const M1 &m1,const M2 &m2) {
496 return DivMap<M1, M2, True>(m1,m2);
499 ///Composition of two maps
501 ///This \ref concept::ReadMap "read only map" returns the composition of
503 ///given maps. That is to say, if \c m1 is of type \c M1 and \c m2 is
507 /// ComposeMap<M1, M2> cm(m1,m2);
509 /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>
511 ///Its \c Key is inherited from \c M2 and its \c Value is from
513 ///The \c M2::Value must be convertible to \c M1::Key.
514 ///\todo Check the requirements.
516 template <typename M1, typename M2, typename NC = False>
517 class ComposeMap : public MapBase<typename M2::Key, typename M1::Value, NC> {
518 typename SmartConstReference<M1>::Type m1;
519 typename SmartConstReference<M2>::Type m2;
521 typedef MapBase<typename M2::Key, typename M1::Value, NC> Parent;
522 typedef typename Parent::Key Key;
523 typedef typename Parent::Value Value;
526 ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
527 Value operator[](Key k) const {return m1[m2[k]];}
529 ///Returns a \ref ComposeMap class
531 ///This function just returns a \ref ComposeMap class.
533 ///\relates ComposeMap
534 template <typename M1, typename M2>
535 inline ComposeMap<M1, M2, True> composeMap(const M1 &m1,const M2 &m2) {
536 return ComposeMap<M1, M2, True>(m1,m2);
539 ///Combines of two maps using an STL (binary) functor.
541 ///Combines of two maps using an STL (binary) functor.
544 ///This \ref concept::ReadMap "read only map" takes two maps and a
545 ///binary functor and returns the composition of
547 ///given maps unsing the functor.
548 ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2
549 ///and \c f is of \c F,
552 /// CombineMap<M1, M2,F,V> cm(m1,m2,f);
554 /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt>
556 ///Its \c Key is inherited from \c M1 and its \c Value is \c V.
557 ///The \c M2::Value and \c M1::Value must be convertible to the corresponding
558 ///input parameter of \c F and the return type of \c F must be convertible
560 ///\todo Check the requirements.
562 template<typename M1, typename M2, typename F,
563 typename V = typename F::result_type,
565 class CombineMap : public MapBase<typename M1::Key, V, NC> {
566 typename SmartConstReference<M1>::Type m1;
567 typename SmartConstReference<M2>::Type m2;
570 typedef MapBase<typename M1::Key, V, NC> Parent;
571 typedef typename Parent::Key Key;
572 typedef typename Parent::Value Value;
575 CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
576 : m1(_m1), m2(_m2), f(_f) {};
577 Value operator[](Key k) const {return f(m1[k],m2[k]);}
580 ///Returns a \ref CombineMap class
582 ///This function just returns a \ref CombineMap class.
584 ///Only the first template parameter (the value type) must be given.
586 ///For example if \c m1 and \c m2 are both \c double valued maps, then
588 ///combineMap<double>(m1,m2,std::plus<double>)
590 ///is equivalent with
595 ///\relates CombineMap
596 template<typename M1, typename M2, typename F, typename V>
597 inline CombineMap<M1, M2, F, V, True>
598 combineMap(const M1& m1,const M2& m2, const F& f) {
599 return CombineMap<M1, M2, F, V, True>(m1,m2,f);
602 template<typename M1, typename M2, typename F>
603 inline CombineMap<M1, M2, F, typename F::result_type, True>
604 combineMap(const M1& m1, const M2& m2, const F& f) {
605 return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
608 template<typename M1, typename M2, typename K1, typename K2, typename V>
609 inline CombineMap<M1, M2, V (*)(K1, K2), V, True>
610 combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
611 return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f);
614 ///Negative value of a map
616 ///This \ref concept::ReadMap "read only map" returns the negative
618 ///value returned by the
619 ///given map. Its \c Key and \c Value will be inherited from \c M.
620 ///The unary \c - operator must be defined for \c Value, of course.
622 template<typename M, typename NC = False>
623 class NegMap : public MapBase<typename M::Key, typename M::Value, NC> {
624 typename SmartConstReference<M>::Type m;
626 typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
627 typedef typename Parent::Key Key;
628 typedef typename Parent::Value Value;
631 NegMap(const M &_m) : m(_m) {};
632 Value operator[](Key k) const {return -m[k];}
635 ///Returns a \ref NegMap class
637 ///This function just returns a \ref NegMap class.
639 template <typename M>
640 inline NegMap<M, True> negMap(const M &m) {
641 return NegMap<M, True>(m);
645 ///Absolute value of a map
647 ///This \ref concept::ReadMap "read only map" returns the absolute value
649 ///value returned by the
650 ///given map. Its \c Key and \c Value will be inherited
651 ///from <tt>M</tt>. <tt>Value</tt>
652 ///must be comparable to <tt>0</tt> and the unary <tt>-</tt>
653 ///operator must be defined for it, of course.
655 ///\bug We need a unified way to handle the situation below:
657 /// struct _UnConvertible {};
658 /// template<class A> inline A t_abs(A a) {return _UnConvertible();}
659 /// template<> inline int t_abs<>(int n) {return abs(n);}
660 /// template<> inline long int t_abs<>(long int n) {return labs(n);}
661 /// template<> inline long long int t_abs<>(long long int n) {return ::llabs(n);}
662 /// template<> inline float t_abs<>(float n) {return fabsf(n);}
663 /// template<> inline double t_abs<>(double n) {return fabs(n);}
664 /// template<> inline long double t_abs<>(long double n) {return fabsl(n);}
668 template<typename M, typename NC = False>
669 class AbsMap : public MapBase<typename M::Key, typename M::Value, NC> {
670 typename SmartConstReference<M>::Type m;
672 typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
673 typedef typename Parent::Key Key;
674 typedef typename Parent::Value Value;
677 AbsMap(const M &_m) : m(_m) {};
678 Value operator[](Key k) const {
680 return tmp >= 0 ? tmp : -tmp;
685 ///Returns a \ref AbsMap class
687 ///This function just returns a \ref AbsMap class.
690 inline AbsMap<M, True> absMap(const M &m) {
691 return AbsMap<M, True>(m);
694 ///Converts an STL style functor to a map
696 ///This \ref concept::ReadMap "read only map" returns the value
700 ///Template parameters \c K and \c V will become its
701 ///\c Key and \c Value. They must be given explicitely
702 ///because a functor does not provide such typedefs.
704 ///Parameter \c F is the type of the used functor.
708 typename K = typename F::argument_type,
709 typename V = typename F::result_type,
711 class FunctorMap : public MapBase<K, V, NC> {
714 typedef MapBase<K, V, NC> Parent;
715 typedef typename Parent::Key Key;
716 typedef typename Parent::Value Value;
719 FunctorMap(const F &_f) : f(_f) {};
720 Value operator[](Key k) const {return f(k);}
723 ///Returns a \ref FunctorMap class
725 ///This function just returns a \ref FunctorMap class.
727 ///The third template parameter isn't necessary to be given.
728 ///\relates FunctorMap
729 template<typename K, typename V, typename F> inline
730 FunctorMap<F, K, V, True> functorMap(const F &f) {
731 return FunctorMap<F, K, V, True>(f);
734 template <typename F> inline
735 FunctorMap<F, typename F::argument_type, typename F::result_type, True>
736 functorMap(const F &f) {
737 return functorMap<typename F::argument_type,
738 typename F::result_type, F>(f);
741 template <typename K, typename V> inline
742 FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
743 return functorMap<K, V, V (*)(K)>(f);
747 ///Converts a map to an STL style (unary) functor
749 ///This class Converts a map to an STL style (unary) functor.
750 ///that is it provides an <tt>operator()</tt> to read its values.
752 ///For the sake of convenience it also works as
753 ///a ususal \ref concept::ReadMap "readable map",
754 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist.
756 template <typename M, typename NC = False>
757 class MapFunctor : public MapBase<typename M::Key, typename M::Value, NC> {
758 typename SmartConstReference<M>::Type m;
760 typedef MapBase<typename M::Key, typename M::Value, NC> Parent;
761 typedef typename Parent::Key Key;
762 typedef typename Parent::Value Value;
765 typedef typename M::Key argument_type;
767 typedef typename M::Value result_type;
770 MapFunctor(const M &_m) : m(_m) {};
771 ///Returns a value of the map
772 Value operator()(Key k) const {return m[k];}
774 Value operator[](Key k) const {return m[k];}
777 ///Returns a \ref MapFunctor class
779 ///This function just returns a \ref MapFunctor class.
780 ///\relates MapFunctor
782 inline MapFunctor<M, True> mapFunctor(const M &m) {
783 return MapFunctor<M, True>(m);
787 ///Applies all map setting operations to two maps
789 ///This map has two \ref concept::WriteMap "writable map"
790 ///parameters and each write request will be passed to both of them.
791 ///If \c M1 is also \ref concept::ReadMap "readable",
792 ///then the read operations will return the
793 ///corresponding values of \c M1.
795 ///The \c Key and \c Value will be inherited from \c M1.
796 ///The \c Key and \c Value of M2 must be convertible from those of \c M1.
798 template<typename M1, typename M2, typename NC = False>
799 class ForkMap : public MapBase<typename M1::Key, typename M1::Value, NC> {
800 typename SmartConstReference<M1>::Type m1;
801 typename SmartConstReference<M2>::Type m2;
803 typedef MapBase<typename M1::Key, typename M1::Value, NC> Parent;
804 typedef typename Parent::Key Key;
805 typedef typename Parent::Value Value;
808 ForkMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
809 Value operator[](Key k) const {return m1[k];}
810 // void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);}
813 ///Returns an \ref ForkMap class
815 ///This function just returns an \ref ForkMap class.
816 ///\todo How to call these type of functions?
819 ///\todo Wrong scope in Doxygen when \c \\relates is used
820 template <typename M1, typename M2>
821 inline ForkMap<M1, M2, True> forkMap(const M1 &m1,const M2 &m2) {
822 return ForkMap<M1, M2, True>(m1,m2);
827 /* ************* BOOL MAPS ******************* */
829 ///Logical 'not' of a map
831 ///This bool \ref concept::ReadMap "read only map" returns the
832 ///logical negation of
833 ///value returned by the
834 ///given map. Its \c Key and will be inherited from \c M,
835 ///its Value is <tt>bool</tt>.
837 template <typename M, typename NC = False>
838 class NotMap : public MapBase<typename M::Key, bool, NC> {
839 typename SmartConstReference<M>::Type m;
841 typedef MapBase<typename M::Key, bool, NC> Parent;
842 typedef typename Parent::Key Key;
843 typedef typename Parent::Value Value;
846 NotMap(const M &_m) : m(_m) {};
847 Value operator[](Key k) const {return !m[k];}
850 ///Returns a \ref NotMap class
852 ///This function just returns a \ref NotMap class.
854 template <typename M>
855 inline NotMap<M, True> notMap(const M &m) {
856 return NotMap<M, True>(m);
866 #endif // LEMON_MAPS_H