title: c++ Handle different types from json object
body: <p>I have a transport listener that receives a json object. For this purposes different subscribers will be interested in different properties of the json msg. The problem with that means being able to handle the type of the property dynamically.</p>
  
  <p>I was thinking of having a data structure similar to this to help:</p>
  
  <pre><code>std::unordered_map&lt;std::string,std::vector&lt;std::function&lt;void (T)&gt;&gt;&gt;; 
  std::unordered_map&lt;std::string,std::vector&lt;T&amp;&gt;&gt;&gt;; 
  </code></pre>
  
  <p>//this doesn't work because I will be forced to have template T on a class template level, bound to the same type which is not what I want.</p>
  
  <p>I was thinking of a <code>union</code> to encapsulate all possible types but that doesn't sound entirely feasible</p>
  
  <p>How it will be used pseudocode:</p>
  
  <pre><code>void OnJsonObjectReceived(JsonObject msg)
  {
     auto key = "test_prop";
     val = get_value_from_json_msg(key, msg) ;
     for(subscriber in _unordered_map.find(key)-&gt;subscribers)
     {
       subscriber = val;
     }
  }
  </code></pre>