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
82ba3300
Commit
82ba3300
authored
Feb 23, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stl.h: transparent conversion of STL linked lists
parent
a3861b54
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
include/pybind11/stl.h
+21
-8
No files found.
include/pybind11/stl.h
View file @
82ba3300
...
...
@@ -15,6 +15,7 @@
#include <map>
#include <unordered_map>
#include <iostream>
#include <list>
#if defined(_MSC_VER)
#pragma warning(push)
...
...
@@ -91,26 +92,31 @@ template <typename Type, typename Key, typename Value> struct map_caster {
PYBIND11_TYPE_CASTER
(
type
,
_
(
"dict<"
)
+
key_conv
::
name
()
+
_
(
", "
)
+
value_conv
::
name
()
+
_
(
">"
));
};
template
<
typename
Type
,
typename
Alloc
>
struct
type_caster
<
std
::
vector
<
Type
,
Alloc
>>
{
typedef
std
::
vector
<
Type
,
Alloc
>
vector_
type
;
typedef
type_caster
<
Typ
e
>
value_conv
;
template
<
typename
Type
,
typename
Value
>
struct
list_caster
{
typedef
Type
type
;
typedef
type_caster
<
Valu
e
>
value_conv
;
bool
load
(
handle
src
,
bool
convert
)
{
list
l
(
src
,
true
);
if
(
!
l
.
check
())
return
false
;
value
.
reserve
(
l
.
size
());
value
.
clear
();
value_conv
conv
;
value
.
clear
();
reserve_maybe
(
l
,
&
value
);
for
(
auto
it
:
l
)
{
if
(
!
conv
.
load
(
it
,
convert
))
return
false
;
value
.
push_back
((
Typ
e
)
conv
);
value
.
push_back
((
Valu
e
)
conv
);
}
return
true
;
}
static
handle
cast
(
const
vector_type
&
src
,
return_value_policy
policy
,
handle
parent
)
{
template
<
typename
T
=
Type
,
typename
std
::
enable_if
<
std
::
is_same
<
decltype
(
std
::
declval
<
T
>
().
reserve
(
0
)),
void
>::
value
,
int
>::
type
=
0
>
void
reserve_maybe
(
list
l
,
Type
*
)
{
value
.
reserve
(
l
.
size
());
}
void
reserve_maybe
(
list
,
void
*
)
{
}
static
handle
cast
(
const
Type
&
src
,
return_value_policy
policy
,
handle
parent
)
{
list
l
(
src
.
size
());
size_t
index
=
0
;
for
(
auto
const
&
value
:
src
)
{
...
...
@@ -121,9 +127,16 @@ template <typename Type, typename Alloc> struct type_caster<std::vector<Type, Al
}
return
l
.
release
();
}
PYBIND11_TYPE_CASTER
(
vector_type
,
_
(
"list<"
)
+
value_conv
::
name
()
+
_
(
">"
));
PYBIND11_TYPE_CASTER
(
Type
,
_
(
"list<"
)
+
value_conv
::
name
()
+
_
(
">"
));
};
template
<
typename
Type
,
typename
Alloc
>
struct
type_caster
<
std
::
vector
<
Type
,
Alloc
>>
:
list_caster
<
std
::
vector
<
Type
,
Alloc
>
,
Type
>
{
};
template
<
typename
Type
,
typename
Alloc
>
struct
type_caster
<
std
::
list
<
Type
,
Alloc
>>
:
list_caster
<
std
::
list
<
Type
,
Alloc
>
,
Type
>
{
};
template
<
typename
Type
,
size_t
Size
>
struct
type_caster
<
std
::
array
<
Type
,
Size
>>
{
typedef
std
::
array
<
Type
,
Size
>
array_type
;
typedef
type_caster
<
Type
>
value_conv
;
...
...
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