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
dbe43ffc
Commit
dbe43ffc
authored
Apr 21, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed implicit type casters for reference_wrapper
parent
f54ded74
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
6 deletions
+11
-6
docs/changelog.rst
+1
-0
example/issues.cpp
+5
-3
example/issues.py
+2
-2
example/issues.ref
+1
-1
include/pybind11/cast.h
+2
-0
No files found.
docs/changelog.rst
View file @
dbe43ffc
...
...
@@ -16,6 +16,7 @@ Changelog
* Added a ``get_include()`` function to the Python module that returns the path
of the directory containing the installed pybind11 header files
* Documentation improvements: import issues, symbol visibility, pickling, limitations
* Added casting support for ``std::reference_wrapper<>``
1.4 (April 7, 2016)
--------------------------
...
...
example/issues.cpp
View file @
dbe43ffc
...
...
@@ -20,7 +20,7 @@ struct DispatchIssue : Base {
}
};
struct
Placeholder
{
int
i
;
};
struct
Placeholder
{
int
i
;
Placeholder
(
int
i
)
:
i
(
i
)
{
}
};
void
dispatch_issue_go
(
const
Base
*
b
)
{
b
->
dispatch
();
}
...
...
@@ -42,17 +42,19 @@ void init_issues(py::module &m) {
m2
.
def
(
"dispatch_issue_go"
,
&
dispatch_issue_go
);
py
::
class_
<
Placeholder
>
(
m2
,
"Placeholder"
)
.
def
(
py
::
init
<
int
>
())
.
def
(
"__repr__"
,
[](
const
Placeholder
&
p
)
{
return
"Placeholder["
+
std
::
to_string
(
p
.
i
)
+
"]"
;
});
// #171: Can't return reference wrappers (or STL datastructures containing them)
m2
.
def
(
"return_vec_of_reference_wrapper"
,
[]
{
m2
.
def
(
"return_vec_of_reference_wrapper"
,
[]
(
std
::
reference_wrapper
<
Placeholder
>
p4
)
{
Placeholder
*
p1
=
new
Placeholder
{
1
};
Placeholder
*
p2
=
new
Placeholder
{
2
};
Placeholder
*
p3
=
new
Placeholder
{
2
};
Placeholder
*
p3
=
new
Placeholder
{
3
};
std
::
vector
<
std
::
reference_wrapper
<
Placeholder
>>
v
;
v
.
push_back
(
std
::
ref
(
*
p1
));
v
.
push_back
(
std
::
ref
(
*
p2
));
v
.
push_back
(
std
::
ref
(
*
p3
));
v
.
push_back
(
p4
);
return
v
;
});
}
example/issues.py
View file @
dbe43ffc
...
...
@@ -5,7 +5,7 @@ sys.path.append('.')
from
example.issues
import
print_cchar
,
print_char
from
example.issues
import
DispatchIssue
,
dispatch_issue_go
from
example.issues
import
return_vec_of_reference_wrapper
from
example.issues
import
Placeholder
,
return_vec_of_reference_wrapper
print_cchar
(
"const char *"
)
print_char
(
'c'
)
...
...
@@ -28,4 +28,4 @@ class PyClass2(DispatchIssue):
b
=
PyClass2
()
dispatch_issue_go
(
b
)
print
(
return_vec_of_reference_wrapper
())
print
(
return_vec_of_reference_wrapper
(
Placeholder
(
4
)
))
example/issues.ref
View file @
dbe43ffc
...
...
@@ -2,4 +2,4 @@ const char *
c
Failed as expected: Tried to call pure virtual function "dispatch"
Yay..
[Placeholder[1], Placeholder[2], Placeholder[
2
]]
[Placeholder[1], Placeholder[2], Placeholder[
3], Placeholder[4
]]
include/pybind11/cast.h
View file @
dbe43ffc
...
...
@@ -246,6 +246,8 @@ public:
static
handle
cast
(
const
std
::
reference_wrapper
<
type
>
&
src
,
return_value_policy
policy
,
handle
parent
)
{
return
type_caster
<
type
>::
cast
(
&
src
.
get
(),
policy
,
parent
);
}
template
<
typename
T
>
using
cast_op_type
=
std
::
reference_wrapper
<
type
>
;
operator
std
::
reference_wrapper
<
type
>
()
{
return
std
::
ref
(
*
((
type
*
)
this
->
value
));
}
};
#define PYBIND11_TYPE_CASTER(type, py_name) \
...
...
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