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
048373c1
Commit
048373c1
authored
Mar 26, 2016
by
Wenzel Jakob
Browse files
explicitly route type casting operations to desired casting operator (fixes #147)
parent
0b489588
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
include/pybind11/cast.h
include/pybind11/cast.h
+13
-2
include/pybind11/common.h
include/pybind11/common.h
+5
-0
No files found.
include/pybind11/cast.h
View file @
048373c1
...
@@ -504,12 +504,23 @@ public:
...
@@ -504,12 +504,23 @@ public:
}
}
protected:
protected:
template
<
typename
T
>
/* Used to select the right casting operator in the two functions below */
using
cast_target
=
typename
std
::
conditional
<
is_tuple
<
typename
intrinsic_type
<
T
>::
type
>::
value
,
/* special case: tuple/pair -> pass by value */
typename
intrinsic_type
<
T
>::
type
,
typename
std
::
conditional
<
std
::
is_pointer
<
T
>::
value
,
typename
std
::
add_pointer
<
typename
intrinsic_type
<
T
>::
type
>::
type
,
/* pass using pointer */
typename
std
::
add_lvalue_reference
<
typename
intrinsic_type
<
T
>::
type
>::
type
/* pass using reference */
>::
type
>
;
template
<
typename
ReturnValue
,
typename
Func
,
size_t
...
Index
>
ReturnValue
call
(
Func
&&
f
,
index_sequence
<
Index
...
>
)
{
template
<
typename
ReturnValue
,
typename
Func
,
size_t
...
Index
>
ReturnValue
call
(
Func
&&
f
,
index_sequence
<
Index
...
>
)
{
return
f
(
(
Tuple
)
std
::
get
<
Index
>
(
value
)...);
return
f
(
std
::
get
<
Index
>
(
value
).
operator
typename
cast_target
<
Tuple
>::
type
().
..);
}
}
template
<
size_t
...
Index
>
type
cast
(
index_sequence
<
Index
...
>
)
{
template
<
size_t
...
Index
>
type
cast
(
index_sequence
<
Index
...
>
)
{
return
type
(
(
Tuple
)
std
::
get
<
Index
>
(
value
)...);
return
type
(
std
::
get
<
Index
>
(
value
).
operator
typename
cast_target
<
Tuple
>::
type
().
..);
}
}
template
<
size_t
...
Indices
>
bool
load
(
handle
src
,
bool
convert
,
index_sequence
<
Indices
...
>
)
{
template
<
size_t
...
Indices
>
bool
load
(
handle
src
,
bool
convert
,
index_sequence
<
Indices
...
>
)
{
...
...
include/pybind11/common.h
View file @
048373c1
...
@@ -257,6 +257,11 @@ template <typename T> struct is_copy_constructible {
...
@@ -257,6 +257,11 @@ template <typename T> struct is_copy_constructible {
static
const
bool
value
=
std
::
is_same
<
std
::
true_type
,
decltype
(
test
<
T
>
(
nullptr
))
>::
value
;
static
const
bool
value
=
std
::
is_same
<
std
::
true_type
,
decltype
(
test
<
T
>
(
nullptr
))
>::
value
;
};
};
/// Helper type determine if another type is a variant of a pair/tuple
template
<
typename
T
>
struct
is_tuple
:
std
::
false_type
{
};
template
<
typename
...
Args
>
struct
is_tuple
<
std
::
tuple
<
Args
...
>>
:
std
::
true_type
{
};
template
<
typename
...
Args
>
struct
is_tuple
<
std
::
pair
<
Args
...
>>
:
std
::
true_type
{
};
/// Helper type to replace 'void' in some expressions
/// Helper type to replace 'void' in some expressions
struct
void_type
{
};
struct
void_type
{
};
...
...
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