# HG changeset patch # User Alpar Juttner # Date 2008-03-20 22:59:35 # Node ID cdbba181b7869afb6797aa3a0f44d10636c5c8d0 # Parent 81563e019fa4cd5ce484d3eecc7e30da2e23fa30 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 diff --git a/lemon/maps.h b/lemon/maps.h --- a/lemon/maps.h +++ b/lemon/maps.h @@ -1667,6 +1667,80 @@ return LessMap(m1,m2); } + namespace _maps_bits { + + template + struct Identity { + typedef Value argument_type; + typedef Value result_type; + Value operator()(const Value& val) const { + return val; + } + }; + + template + struct IteratorTraits { + typedef typename std::iterator_traits<_Iterator>::value_type Value; + }; + + template + struct IteratorTraits<_Iterator, + typename exists::type> + { + typedef typename _Iterator::container_type::value_type Value; + }; + + } + + /// \brief Writable bool map for logging each \c true assigned element + /// + /// A \ref concepts::ReadWriteMap "read-write" bool map for logging + /// each \c true assigned element, i.e it copies subsequently each + /// keys set to \c true to the given iterator. + /// + /// \tparam It the type of the Iterator. + /// \tparam Ke the type of the map's Key. The default value should + /// work in most cases. + /// + /// \note The container of the iterator must contain enough space + /// for the elements. (Or it should be an inserter iterator). + /// + /// \todo Revise the name of this class and give an example code. + template ::Value> + class StoreBoolMap { + public: + typedef It Iterator; + + typedef Ke Key; + typedef bool Value; + + /// Constructor + StoreBoolMap(Iterator it) + : _begin(it), _end(it) {} + + /// Gives back the given iterator set for the first key + Iterator begin() const { + return _begin; + } + + /// Gives back the the 'after the last' iterator + Iterator end() const { + return _end; + } + + /// The set function of the map + void set(const Key& key, Value value) const { + if (value) { + *_end++ = key; + } + } + + private: + Iterator _begin; + mutable Iterator _end; + }; + /// @} }