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
82ba3300
Commit
82ba3300
authored
Feb 23, 2016
by
Wenzel Jakob
Browse files
stl.h: transparent conversion of STL linked lists
parent
a3861b54
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
include/pybind11/stl.h
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