title: Boost Python No to_python converter found for std::string
body: <p>So, I am trying to create a to_python converter that will allow me to return a boost::optional from an exposed function and have it treated as T if the optional is set and None if not.  Based on a post I found on <a href="http://mail.python.org/pipermail/cplusplus-sig/2007-May/012003.html" rel="noreferrer">C++Sig</a>, I wrote the following code.</p>
  
  <pre><code>template&lt;typename T&gt;
  struct optional_ : private boost::noncopyable {
    struct conversion {
      static PyObject* convert(boost::optional&lt;T&gt; const&amp; value) {
        if (value) {
          return boost::python::to_python_value&lt;T&gt;()(*value);
        }
        Py_INCREF(Py_None);
        return Py_None;
      }
    };
    explicit optional_() {
      boost::python::to_python_converter&lt;boost::optional&lt;T&gt;, conversion&gt;();
    }
  };
  </code></pre>
  
  <p>As far as I can tell, it works for converting the optionals, but python throws the following exception "TypeError: No to_python (by-value) converter found for C++ type: std::string".  I know that C++ is able to convert strings to python since most of my exposed functions return strings.  Why doesn't boost::python::to_python_value recognize it, and how can I utilize whatever converter it has?</p>
  
  <p>Fixed by changing to the following (based on <a href="http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/" rel="noreferrer">this article</a>):</p>
  
  <pre><code>template&lt;typename T&gt;
  struct optional_ : private boost::noncopyable {
    struct conversion {
      static PyObject* convert(boost::optional&lt;T&gt; const&amp; value) {
        using namespace boost::python;
        return incref((value ? object(*value) : object()).ptr());
      }
    };
    explicit optional_() {
      boost::python::to_python_converter&lt;boost::optional&lt;T&gt;, conversion&gt;();
    }
  };
  </code></pre>
  
  <p>Now to just do the other version so that it is cleaner and works better.</p>