title: How to define an implicit conversion for typedefs?
body: <p>I want to have an automatic conversion from <code>std::string</code> into my type <code>my_type</code>, defined as</p>
  
  <p><code>typedef std::pair&lt;std::string,int&gt; my_type;</code></p>
  
  <p>such that the <code>.first</code> part of the converted <code>my_type</code> is the string and the <code>.second</code> part is always 0.</p>
  
  <p>It should also work if one calls the function <code>std::string fun(my_type x, ...) { return x.first; }</code> with, say,</p>
  
  <p><code>std::string s = "Hello"; fun(s, ...);</code>.</p>
  
  <p>I don't want to define a new class instead of <code>my_type</code> and also not to overload all of my functions if possible. I tried to wrap my head around how to use <code>operator</code> for this but I can't get my program to compile.</p>
  
  <p><strong>EDIT:</strong>
  Since this doesn't seem to be possible without defining a custom struct or so, here is a workaround that I came up with, but I was hoping it can be achieved without defining a new class/struct. Thank you for saving me more time trying to do this, though.</p>
  
  <pre><code>class Element {
    public:
      Element() {};
      Element(std::string s, int a) { name = s; value = a; };
      Element(std::string s) { name = s; value = 0; };
      ...
      std::string return_name() { return name; };
    private:
      std::string name;
      int value;
   };
  
  std::string fun(Element x) { return x.return_name(); };
  </code></pre>
  
  <p>Calling <code>std::string s = "Hello"; fun(s);</code> works now automatically.</p>