Changeset 1076:67a115cdade4 in lemon0.x for src/lemon/maps.h
 Timestamp:
 01/12/05 13:51:30 (19 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1472
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/lemon/maps.h
r1070 r1076 99 99 }; 100 100 101 ///Returns a \ref ConstMap class 102 103 ///This function just returns a \ref ConstMap class. 104 ///\relates ConstMap 105 template<class V,class K> 106 inline ConstMap<V,K> constMap(const K &k) 107 { 108 return ConstMap<V,K>(k); 109 } 110 111 101 112 //to document later 102 113 template<typename T, T v> … … 533 544 } 534 545 546 ///Converts an STL style functor to a a map 547 548 ///This \ref concept::ReadMap "read only map" returns the value 549 ///of a 550 ///given map. 551 /// 552 ///Template parameters \c K and \c V will become its 553 ///\c Key and \c Value. They must be given explicitely 554 ///because a functor does not provide such typedefs. 555 /// 556 ///Parameter \c F is the type of the used functor. 557 558 559 template<class K,class V,class F> 560 class FunctorMap 561 { 562 const F &f; 563 public: 564 typedef K Key; 565 typedef V Value; 566 567 ///Constructor 568 569 ///\e 570 /// 571 FunctorMap(const F &_f) : f(_f) {}; 572 Value operator[](Key k) const {return f(k);} 573 }; 574 575 ///Returns a \ref FunctorMap class 576 577 ///This function just returns a \ref FunctorMap class. 578 /// 579 ///The third template parameter isn't necessary to be given. 580 ///\relates FunctorMap 581 template<class K,class V, class F> 582 inline FunctorMap<K,V,F> functorMap(const F &f) 583 { 584 return FunctorMap<K,V,F>(f); 585 } 586 587 ///Converts a map to an STL style functor 588 589 ///This class Converts a map to an STL style functor. 590 ///that is it provides an <tt>operator()</tt> to read its values. 591 /// 592 ///For the sake of convenience it also works as a ususal map, i.e 593 ///<tt>operator[]</tt> and the \c Key and \c Valu typedefs also exist. 594 595 template<class M> 596 class MapFunctor 597 { 598 const M &m; 599 public: 600 typedef typename M::Key Key; 601 typedef typename M::Value Value; 602 603 ///Constructor 604 605 ///\e 606 /// 607 MapFunctor(const M &_m) : m(_m) {}; 608 ///Returns a value of the map 609 610 ///\e 611 /// 612 Value operator()(Key k) const {return m[k];} 613 ///\e 614 /// 615 Value operator[](Key k) const {return m[k];} 616 }; 617 618 ///Returns a \ref MapFunctor class 619 620 ///This function just returns a \ref MapFunctor class. 621 ///\relates MapFunctor 622 template<class M> 623 inline MapFunctor<M> mapFunctor(const M &m) 624 { 625 return MapFunctor<M>(m); 626 } 627 628 535 629 /// @} 536 630
Note: See TracChangeset
for help on using the changeset viewer.