... | ... |
@@ -1646,28 +1646,102 @@ |
1646 | 1646 |
typedef MapBase<typename M1::Key, bool> Parent; |
1647 | 1647 |
typedef typename Parent::Key Key; |
1648 | 1648 |
typedef typename Parent::Value Value; |
1649 | 1649 |
|
1650 | 1650 |
/// Constructor |
1651 | 1651 |
LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {} |
1652 | 1652 |
/// \e |
1653 | 1653 |
Value operator[](const Key &k) const { return _m1[k]<_m2[k]; } |
1654 | 1654 |
}; |
1655 | 1655 |
|
1656 | 1656 |
/// Returns an \ref LessMap class |
1657 | 1657 |
|
1658 | 1658 |
/// This function just returns an \ref LessMap class. |
1659 | 1659 |
/// |
1660 | 1660 |
/// For example, if \c m1 and \c m2 are maps with keys and values of |
1661 | 1661 |
/// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to |
1662 | 1662 |
/// <tt>m1[x]<m2[x]</tt>. |
1663 | 1663 |
/// |
1664 | 1664 |
/// \relates LessMap |
1665 | 1665 |
template<typename M1, typename M2> |
1666 | 1666 |
inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) { |
1667 | 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 | 1747 |
#endif // LEMON_MAPS_H |
0 comments (0 inline)