title: How can I enforce two function parameters have the same template type?
body: <p>I'm trying to create a registry in which I can register sensors with associated sensor processing stages.</p>
  
  <p><strong>TLDR:</strong> How can I enforce two function parameters have a common template parameter/member type where both inherit from abstract classes and can be placed into collections which accept any objects derived from these abstract classes?</p>
  
  <p>Ideally, I would like to have something like this</p>
  
  <pre><code>// registry
  map&lt;string, Sensor&gt; sensors;
  map&lt;string, SensorProcessing&gt; processors;
  
  // sensor base class
  class Sensor
  {
      virtual Data sense();
  }
  
  // processing base class
  class SensorProcessing
  {
      virtual void process(Data d);
  }
  
  // data kind base class
  struct Data { string name; }
  </code></pre>
  
  <p>where <code>Sensor</code> and <code>SensorProcessing</code> are abstract types.
  Ideally, the collection should accept any derived type of sensor or processing.</p>
  
  <p>When I register the sensor and a processing stage, I would like to enforce that the <code>SensorProcessing</code> object can handle the data produced by the <code>Sensor</code> object it is registered with. 
  For instance, it would not make sense to pair a processing stage operating on images with a sensor that outputs laser scans.</p>
  
  <p>Something like this for the registration would be nice:</p>
  
  <pre><code>void register_sensor(string name, Sensor s, SensorProcessing p)
  {
      // enforce that p eats what s produces, in a typesafe but polymorphic manner
      static_assert(std::is_same&lt;s::data_type, p::data_type&gt;);
  }
  </code></pre>
  
  <p>But of course it's not that simple because with the arguments of <code>register_sensor()</code> being the base types, I can't at compile time check that they agree on the data type they use without templating. I'm not sure how to do this however, and also place sensors and processors into their own class hierarchies.</p>