Skip to content

Instantly share code, notes, and snippets.

@OXPHOS
Last active July 18, 2016 03:19
Show Gist options
  • Save OXPHOS/c59a016e20054ccb4095d7c22d352ed5 to your computer and use it in GitHub Desktop.
Save OXPHOS/c59a016e20054ccb4095d7c22d352ed5 to your computer and use it in GitHub Desktop.
template<typename T>
void* createInstance() { return new T; }
void cast_to_type()
{
typedef std::map<std::string, void*(*)()> map_type;
map_type map;
map["int"] = createInstance<int>;
map["double"] = createInstance<double>;
map["shogun::SGVector<int>"] = createInstance<shogun::SGVector<int> >;
map["shogun::SGVector<double>"] = createInstance<shogun::SGVector<double> >;
}
#define CEREAL_SAVE_FUNCTION_NAME cereal_save
#define CEREAL_LOAD_FUNCTION_NAME cereal_load
template<class Archive>
void CSGObject::cereal_save(Archive& ar) const
{
for (auto it = self->map.begin(); it != self->map.end(); ++it)
ar(it->second); // archive Any object
}
template void CSGObject::cereal_save<cereal::JSONOutputArchive>(cereal::JSONOutputArchive& ar) const;
template<class Archive>
void CSGObject::cereal_load(Archive& ar)
{
}
template void CSGObject::cereal_load<cereal::JSONInputArchive>(cereal::JSONInputArchive& ar);
#undef CEREAL_SAVE_FUNCTION_NAME
#undef CEREAL_LOAD_FUNCTION_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment