Skip to content

Commit

Permalink
added detail on wrapping factory functions
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Aug 23, 2023
1 parent 17403c0 commit c09f373
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/porting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ then either run an in-place constructor and return normally (in which case
the instance is assumed to be correctly constructed) or fail by raising an
exception.

To turn an existing factory function into a constructor, you will need to
combine the above pattern with an invocation of the move/copy-constructor,
e.g.:

.. code-block:: cpp
nb::class_<MyType>(m, "MyType")
.def("__init__", [](MyType *t) { new (t) MyType(MyType::create()); });
Implicit conversions
--------------------

Expand Down

0 comments on commit c09f373

Please sign in to comment.