dimanche 23 juin 2019

Use std::map with std::any as value type

I'd like to have class Config able to store literally any value within a string key. For that purpose it seems that std::map fits. Unfortunately this isn't compiling.

That looks like that std::is_copy_constructible> trait fails. How can I overcome that?

class Config {
public:
   static Config* get();

   enum class Option : int {
      FirstOption = 0x0,
      SecondOption = 0x1
   };

private:
   Config();
   ~Config();
   std::map<Option, std::any> m_config;

That compiled on MS Visual Studio, but won't compile on g++ 9.1.0.

Aucun commentaire:

Enregistrer un commentaire