[QUESTION]Can different return value and call policies be used depending on the actual type of std::variant?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Recently, I want to export a function whose return type is std::variant. However, different return value policies and additional call policies should be applied according to the actual return value type, for example:
When return type is A, it needs to be py::return_value_policy::copy.
When return type is B, it needs to be py::return_value_policy::take_ownership with additional call policy py::keep_alive<0, 1>().
When return type is C, it needs to be py::return_value_policy::reference_internal.
Are there any ways to specify the different return_value_policies for each return type of std::variant<...>? Many thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing pybind11's std::variant conversion path and the return_value_policy and keep_alive APIs named in the question. Done means establishing whether policies can vary by variant alternative and documenting or specifying the required supported approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100