Created
January 12, 2014 07:46
-
-
Save Fuyutsubaki/8382011 to your computer and use it in GitHub Desktop.
型から値をだすmap
Type to Value map on C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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