title: Comparing typeid pointers
body: <p>In this program I use typeid to check the derived type of an object:</p>
  
  <pre><code>#include &lt;cstdint&gt;
  #include &lt;memory&gt;
  #include &lt;cassert&gt;
  #include &lt;string&gt;
  #include &lt;typeinfo&gt;
  
  struct  Wrap
  {
      explicit Wrap(int64_t id) : mImpl(new Impl&lt;int64_t&gt;(id)) {}
  
      explicit Wrap(std::string id) : mImpl(new Impl&lt;std::string&gt;(std::move(id))) {}    
  
      bool isInt64() const
      {
          const ImplBase&amp; impl = *mImpl;
          return (&amp;typeid(impl) == &amp;typeid(const Impl&lt;int64_t&gt;));
      }    
  
      bool isString() const
      {
          const ImplBase&amp; impl = *mImpl;
          return &amp;typeid(impl) == &amp;typeid(const Impl&lt;std::string&gt;);
      }
  
  private:
      struct ImplBase
      {
          virtual ~ImplBase() {}
      };
  
      template&lt;typename T&gt;
      struct Impl : ImplBase
      {
          Impl(T value) :
              mValue(std::move(value))
          {
          }
  
          T mValue;
      };
  
      std::shared_ptr&lt;const ImplBase&gt; mImpl;
  };
  
  int main()
  {
      Wrap r1(int64_t(1));
      assert(r1.isInt64());
  
      Wrap r2(std::string("s"));
      assert(r2.isString());
  }
  </code></pre>
  
  <p>It seems to work, however, I worry that this may not work on all platforms. Also I'm not sure if I should use:</p>
  
  <pre><code>typeid(const Impl&lt;std::string&gt;&amp;) // with ref
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>typeid(const Impl&lt;std::string&gt;) // without ref
  </code></pre>
  
  <p>in the comparison functions.</p>
  
  <p>Is the above code correct? If not, then how can I fix it?</p>