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

Avoid explicitly resetting a std::[experimental::]optional #874

Merged
merged 1 commit into from
May 27, 2017

Conversation

bmerry
Copy link
Contributor

@bmerry bmerry commented May 26, 2017

Now that #851 has removed all multiple uses of a caster, it can just use
the default-constructed value with needing a reset. This fixes two
issues:

  1. With std::experimental::optional (at least under GCC 5.4), the = {}
    would construct an instance of the optional type and then move-assign
    it, which fails if the value type isn't move-assignable.

  2. With older versions of Boost, the = {} could fail because it is
    ambiguous, allowing construction of either boost::none or the value
    type.

Now that pybind#851 has removed all multiple uses of a caster, it can just use
the default-constructed value with needing a reset. This fixes two
issues:

1. With std::experimental::optional (at least under GCC 5.4), the `= {}`
would construct an instance of the optional type and then move-assign
it, which fails if the value type isn't move-assignable.

2. With older versions of Boost, the `= {}` could fail because it is
ambiguous, allowing construction of either `boost::none` or the value
type.
@bmerry
Copy link
Contributor Author

bmerry commented May 26, 2017

This is intended as an alternative to #850.

@dean0x7d
Copy link
Member

Thanks for simplifying this! Looks good together with the updated casters. The single-use rule is manually enforced right now, but it should become a compiler-enforced feature with #864.

@dean0x7d dean0x7d merged commit 46dbee7 into pybind:master May 27, 2017
@bmerry bmerry deleted the optional-noreset branch May 28, 2017 10:52
@dean0x7d dean0x7d modified the milestone: v2.2 Aug 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants