Is there an elegant way to represent a map containing different types in C++?

前端 未结 4 1098
小蘑菇
小蘑菇 2021-01-15 13:16

I\'m building a class which I want to configure using various parameters which may one of: int, double and string (or const char

4条回答
  •  暖寄归人
    2021-01-15 14:08

    If I have understood well, you want a std::map (or, even better, a std::unordered_map<> since you want hashes) where A is a string and B can be a int, double or std::string.

    For B you can use boost::any<>. Otherwise, if you don't want to use boost, you can use a discriminated union.

提交回复
热议问题