lemon/maps.h
changeset 112 d2ee5e7f00ef
parent 82 bce6c8f93d10
child 123 8899d1891a3c
equal deleted inserted replaced
17:3f5906a50500 18:aa8a72f2780f
  1665   template<typename M1, typename M2>
  1665   template<typename M1, typename M2>
  1666   inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
  1666   inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
  1667     return LessMap<M1, M2>(m1,m2);
  1667     return LessMap<M1, M2>(m1,m2);
  1668   }
  1668   }
  1669 
  1669 
       
  1670   namespace _maps_bits {
       
  1671 
       
  1672     template <typename Value>
       
  1673     struct Identity {
       
  1674       typedef Value argument_type;
       
  1675       typedef Value result_type;
       
  1676       Value operator()(const Value& val) const {
       
  1677 	return val;
       
  1678       }
       
  1679     };
       
  1680 
       
  1681     template <typename _Iterator, typename Enable = void>
       
  1682     struct IteratorTraits {
       
  1683       typedef typename std::iterator_traits<_Iterator>::value_type Value;
       
  1684     };
       
  1685 
       
  1686     template <typename _Iterator>
       
  1687     struct IteratorTraits<_Iterator,
       
  1688       typename exists<typename _Iterator::container_type>::type>
       
  1689     {
       
  1690       typedef typename _Iterator::container_type::value_type Value;
       
  1691     };
       
  1692 
       
  1693   }
       
  1694 
       
  1695   /// \brief Writable bool map for logging each \c true assigned element
       
  1696   ///
       
  1697   /// A \ref concepts::ReadWriteMap "read-write" bool map for logging
       
  1698   /// each \c true assigned element, i.e it copies subsequently each
       
  1699   /// keys set to \c true to the given iterator.
       
  1700   ///
       
  1701   /// \tparam It the type of the Iterator.
       
  1702   /// \tparam Ke the type of the map's Key. The default value should
       
  1703   /// work in most cases.
       
  1704   ///
       
  1705   /// \note The container of the iterator must contain enough space
       
  1706   /// for the elements. (Or it should be an inserter iterator).
       
  1707   ///
       
  1708   /// \todo Revise the name of this class and give an example code.
       
  1709   template <typename It,
       
  1710 	    typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
       
  1711   class StoreBoolMap {
       
  1712   public:
       
  1713     typedef It Iterator;
       
  1714 
       
  1715     typedef Ke Key;
       
  1716     typedef bool Value;
       
  1717 
       
  1718     /// Constructor
       
  1719     StoreBoolMap(Iterator it)
       
  1720       : _begin(it), _end(it) {}
       
  1721 
       
  1722     /// Gives back the given iterator set for the first key
       
  1723     Iterator begin() const {
       
  1724       return _begin;
       
  1725     }
       
  1726 
       
  1727     /// Gives back the the 'after the last' iterator
       
  1728     Iterator end() const {
       
  1729       return _end;
       
  1730     }
       
  1731 
       
  1732     /// The set function of the map
       
  1733     void set(const Key& key, Value value) const {
       
  1734       if (value) {
       
  1735 	*_end++ = key;
       
  1736       }
       
  1737     }
       
  1738 
       
  1739   private:
       
  1740     Iterator _begin;
       
  1741     mutable Iterator _end;
       
  1742   };
       
  1743 
  1670   /// @}
  1744   /// @}
  1671 }
  1745 }
  1672 
  1746 
  1673 #endif // LEMON_MAPS_H
  1747 #endif // LEMON_MAPS_H