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

Empty variant #3019

Closed
pschella opened this issue May 24, 2021 · 5 comments
Closed

Empty variant #3019

pschella opened this issue May 24, 2021 · 5 comments
Labels
casters Related to casters, and to be taken into account when analyzing/reworking casters enhancement help wanted

Comments

@pschella
Copy link
Contributor

Would be useful to cast between empty std::variant (i.e. std::monostate) and None. Something like this (in stl) should do the trick I think:

namespace pybind11 {
namespace detail {
    template <> struct type_caster<std::monostate> {
    public:
        PYBIND11_TYPE_CASTER(std::monostate, _("None"));

        bool load(handle src, bool) {
            return src.ptr() == Py_None;
        }

        static handle cast(std::monostate src, return_value_policy /* policy */, handle /* parent */) {
            Py_RETURN_NONE;
        }
    };
}
}
@SeanCurtis-TRI
Copy link

I completely agree. std::monostate is the preferred mechanism for indicating an empty variant, it would be nice to have it supported out of the box.

@Skylion007 Skylion007 added casters Related to casters, and to be taken into account when analyzing/reworking casters enhancement help wanted labels Aug 31, 2021
@Skylion007
Copy link
Collaborator

@SeanCurtis-TRI @pschella Would be happy to review a PR about this with relevant tests.

@gabrieldevillers
Copy link

Wasn't this fixed by #3818 ? @rwgk

@SeanCurtis-TRI
Copy link

I'm persuaded that the PR closes this issue. You have my vote.

@rwgk
Copy link
Collaborator

rwgk commented Aug 11, 2022

Wasn't this fixed by #3818 ? @rwgk

Yes, thanks for pointing out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
casters Related to casters, and to be taken into account when analyzing/reworking casters enhancement help wanted
Projects
None yet
Development

No branches or pull requests

5 participants