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