Created
October 14, 2011 10:24
-
-
Save piranna/1286759 to your computer and use it in GitHub Desktop.
OrderedHashMap similar to Python OrderedDict implemented with Boost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/multi_index_container.hpp> | |
#include <boost/multi_index/hashed_index.hpp> | |
#include <boost/multi_index/member.hpp> | |
#include <boost/multi_index/sequenced_index.hpp> | |
using namespace ::boost; | |
using namespace ::boost::multi_index; | |
template <typename T1,typename T2> | |
struct mutable_pair | |
{ | |
typedef T1 first_type; | |
typedef T2 second_type; | |
mutable_pair():first(T1()),second(T2()){} | |
mutable_pair(const T1& f,const T2& s):first(f),second(s){} | |
mutable_pair(const std::pair<T1,T2>& p):first(p.first),second(p.second){} | |
T1 first; | |
mutable T2 second; | |
}; | |
struct by_seq{}; | |
template <typename Key, typename T> | |
struct OrderedHashMap_set_indices: | |
indexed_by | |
< | |
hashed_unique<member | |
< | |
mutable_pair<Key, T>, | |
Key, | |
&mutable_pair<Key, T>::first | |
> >, | |
sequenced<tag<by_seq> > | |
> | |
{}; | |
template <typename Key, typename T> | |
class OrderedHashMap: | |
public multi_index_container | |
< | |
mutable_pair<Key, T>, | |
OrderedHashMap_set_indices<Key, T> | |
> | |
{ | |
//public: | |
// multi_index_container<mutable_pair<Key, T> >::index<by_seq>::type::iterator begin() | |
// { | |
// return get<by_seq>().begin(); | |
// }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment