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
146397ec
Commit
146397ec
authored
Sep 06, 2016
by
Wenzel Jakob
Browse files
allow iterators with different RV policies (fixes #388)
parent
fe34241e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+6
-5
No files found.
include/pybind11/pybind11.h
View file @
146397ec
...
...
@@ -1123,7 +1123,7 @@ PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, handle arg
keep_alive_impl
(
nurse
,
patient
);
}
template
<
typename
Iterator
,
typename
Sentinel
,
bool
KeyIterator
=
false
>
template
<
typename
Iterator
,
typename
Sentinel
,
bool
KeyIterator
,
typename
...
Extra
>
struct
iterator_state
{
Iterator
it
;
Sentinel
end
;
...
...
@@ -1139,10 +1139,10 @@ template <typename Iterator,
typename
ValueType
=
decltype
(
*
std
::
declval
<
Iterator
>()),
typename
...
Extra
>
iterator
make_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typedef
detail
::
iterator_state
<
Iterator
,
Sentinel
>
state
;
typedef
detail
::
iterator_state
<
Iterator
,
Sentinel
,
false
,
Extra
...
>
state
;
if
(
!
detail
::
get_type_info
(
typeid
(
state
)))
{
class_
<
state
>
(
handle
(),
""
)
class_
<
state
>
(
handle
(),
"
iterator
"
)
.
def
(
"__iter__"
,
[](
state
&
s
)
->
state
&
{
return
s
;
})
.
def
(
"__next__"
,
[](
state
&
s
)
->
ValueType
{
if
(
!
s
.
first
)
...
...
@@ -1157,15 +1157,16 @@ iterator make_iterator(Iterator first, Sentinel 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
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typedef
detail
::
iterator_state
<
Iterator
,
Sentinel
,
true
>
state
;
typedef
detail
::
iterator_state
<
Iterator
,
Sentinel
,
true
,
Extra
...
>
state
;
if
(
!
detail
::
get_type_info
(
typeid
(
state
)))
{
class_
<
state
>
(
handle
(),
""
)
class_
<
state
>
(
handle
(),
"
iterator
"
)
.
def
(
"__iter__"
,
[](
state
&
s
)
->
state
&
{
return
s
;
})
.
def
(
"__next__"
,
[](
state
&
s
)
->
KeyType
{
if
(
!
s
.
first
)
...
...
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