title: How to wrap templated classes with pybind11
body: <p>I've got a class structure similar to the one below, where I have two types A and B with similar signatures that only differ in argument/return type. I then use a class template to be able to process both classes, achieving a static variant of ducktyping in Python. Now I want to wrap this code into Python with pybind11, where I hope to get a class that takes both types using standard, dynamic ducktyping. How do I do this?</p>
  
  <p>I'm basically looking for a way to disable the strict type check in pybind11 or specify multiple types such that both TypeA and TypeB are accepted. The way the example below is defined, only TypeA passes the check. I also can't unify A and B into a base class because of the different function signatures.</p>
  
  <pre><code>#include &lt;pybind11/pybind11.h&gt;
  #include &lt;iostream&gt;
  
  class TypeA {
  public:
      typedef double InType;
      typedef std::string OutType;
      const OutType operator()(const InType arg)
      {
          return std::to_string(arg);
      }
  };
  
  class TypeB {
  public:
      typedef std::string InType;
      typedef double OutType;
      const OutType operator()(const InType arg)
      {
          return std::stod(arg);
      }
  };
  
  template&lt;typename T&gt;
  class DuckType {
  public:
      void runType(const typename T::InType arg)
      {
          T x;
          const typename T::OutType y = x(arg);
          std::cout &lt;&lt; y &lt;&lt; std::endl;
      }
  };
  
  namespace py = pybind11;
  
  PYBIND11_PLUGIN(ducktyping) {
  
      pybind11::module m("ducktyping", "Testing ducktyping with templates");
  
      typedef DuckType&lt;TypeA&gt; Type;
      py::class_&lt;Type&gt;(m, "DuckType")
      .def("run_type", &amp;Type::runType);
      ;
      return m.ptr();
  }
  </code></pre>