aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-31 14:50:22 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-31 14:50:22 +0000
commitf61d05dcb0459a7678b64c65d9823c2f5069b54d (patch)
tree13faad5f977fea6e7ba6f8224f921c41dcc9543c
parent15d37ff1a670023cbb135bd8698a908c64750391 (diff)
downloadpaludis-f61d05dcb0459a7678b64c65d9823c2f5069b54d.tar.gz
paludis-f61d05dcb0459a7678b64c65d9823c2f5069b54d.tar.xz
Let maps use a different comparator
-rw-r--r--paludis/util/map-fwd.hh6
-rw-r--r--paludis/util/map-impl.hh67
-rw-r--r--paludis/util/map.hh12
3 files changed, 48 insertions, 37 deletions
diff --git a/paludis/util/map-fwd.hh b/paludis/util/map-fwd.hh
index 6aceffb..820eec1 100644
--- a/paludis/util/map-fwd.hh
+++ b/paludis/util/map-fwd.hh
@@ -20,9 +20,13 @@
#ifndef PALUDIS_GUARD_PALUDIS_UTIL_MAP_FWD_HH
#define PALUDIS_GUARD_PALUDIS_UTIL_MAP_FWD_HH 1
+
namespace paludis
{
- template <typename K_, typename V_>
+ template <typename T_>
+ struct DefaultMapComparator;
+
+ template <typename K_, typename V_, typename C_ = DefaultMapComparator<K_> >
struct Map;
}
diff --git a/paludis/util/map-impl.hh b/paludis/util/map-impl.hh
index ef0747f..377cf76 100644
--- a/paludis/util/map-impl.hh
+++ b/paludis/util/map-impl.hh
@@ -26,87 +26,94 @@
#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <map>
#include <iterator>
+#include <functional>
namespace paludis
{
+ template <typename T_>
+ struct PALUDIS_VISIBLE DefaultMapComparator :
+ std::less<T_>
+ {
+ };
+
template <>
- template <typename K_, typename V_>
- struct Implementation<Map<K_, V_> >
+ template <typename K_, typename V_, typename C_>
+ struct Implementation<Map<K_, V_, C_> >
{
- std::map<K_, V_> map;
+ std::map<K_, V_, C_> map;
};
}
-template <typename K_, typename V_>
-paludis::Map<K_, V_>::Map() :
- paludis::PrivateImplementationPattern<paludis::Map<K_, V_> >(new paludis::Implementation<paludis::Map<K_, V_> >)
+template <typename K_, typename V_, typename C_>
+paludis::Map<K_, V_, C_>::Map() :
+ paludis::PrivateImplementationPattern<paludis::Map<K_, V_, C_> >(new paludis::Implementation<paludis::Map<K_, V_, C_> >)
{
}
-template <typename K_, typename V_>
-paludis::Map<K_, V_>::~Map()
+template <typename K_, typename V_, typename C_>
+paludis::Map<K_, V_, C_>::~Map()
{
}
-template <typename K_, typename V_>
-typename paludis::Map<K_, V_>::Iterator
-paludis::Map<K_, V_>::begin() const
+template <typename K_, typename V_, typename C_>
+typename paludis::Map<K_, V_, C_>::Iterator
+paludis::Map<K_, V_, C_>::begin() const
{
return Iterator(_imp->map.begin());
}
-template <typename K_, typename V_>
-typename paludis::Map<K_, V_>::Iterator
-paludis::Map<K_, V_>::end() const
+template <typename K_, typename V_, typename C_>
+typename paludis::Map<K_, V_, C_>::Iterator
+paludis::Map<K_, V_, C_>::end() const
{
return Iterator(_imp->map.end());
}
-template <typename K_, typename V_>
-typename paludis::Map<K_, V_>::Iterator
-paludis::Map<K_, V_>::find(const K_ & k) const
+template <typename K_, typename V_, typename C_>
+typename paludis::Map<K_, V_, C_>::Iterator
+paludis::Map<K_, V_, C_>::find(const K_ & k) const
{
return Iterator(_imp->map.find(k));
}
-template <typename K_, typename V_>
-typename paludis::Map<K_, V_>::Inserter
-paludis::Map<K_, V_>::inserter()
+template <typename K_, typename V_, typename C_>
+typename paludis::Map<K_, V_, C_>::Inserter
+paludis::Map<K_, V_, C_>::inserter()
{
return Inserter(std::inserter(_imp->map, _imp->map.begin()));
}
-template <typename K_, typename V_>
+template <typename K_, typename V_, typename C_>
bool
-paludis::Map<K_, V_>::empty() const
+paludis::Map<K_, V_, C_>::empty() const
{
return _imp->map.empty();
}
-template <typename K_, typename V_>
+template <typename K_, typename V_, typename C_>
unsigned
-paludis::Map<K_, V_>::size() const
+paludis::Map<K_, V_, C_>::size() const
{
return _imp->map.size();
}
-template <typename K_, typename V_>
+template <typename K_, typename V_, typename C_>
void
-paludis::Map<K_, V_>::insert(const K_ & k, const V_ & v)
+paludis::Map<K_, V_, C_>::insert(const K_ & k, const V_ & v)
{
_imp->map.insert(std::make_pair(k, v));
}
-template <typename K_, typename V_>
+template <typename K_, typename V_, typename C_>
void
-paludis::Map<K_, V_>::erase(const typename paludis::Map<K_, V_>::Iterator & i)
+paludis::Map<K_, V_, C_>::erase(const typename paludis::Map<K_, V_, C_>::Iterator & i)
{
_imp->map.erase(i->first);
}
-template <typename K_, typename V_>
+template <typename K_, typename V_, typename C_>
void
-paludis::Map<K_, V_>::erase(const K_ & i)
+paludis::Map<K_, V_, C_>::erase(const K_ & i)
{
_imp->map.erase(i);
}
diff --git a/paludis/util/map.hh b/paludis/util/map.hh
index 0e67a8d..8319fb2 100644
--- a/paludis/util/map.hh
+++ b/paludis/util/map.hh
@@ -32,24 +32,24 @@
namespace paludis
{
- template <typename K_, typename V_>
+ template <typename K_, typename V_, typename C_>
class PALUDIS_VISIBLE Map :
- private PrivateImplementationPattern<Map<K_, V_> >,
- private InstantiationPolicy<Map<K_, V_>, instantiation_method::NonCopyableTag>
+ private PrivateImplementationPattern<Map<K_, V_, C_> >,
+ private InstantiationPolicy<Map<K_, V_, C_>, instantiation_method::NonCopyableTag>
{
private:
- using PrivateImplementationPattern<Map<K_, V_> >::_imp;
+ using PrivateImplementationPattern<Map<K_, V_, C_> >::_imp;
public:
Map();
~Map();
- typedef libwrapiter::ForwardIterator<Map<K_, V_>, const std::pair<const K_, V_> > Iterator;
+ typedef libwrapiter::ForwardIterator<Map<K_, V_, C_>, const std::pair<const K_, V_> > Iterator;
Iterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
Iterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
Iterator find(const K_ &) const PALUDIS_ATTRIBUTE((warn_unused_result));
- typedef libwrapiter::OutputIterator<Map<K_, V_>, std::pair<const K_, V_> > Inserter;
+ typedef libwrapiter::OutputIterator<Map<K_, V_, C_>, std::pair<const K_, V_> > Inserter;
Inserter inserter() PALUDIS_ATTRIBUTE((warn_unused_result));
bool empty() const PALUDIS_ATTRIBUTE((warn_unused_result));