lemon/maps.h
changeset 1681 84e43c7ca1e3
parent 1675 fa89ffb27a6d
child 1691 6be54bcc14ec
equal deleted inserted replaced
10:9e8a430038a7 11:edb23aa851e9
   707   template<typename F, 
   707   template<typename F, 
   708 	   typename K = typename F::argument_type, 
   708 	   typename K = typename F::argument_type, 
   709 	   typename V = typename F::result_type,
   709 	   typename V = typename F::result_type,
   710 	   typename NC = False> 
   710 	   typename NC = False> 
   711   class FunctorMap : public MapBase<K, V, NC> {
   711   class FunctorMap : public MapBase<K, V, NC> {
   712     const F &f;
   712     F f;
   713   public:
   713   public:
   714     typedef MapBase<K, V, NC> Parent;
   714     typedef MapBase<K, V, NC> Parent;
   715     typedef typename Parent::Key Key;
   715     typedef typename Parent::Key Key;
   716     typedef typename Parent::Value Value;
   716     typedef typename Parent::Value Value;
   717 
   717 
   718     ///Constructor
   718     ///Constructor
   719     FunctorMap(const F &_f) : f(_f) {};
   719     FunctorMap(const F &_f) : f(_f) {}
   720     Value operator[](Key k) const {return f(k);}
   720 
       
   721     Value operator[](Key k) const { return f(k);}
   721   };
   722   };
   722   
   723   
   723   ///Returns a \ref FunctorMap class
   724   ///Returns a \ref FunctorMap class
   724 
   725 
   725   ///This function just returns a \ref FunctorMap class.
   726   ///This function just returns a \ref FunctorMap class.
   732   }
   733   }
   733 
   734 
   734   template <typename F> inline 
   735   template <typename F> inline 
   735   FunctorMap<F, typename F::argument_type, typename F::result_type, True> 
   736   FunctorMap<F, typename F::argument_type, typename F::result_type, True> 
   736   functorMap(const F &f) {
   737   functorMap(const F &f) {
   737     return functorMap<typename F::argument_type, 
   738     return FunctorMap<F, typename F::argument_type, 
   738       typename F::result_type, F>(f);
   739       typename F::result_type, True>(f);
   739   }
   740   }
   740 
   741 
   741   template <typename K, typename V> inline 
   742   template <typename K, typename V> inline 
   742   FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
   743   FunctorMap<V (*)(K), K, V, True> functorMap(V (*f)(K)) {
   743     return functorMap<K, V, V (*)(K)>(f);
   744     return FunctorMap<V (*)(K), K, V, True>(f);
   744   }
   745   }
   745 
   746 
   746 
   747 
   747   ///Converts a map to an STL style (unary) functor
   748   ///Converts a map to an STL style (unary) functor
   748 
   749