Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11_abseil
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_abseil
Commits
6fa281d7
Commit
6fa281d7
authored
Apr 15, 2021
by
Ken Oslund
Committed by
Copybara-Service
Apr 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Internal change
PiperOrigin-RevId: 368762888
parent
20c01c01
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
pybind11_abseil/absl_casters.h
+12
-0
pybind11_abseil/tests/absl_example.cc
+9
-0
pybind11_abseil/tests/absl_test.py
+1
-0
No files found.
pybind11_abseil/absl_casters.h
View file @
6fa281d7
...
...
@@ -269,6 +269,18 @@ struct type_caster<absl::Span<const T>> {
:
vector_converter_
(
std
::
move
(
other
.
vector_converter_
)),
value_
(
get_vector
())
{}
type_caster
&
operator
=
(
const
type_caster
<
absl
::
Span
<
const
T
>>&
other
)
{
vector_converter_
=
other
.
vector_converter_
;
value_
=
get_vector
();
return
*
this
;
}
type_caster
&
operator
=
(
type_caster
<
absl
::
Span
<
const
T
>>&&
other
)
{
vector_converter_
=
std
::
move
(
other
.
vector_converter_
);
value_
=
get_vector
();
return
*
this
;
}
static
constexpr
auto
name
=
_
(
"Span["
)
+
make_caster
<
T
>::
name
+
_
(
"]"
);
// We do not allow moving because 1) spans are super lightweight, so there's
...
...
pybind11_abseil/tests/absl_example.cc
View file @
6fa281d7
...
...
@@ -43,6 +43,13 @@ bool CheckSpan(absl::Span<const int> span, const std::vector<int>& values) {
return
true
;
}
bool
CheckSpanCasterCopy
(
const
handle
&
span
,
const
std
::
vector
<
int
>&
values
)
{
pybind11
::
detail
::
make_caster
<
absl
::
Span
<
const
int
>>
caster
;
caster
=
pybind11
::
detail
::
load_type
<
absl
::
Span
<
const
int
>>
(
span
);
return
CheckSpan
(
pybind11
::
detail
::
cast_op
<
absl
::
Span
<
const
int
>>
(
caster
),
values
);
}
absl
::
CivilSecond
MakeCivilSecond
(
double
secs
)
{
return
absl
::
ToCivilSecond
(
absl
::
FromUnixSeconds
(
static_cast
<
int64_t
>
(
secs
)),
absl
::
UTCTimeZone
());
...
...
@@ -246,6 +253,8 @@ PYBIND11_MODULE(absl_example, m) {
// absl::Span bindings.
m
.
def
(
"check_span"
,
&
CheckSpan
,
arg
(
"span"
),
arg
(
"values"
));
m
.
def
(
"check_span_caster_copy"
,
&
CheckSpanCasterCopy
,
arg
(
"span"
),
arg
(
"values"
));
class_
<
VectorContainer
>
(
m
,
"VectorContainer"
)
.
def
(
init
())
.
def
(
"make_span"
,
&
VectorContainer
::
MakeSpan
,
arg
(
"values"
));
...
...
pybind11_abseil/tests/absl_test.py
View file @
6fa281d7
...
...
@@ -227,6 +227,7 @@ class AbslSpanTest(parameterized.TestCase):
# Pass values twice- one will be converted to a span, the other to a vector
# (which is known to work), and then they will be compared.
self
.
assertTrue
(
absl_example
.
check_span
(
values
,
values
))
self
.
assertTrue
(
absl_example
.
check_span_caster_copy
(
values
,
values
))
def
test_span_with_pointers
(
self
):
objs
=
[
absl_example
.
ObjectForSpan
(
3
),
absl_example
.
ObjectForSpan
(
5
)]
...
...
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