Skip to content

Commit

Permalink
fix map serialization on osx (apache#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen authored May 8, 2017
1 parent ee8481c commit a6c5701
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions include/dmlc/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,15 @@ struct PairHandler {
};

// set type handler that can handle most collection type case
template<typename ContainerType>
template<typename ContainerType, typename ElemType>
struct CollectionHandler {
inline static void Write(Stream *strm, const ContainerType &data) {
typedef typename ContainerType::value_type ElemType;
// dump data to vector
std::vector<ElemType> vdata(data.begin(), data.end());
// serialize the vector
Handler<std::vector<ElemType> >::Write(strm, vdata);
}
inline static bool Read(Stream *strm, ContainerType *data) {
typedef typename ContainerType::value_type ElemType;
std::vector<ElemType> vdata;
if (!Handler<std::vector<ElemType> >::Read(strm, &vdata)) return false;
data->clear();
Expand Down Expand Up @@ -308,17 +306,6 @@ struct Handler<std::basic_string<T> > {
}
};

template<typename T>
struct Handler<const std::basic_string<T> > {
inline static void Write(Stream *strm, const std::basic_string<T> &data) {
IfThenElse<dmlc::is_pod<T>::value,
PODStringHandler<T>,
UndefinedSerializerFor<T>,
const std::basic_string<T> >
::Write(strm, data);
}
};

template<typename TA, typename TB>
struct Handler<std::pair<TA, TB> > {
inline static void Write(Stream *strm, const std::pair<TA, TB> &data) {
Expand All @@ -339,22 +326,22 @@ struct Handler<std::pair<TA, TB> > {

template<typename K, typename V>
struct Handler<std::map<K, V> >
: public CollectionHandler<std::map<K, V> > {
: public CollectionHandler<std::map<K, V>, std::pair<K, V> > {
};

template<typename K, typename V>
struct Handler<std::multimap<K, V> >
: public CollectionHandler<std::multimap<K, V> > {
: public CollectionHandler<std::multimap<K, V>, std::pair<K, V> > {
};

template<typename T>
struct Handler<std::set<T> >
: public CollectionHandler<std::set<T> > {
: public CollectionHandler<std::set<T>, T> {
};

template<typename T>
struct Handler<std::multiset<T> >
: public CollectionHandler<std::multiset<T> > {
: public CollectionHandler<std::multiset<T>, T> {
};

template<typename T>
Expand All @@ -370,22 +357,22 @@ struct Handler<std::deque<T> >
#if DMLC_USE_CXX11
template<typename K, typename V>
struct Handler<std::unordered_map<K, V> >
: public CollectionHandler<std::unordered_map<K, V> > {
: public CollectionHandler<std::unordered_map<K, V>, std::pair<K, V> > {
};

template<typename K, typename V>
struct Handler<std::unordered_multimap<K, V> >
: public CollectionHandler<std::unordered_multimap<K, V> > {
: public CollectionHandler<std::unordered_multimap<K, V>, std::pair<K, V> > {
};

template<typename T>
struct Handler<std::unordered_set<T> >
: public CollectionHandler<std::unordered_set<T> > {
: public CollectionHandler<std::unordered_set<T>, T> {
};

template<typename T>
struct Handler<std::unordered_multiset<T> >
: public CollectionHandler<std::unordered_multiset<T> > {
: public CollectionHandler<std::unordered_multiset<T>, T> {
};
#endif
//! \endcond
Expand Down

0 comments on commit a6c5701

Please sign in to comment.