Есть такой вот контейнер на базе boost::multin_index.
Код компилируется microsoft компилятором, но вот с GCC проблемы...
| Скрытый текст |
| #ifndef __vector_map_mltidx_h__
#define __vector_map_mltidx_h__
//std
#include <algorithm>
//boost
#ifndef Q_MOC_RUN //QT MOC BUG
#include "boost/multi_index_container.hpp"
#include "boost/multi_index/sequenced_index.hpp"
#include "boost/multi_index/ordered_index.hpp"
#include "boost/multi_index/random_access_index.hpp"
#endif
template<typename Element_, typename Extractor_>
struct vector_map_mltidx
{
//types
typedef Element_ Element_t;
typedef Extractor_ Extractor_t;
//tags
struct tag_SEQ {};
struct tag_RA {};
struct tag_OU {};
typedef boost::multi_index_container<
Element_,
boost::multi_index::indexed_by<
boost::multi_index::sequenced<boost::multi_index::tag<tag_SEQ> >,
boost::multi_index::random_access<boost::multi_index::tag<tag_RA> >,
boost::multi_index::ordered_unique<boost::multi_index::tag<tag_OU>, Extractor_>
>
> container;
typedef typename container::template index<tag_SEQ>::type container_SEQ_view;
typedef typename container::template index<tag_RA>::type container_RA_view;
typedef typename container::template index<tag_OU>::type container_OU_view;
};
namespace vector_map_serialize {
template<class Element_, class Extractor_, class Archive>
void save_vector_map_mltidx(typename ::vector_map_mltidx<Element_, Extractor_>::container const &vmap, Archive &ar, const unsigned int /*version*/)
{
typedef ::vector_map_mltidx<Element_, Extractor_> vm_mdx_t;
unsigned int size = vmap.size();
ar << size;
/*
vector_map_mltidx.h:49: error: expected primary-expression before ')' token
typename vm_mdx_t::container_SEQ_view const &seq = vmap.get<vm_mdx_t::tag_SEQ>();
*/ ^
typename vm_mdx_t::container_SEQ_view const &seq = vmap.get<vm_mdx_t::tag_SEQ>();
std::for_each(seq.begin(), seq.end(), [&vmap, &ar](const Element_& el)
{
ar << el;
}
);
}
} //namespace vector_map_serialize
#endif
|
| |
Я в курсе про то что бустовый сериализатор умеет сериализовать мультииндекс.
Но нужно именно так.