Skip to content

Instantly share code, notes, and snippets.

@Fuyutsubaki
Created January 12, 2014 07:46
Show Gist options
  • Save Fuyutsubaki/8382011 to your computer and use it in GitHub Desktop.
Save Fuyutsubaki/8382011 to your computer and use it in GitHub Desktop.
型から値をだすmap Type to Value map on C++
#include<boost\any.hpp>
#include<unordered_map>
#include<typeindex>
#include<iostream>
#include<string>
class Type2ValueMap
{
public:
template<class T>
const T&get()const
{
return boost::any_cast<const T&>(map.at(typeid(T)));
}
template<class T>
void set(const T&x){map[typeid(T)] = x;}
private:
std::unordered_map<std::type_index, boost::any> map;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment