Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for implicit conversions to C++ types #264

Closed
wants to merge 5 commits into from

Commits on Aug 22, 2016

  1. Add support for implicit conversions to C++ types

    See issue pybind#259.
    
    This commit adds support for py::implicitly_convertible<From,To>() to
    perform implicit conversion, at the C++ level, when To is not a
    pybind11-registered type (e.g. a custom C++ type that should not be
    exposed, or a primitive type (double, etc.)).
    
    In essence, this lets you make use of C++ implicit converters (typically
    via a 'From::operator To()' or a non-explicit 'To::To(const From&)'
    constructor) with pybind11 instances without needing to create an
    explicit pybind11 interface for the conversion.
    
    As a simple example, consider the two classes:
    
        class A {
            ...
            void method(uint64_t val) { ... }
        }
        class B {
            ...
            operator uint64_t() { ... } // returns unique identifier
        }
    
    In C++, you can call `a.method(22)` or `a.method(b)`.  Telling
    pybind11 about the conversion allows you to do the same in python.
    
    Without the implicit conversion, you would have to either overload
    A.method to accept both uint64_t and B instances, or would have to add
    a method to B's interface that returns the id, then pass this method
    result to A's method.
    jagerman committed Aug 22, 2016
    Configuration menu
    Copy the full SHA
    9c99a8e View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2016

  1. Configuration menu
    Copy the full SHA
    fb60dcc View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4d8b2d5 View commit details
    Browse the repository at this point in the history
  3. Minor style fix

    jagerman committed Sep 9, 2016
    Configuration menu
    Copy the full SHA
    f9909fc View commit details
    Browse the repository at this point in the history

Commits on Sep 10, 2016

  1. Disable MSVC's unreachable code warning

    Depending on exactly when MSVC decides to inline, this can get triggered
    in ->impl when the called code unconditionally throws an exception.  MSVC
    is, in that case, right that the code is unreachable, but it's also a
    stupid warning (because it *doesn't* happen if MSVC doesn't decide to
    inline).
    jagerman committed Sep 10, 2016
    Configuration menu
    Copy the full SHA
    b3fb89f View commit details
    Browse the repository at this point in the history