Restored (and modified) StoreBoolMap (it was removed in 7ff1c348ae0c)
authorAlpar Juttner <alpar@cs.elte.hu>
Thu, 20 Mar 2008 21:59:35 +0000
changeset 104cdbba181b786
parent 102 81563e019fa4
child 106 9ba2d265e191
Restored (and modified) StoreBoolMap (it was removed in 7ff1c348ae0c)

- also restored _maps_bits::IteratorTraits
- removes the Functor template parameter from StoreBoolMap
- doc changed a bit
lemon/maps.h
     1.1 --- a/lemon/maps.h	Thu Mar 20 17:15:35 2008 +0100
     1.2 +++ b/lemon/maps.h	Thu Mar 20 21:59:35 2008 +0000
     1.3 @@ -1667,6 +1667,80 @@
     1.4      return LessMap<M1, M2>(m1,m2);
     1.5    }
     1.6  
     1.7 +  namespace _maps_bits {
     1.8 +
     1.9 +    template <typename Value>
    1.10 +    struct Identity {
    1.11 +      typedef Value argument_type;
    1.12 +      typedef Value result_type;
    1.13 +      Value operator()(const Value& val) const {
    1.14 +	return val;
    1.15 +      }
    1.16 +    };
    1.17 +
    1.18 +    template <typename _Iterator, typename Enable = void>
    1.19 +    struct IteratorTraits {
    1.20 +      typedef typename std::iterator_traits<_Iterator>::value_type Value;
    1.21 +    };
    1.22 +
    1.23 +    template <typename _Iterator>
    1.24 +    struct IteratorTraits<_Iterator,
    1.25 +      typename exists<typename _Iterator::container_type>::type>
    1.26 +    {
    1.27 +      typedef typename _Iterator::container_type::value_type Value;
    1.28 +    };
    1.29 +
    1.30 +  }
    1.31 +
    1.32 +  /// \brief Writable bool map for logging each \c true assigned element
    1.33 +  ///
    1.34 +  /// A \ref concepts::ReadWriteMap "read-write" bool map for logging
    1.35 +  /// each \c true assigned element, i.e it copies subsequently each
    1.36 +  /// keys set to \c true to the given iterator.
    1.37 +  ///
    1.38 +  /// \tparam It the type of the Iterator.
    1.39 +  /// \tparam Ke the type of the map's Key. The default value should
    1.40 +  /// work in most cases.
    1.41 +  ///
    1.42 +  /// \note The container of the iterator must contain enough space
    1.43 +  /// for the elements. (Or it should be an inserter iterator).
    1.44 +  ///
    1.45 +  /// \todo Revise the name of this class and give an example code.
    1.46 +  template <typename It,
    1.47 +	    typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
    1.48 +  class StoreBoolMap {
    1.49 +  public:
    1.50 +    typedef It Iterator;
    1.51 +
    1.52 +    typedef Ke Key;
    1.53 +    typedef bool Value;
    1.54 +
    1.55 +    /// Constructor
    1.56 +    StoreBoolMap(Iterator it)
    1.57 +      : _begin(it), _end(it) {}
    1.58 +
    1.59 +    /// Gives back the given iterator set for the first key
    1.60 +    Iterator begin() const {
    1.61 +      return _begin;
    1.62 +    }
    1.63 +
    1.64 +    /// Gives back the the 'after the last' iterator
    1.65 +    Iterator end() const {
    1.66 +      return _end;
    1.67 +    }
    1.68 +
    1.69 +    /// The set function of the map
    1.70 +    void set(const Key& key, Value value) const {
    1.71 +      if (value) {
    1.72 +	*_end++ = key;
    1.73 +      }
    1.74 +    }
    1.75 +
    1.76 +  private:
    1.77 +    Iterator _begin;
    1.78 +    mutable Iterator _end;
    1.79 +  };
    1.80 +
    1.81    /// @}
    1.82  }
    1.83