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
74439a64
Unverified
Commit
74439a64
authored
Oct 18, 2023
by
Sergei Izmailov
Committed by
GitHub
Oct 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature: Use typed iterators in `make_*iterator` (#4876)
parent
0cbd92ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
include/pybind11/pybind11.h
+13
-6
tests/test_sequences_and_iterators.py
+9
-0
No files found.
include/pybind11/pybind11.h
View file @
74439a64
...
...
@@ -15,6 +15,7 @@
#include "attr.h"
#include "gil.h"
#include "options.h"
#include "typing.h"
#include <cstdlib>
#include <cstring>
...
...
@@ -2447,7 +2448,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
typename
Sentinel
,
typename
ValueType
=
typename
detail
::
iterator_access
<
Iterator
>::
result_type
,
typename
...
Extra
>
iterator
make_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typing
::
Iterator
<
ValueType
>
make_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
return
detail
::
make_iterator_impl
<
detail
::
iterator_access
<
Iterator
>
,
Policy
,
Iterator
,
...
...
@@ -2465,7 +2466,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
typename
Sentinel
,
typename
KeyType
=
typename
detail
::
iterator_key_access
<
Iterator
>::
result_type
,
typename
...
Extra
>
iterator
make_key_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typing
::
Iterator
<
KeyType
>
make_key_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
return
detail
::
make_iterator_impl
<
detail
::
iterator_key_access
<
Iterator
>
,
Policy
,
Iterator
,
...
...
@@ -2483,7 +2484,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
typename
Sentinel
,
typename
ValueType
=
typename
detail
::
iterator_value_access
<
Iterator
>::
result_type
,
typename
...
Extra
>
iterator
make_value_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
typing
::
Iterator
<
ValueType
>
make_value_iterator
(
Iterator
first
,
Sentinel
last
,
Extra
&&
...
extra
)
{
return
detail
::
make_iterator_impl
<
detail
::
iterator_value_access
<
Iterator
>
,
Policy
,
Iterator
,
...
...
@@ -2498,8 +2499,10 @@ iterator make_value_iterator(Iterator first, Sentinel last, Extra &&...extra) {
/// `std::begin()`/`std::end()`
template
<
return_value_policy
Policy
=
return_value_policy
::
reference_internal
,
typename
Type
,
typename
ValueType
=
typename
detail
::
iterator_access
<
decltype
(
std
::
begin
(
std
::
declval
<
Type
&>
()))
>::
result_type
,
typename
...
Extra
>
iterator
make_iterator
(
Type
&
value
,
Extra
&&
...
extra
)
{
typing
::
Iterator
<
ValueType
>
make_iterator
(
Type
&
value
,
Extra
&&
...
extra
)
{
return
make_iterator
<
Policy
>
(
std
::
begin
(
value
),
std
::
end
(
value
),
std
::
forward
<
Extra
>
(
extra
)...);
}
...
...
@@ -2508,8 +2511,10 @@ iterator make_iterator(Type &value, Extra &&...extra) {
/// `std::begin()`/`std::end()`
template
<
return_value_policy
Policy
=
return_value_policy
::
reference_internal
,
typename
Type
,
typename
KeyType
=
typename
detail
::
iterator_key_access
<
decltype
(
std
::
begin
(
std
::
declval
<
Type
&>
()))
>::
result_type
,
typename
...
Extra
>
iterator
make_key_iterator
(
Type
&
value
,
Extra
&&
...
extra
)
{
typing
::
Iterator
<
KeyType
>
make_key_iterator
(
Type
&
value
,
Extra
&&
...
extra
)
{
return
make_key_iterator
<
Policy
>
(
std
::
begin
(
value
),
std
::
end
(
value
),
std
::
forward
<
Extra
>
(
extra
)...);
}
...
...
@@ -2518,8 +2523,10 @@ iterator make_key_iterator(Type &value, Extra &&...extra) {
/// `std::begin()`/`std::end()`
template
<
return_value_policy
Policy
=
return_value_policy
::
reference_internal
,
typename
Type
,
typename
ValueType
=
typename
detail
::
iterator_value_access
<
decltype
(
std
::
begin
(
std
::
declval
<
Type
&>
()))
>::
result_type
,
typename
...
Extra
>
iterator
make_value_iterator
(
Type
&
value
,
Extra
&&
...
extra
)
{
typing
::
Iterator
<
ValueType
>
make_value_iterator
(
Type
&
value
,
Extra
&&
...
extra
)
{
return
make_value_iterator
<
Policy
>
(
std
::
begin
(
value
),
std
::
end
(
value
),
std
::
forward
<
Extra
>
(
extra
)...);
}
...
...
tests/test_sequences_and_iterators.py
View file @
74439a64
...
...
@@ -58,6 +58,15 @@ def test_generalized_iterators_simple():
assert
list
(
m
.
IntPairs
([(
1
,
2
),
(
3
,
4
),
(
0
,
5
)])
.
simple_values
())
==
[
2
,
4
,
5
]
def
test_iterator_doc_annotations
():
assert
m
.
IntPairs
.
nonref
.
__doc__
.
endswith
(
"-> Iterator[tuple[int, int]]
\n
"
)
assert
m
.
IntPairs
.
nonref_keys
.
__doc__
.
endswith
(
"-> Iterator[int]
\n
"
)
assert
m
.
IntPairs
.
nonref_values
.
__doc__
.
endswith
(
"-> Iterator[int]
\n
"
)
assert
m
.
IntPairs
.
simple_iterator
.
__doc__
.
endswith
(
"-> Iterator[tuple[int, int]]
\n
"
)
assert
m
.
IntPairs
.
simple_keys
.
__doc__
.
endswith
(
"-> Iterator[int]
\n
"
)
assert
m
.
IntPairs
.
simple_values
.
__doc__
.
endswith
(
"-> Iterator[int]
\n
"
)
def
test_iterator_referencing
():
"""Test that iterators reference rather than copy their referents."""
vec
=
m
.
VectorNonCopyableInt
()
...
...
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