Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
19021b6e
Commit
19021b6e
authored
Jan 28, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding classu alias for class_<U, std::unique_ptr<U>>.
parent
78a9882e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
1 deletions
+10
-1
include/pybind11/smart_holder.h
+8
-0
tests/test_class_sh_unique_ptr_member.cpp
+2
-1
No files found.
include/pybind11/smart_holder.h
View file @
19021b6e
...
...
@@ -19,4 +19,12 @@ public:
using
class_
<
type_
,
smart_holder
,
options
...
>::
class_
;
};
// Similar in idea to `py::classh`, but for `std::unique_ptr<U>` holder, to support
// an easier transition to `py::smart_holder` as default holder.
template
<
typename
type_
,
typename
...
options
>
class
classu
:
public
class_
<
type_
,
std
::
unique_ptr
<
type_
>
,
options
...
>
{
public
:
using
class_
<
type_
,
std
::
unique_ptr
<
type_
>
,
options
...
>::
class_
;
};
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
tests/test_class_sh_unique_ptr_member.cpp
View file @
19021b6e
...
...
@@ -50,7 +50,8 @@ TEST_SUBMODULE(class_sh_unique_ptr_member, m) {
m
.
def
(
"make_unique_pointee"
,
make_unique_pointee
);
py
::
class_
<
ptr_owner
>
(
m
,
"ptr_owner"
)
// Could also be class_, but can conveniently be used for testing classu.
py
::
classu
<
ptr_owner
>
(
m
,
"ptr_owner"
)
.
def
(
py
::
init
<
std
::
unique_ptr
<
pointee
>>
(),
py
::
arg
(
"ptr"
))
.
def
(
"is_owner"
,
&
ptr_owner
::
is_owner
)
.
def
(
"give_up_ownership_via_unique_ptr"
,
&
ptr_owner
::
give_up_ownership_via_unique_ptr
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment