Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
dbe43ffc
Commit
dbe43ffc
authored
Apr 21, 2016
by
Wenzel Jakob
Browse files
completed implicit type casters for reference_wrapper
parent
f54ded74
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
6 deletions
+11
-6
docs/changelog.rst
docs/changelog.rst
+1
-0
example/issues.cpp
example/issues.cpp
+5
-3
example/issues.py
example/issues.py
+2
-2
example/issues.ref
example/issues.ref
+1
-1
include/pybind11/cast.h
include/pybind11/cast.h
+2
-0
No files found.
docs/changelog.rst
View file @
dbe43ffc
...
@@ -16,6 +16,7 @@ Changelog
...
@@ -16,6 +16,7 @@ Changelog
* Added a ``get_include()`` function to the Python module that returns the path
* Added a ``get_include()`` function to the Python module that returns the path
of the directory containing the installed pybind11 header files
of the directory containing the installed pybind11 header files
* Documentation improvements: import issues, symbol visibility, pickling, limitations
* Documentation improvements: import issues, symbol visibility, pickling, limitations
* Added casting support for ``std::reference_wrapper<>``
1.4 (April 7, 2016)
1.4 (April 7, 2016)
--------------------------
--------------------------
...
...
example/issues.cpp
View file @
dbe43ffc
...
@@ -20,7 +20,7 @@ struct DispatchIssue : Base {
...
@@ -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
();
}
void
dispatch_issue_go
(
const
Base
*
b
)
{
b
->
dispatch
();
}
...
@@ -42,17 +42,19 @@ void init_issues(py::module &m) {
...
@@ -42,17 +42,19 @@ void init_issues(py::module &m) {
m2
.
def
(
"dispatch_issue_go"
,
&
dispatch_issue_go
);
m2
.
def
(
"dispatch_issue_go"
,
&
dispatch_issue_go
);
py
::
class_
<
Placeholder
>
(
m2
,
"Placeholder"
)
py
::
class_
<
Placeholder
>
(
m2
,
"Placeholder"
)
.
def
(
py
::
init
<
int
>
())
.
def
(
"__repr__"
,
[](
const
Placeholder
&
p
)
{
return
"Placeholder["
+
std
::
to_string
(
p
.
i
)
+
"]"
;
});
.
def
(
"__repr__"
,
[](
const
Placeholder
&
p
)
{
return
"Placeholder["
+
std
::
to_string
(
p
.
i
)
+
"]"
;
});
// #171: Can't return reference wrappers (or STL datastructures containing them)
// #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
*
p1
=
new
Placeholder
{
1
};
Placeholder
*
p2
=
new
Placeholder
{
2
};
Placeholder
*
p2
=
new
Placeholder
{
2
};
Placeholder
*
p3
=
new
Placeholder
{
2
};
Placeholder
*
p3
=
new
Placeholder
{
3
};
std
::
vector
<
std
::
reference_wrapper
<
Placeholder
>>
v
;
std
::
vector
<
std
::
reference_wrapper
<
Placeholder
>>
v
;
v
.
push_back
(
std
::
ref
(
*
p1
));
v
.
push_back
(
std
::
ref
(
*
p1
));
v
.
push_back
(
std
::
ref
(
*
p2
));
v
.
push_back
(
std
::
ref
(
*
p2
));
v
.
push_back
(
std
::
ref
(
*
p3
));
v
.
push_back
(
std
::
ref
(
*
p3
));
v
.
push_back
(
p4
);
return
v
;
return
v
;
});
});
}
}
example/issues.py
View file @
dbe43ffc
...
@@ -5,7 +5,7 @@ sys.path.append('.')
...
@@ -5,7 +5,7 @@ sys.path.append('.')
from
example.issues
import
print_cchar
,
print_char
from
example.issues
import
print_cchar
,
print_char
from
example.issues
import
DispatchIssue
,
dispatch_issue_go
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_cchar
(
"const char *"
)
print_char
(
'c'
)
print_char
(
'c'
)
...
@@ -28,4 +28,4 @@ class PyClass2(DispatchIssue):
...
@@ -28,4 +28,4 @@ class PyClass2(DispatchIssue):
b
=
PyClass2
()
b
=
PyClass2
()
dispatch_issue_go
(
b
)
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 *
...
@@ -2,4 +2,4 @@ const char *
c
c
Failed as expected: Tried to call pure virtual function "dispatch"
Failed as expected: Tried to call pure virtual function "dispatch"
Yay..
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:
...
@@ -246,6 +246,8 @@ public:
static
handle
cast
(
const
std
::
reference_wrapper
<
type
>
&
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
const
std
::
reference_wrapper
<
type
>
&
src
,
return_value_policy
policy
,
handle
parent
)
{
return
type_caster
<
type
>::
cast
(
&
src
.
get
(),
policy
,
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) \
#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