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
2b308e01
Commit
2b308e01
authored
Aug 24, 2016
by
Ivan Smirnov
Browse files
Add support for iterators with differing end type
parent
c5a1c8a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+10
-6
include/pybind11/stl_bind.h
include/pybind11/stl_bind.h
+1
-1
No files found.
include/pybind11/pybind11.h
View file @
2b308e01
...
...
@@ -1117,8 +1117,10 @@ PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, handle arg
keep_alive_impl
(
nurse
,
patient
);
}
template
<
typename
Iterator
,
bool
KeyIterator
=
false
>
struct
iterator_state
{
Iterator
it
,
end
;
template
<
typename
Iterator
,
typename
Sentinel
,
bool
KeyIterator
=
false
>
struct
iterator_state
{
Iterator
it
;
Sentinel
end
;
bool
first
;
};
...
...
@@ -1127,10 +1129,11 @@ NAMESPACE_END(detail)
template
<
typename
...
Args
>
detail
::
init
<
Args
...
>
init
()
{
return
detail
::
init
<
Args
...
>
();
}
template
<
typename
Iterator
,
typename
Sentinel
,
typename
ValueType
=
decltype
(
*
std
::
declval
<
Iterator
>()),
typename
...
Extra
>
iterator
make_iterator
(
Iterator
first
,
Iterator
last
,
Extra
&&
...
extra
)
{
typedef
detail
::
iterator_state
<
Iterator
>
state
;
iterator
make_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typedef
detail
::
iterator_state
<
Iterator
,
Sentinel
>
state
;
if
(
!
detail
::
get_type_info
(
typeid
(
state
)))
{
class_
<
state
>
(
handle
(),
""
)
...
...
@@ -1149,10 +1152,11 @@ iterator make_iterator(Iterator first, Iterator last, Extra &&... extra) {
return
(
iterator
)
cast
(
state
{
first
,
last
,
true
});
}
template
<
typename
Iterator
,
typename
Sentinel
,
typename
KeyType
=
decltype
((
*
std
::
declval
<
Iterator
>()).
first
),
typename
...
Extra
>
iterator
make_key_iterator
(
Iterator
first
,
Iterator
last
,
Extra
&&
...
extra
)
{
typedef
detail
::
iterator_state
<
Iterator
,
true
>
state
;
iterator
make_key_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typedef
detail
::
iterator_state
<
Iterator
,
Sentinel
,
true
>
state
;
if
(
!
detail
::
get_type_info
(
typeid
(
state
)))
{
class_
<
state
>
(
handle
(),
""
)
...
...
include/pybind11/stl_bind.h
View file @
2b308e01
...
...
@@ -245,7 +245,7 @@ pybind11::class_<std::vector<T, Allocator>, holder_type> bind_vector(pybind11::m
cl
.
def
(
"__iter__"
,
[](
Vector
&
v
)
{
return
pybind11
::
make_iterator
<
ItType
,
T
>
(
v
.
begin
(),
v
.
end
());
return
pybind11
::
make_iterator
<
ItType
,
ItType
,
T
>
(
v
.
begin
(),
v
.
end
());
},
pybind11
::
keep_alive
<
0
,
1
>
()
/* Essential: keep list alive while iterator exists */
);
...
...
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