Is there any way to have a map of different types without casting? I don't mean std::map
or boost::map
, I mean my own implementation without casting. I don't want to use boost::any
or std::any
, something like std::variant
if it doesn't use casting. I am open to templates or any other fast (no casting) solution.
Would this work:
#define Args double, int, std::vector<double>, std::shared_ptr<double>
class ugly_map_uppearing_nice final
{
public:
template<typename T>
void get_ref_risky(const std::string& name, T* t)
{
//it = find... it!=end, it->... + get
// some checks...
t = &std::get<T>(m_imp[name]);
};
private:
std::map<std::string, std::variant<Args>> m_imp;
};