#include #include #include #include #include #include #include #include template class serialized_set_factory_class: public boost::flyweights::factory_marker { typedef std::set > container_type; public: typedef typename container_type::iterator handle_type; typedef typename container_type::value_type entry_type; serialized_set_factory_class() { std::ifstream ifs(Filename); if(ifs){ boost::archive::text_iarchive ia(ifs); typename container_type::size_type s=0; ia>>s; for(typename container_type::size_type n=s;n--;){ Value v; ia>>v; cont.insert(cont.end(),Entry(v)); } std::clog<<"loaded "<(*it); } std::clog<<"saved "< struct serialized_set_factory:boost::flyweights::factory_marker { template struct apply { typedef serialized_set_factory_class< Entry,Value,Filename > type; }; }; using namespace boost::flyweights; extern const char filename[]="fw.bd"; typedef flyweight< std::string, serialized_set_factory, no_tracking > fw_t; int main() { fw_t fw1("Hello"),fw2("Boost"),fw3("Farewell"),fw4("Boost"); }