|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-08-13 20:53:17
AMDG
John C. Femiani wrote:
> I was just wondering why fusion (and mpl) don't include multi-maps or
> multi-sets. Are they unnecessary at compile time? Are they too
> trivial? Do they conceptually not work?
The easiest way to implement a multimap is in terms of an ordinary map.
In a fusion/mpl map the key is a type
and lookup uses overload resolution. This means that there
is necessarily a 1-1 correspondence between keys and values.
The obvious way to implement a multimap is to make the
value a container. Because of the function nature of
fusion/mpl this would be like
template<class M, class K, class V>
struct multimap_insert_existing {
typedef typename insert<typename erase_key<M, K>::type, pair<K,
typename push_back<typename at<M, K>::type, V>::type> > type;
};
template<class M, class K, class V>
struct multimap_insert_new {
typedef typename insert<M, pair<K, vector1<V> > > type;
};
template<class M, class T>
struct multimap_insert {
typedef typename T::first key_type;
typedef typename T::second value_type;
typedef typename eval_if<has_key<M, key_type>,
multimap_insert_existing<M, key_type_value_type>, multimap_insert_new<M,
key_type, value_type> >::type type;
};
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net