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
70ed2a48
"git@developer.sourcefind.cn:gaoqiong/pybind11.git" did not exist on "9fb50c56d02eae0b345a7964aacb0b4f16c23a54"
Commit
70ed2a48
authored
Jan 22, 2017
by
Jason Rhinelander
Committed by
Wenzel Jakob
Jan 31, 2017
Browse files
Use constexpr_first for args/kwargs positional checks
parent
34d308ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
19 deletions
+11
-19
include/pybind11/cast.h
include/pybind11/cast.h
+11
-19
No files found.
include/pybind11/cast.h
View file @
70ed2a48
...
...
@@ -1248,22 +1248,6 @@ NAMESPACE_BEGIN(detail)
// forward declaration
struct
function_record
;
// Helper struct to only allow py::args and/or py::kwargs at the end of the function arguments
template
<
bool
args
,
bool
kwargs
,
bool
args_kwargs_are_last
>
struct
assert_args_kwargs_must_be_last
{
static
constexpr
bool
has_args
=
args
,
has_kwargs
=
kwargs
;
static_assert
(
args_kwargs_are_last
,
"py::args/py::kwargs are only permitted as the last argument(s) of a function"
);
};
template
<
typename
...
T
>
struct
args_kwargs_must_be_last
;
template
<
typename
T1
,
typename
...
Tmore
>
struct
args_kwargs_must_be_last
<
T1
,
Tmore
...
>
:
args_kwargs_must_be_last
<
Tmore
...
>
{};
template
<
typename
...
T
>
struct
args_kwargs_must_be_last
<
args
,
T
...
>
:
assert_args_kwargs_must_be_last
<
true
,
false
,
sizeof
...(
T
)
==
0
>
{};
template
<
typename
...
T
>
struct
args_kwargs_must_be_last
<
kwargs
,
T
...
>
:
assert_args_kwargs_must_be_last
<
false
,
true
,
sizeof
...(
T
)
==
0
>
{};
template
<
typename
...
T
>
struct
args_kwargs_must_be_last
<
args
,
kwargs
,
T
...
>
:
assert_args_kwargs_must_be_last
<
true
,
true
,
sizeof
...(
T
)
==
0
>
{};
template
<
>
struct
args_kwargs_must_be_last
<>
:
assert_args_kwargs_must_be_last
<
false
,
false
,
true
>
{};
using
function_arguments
=
const
std
::
vector
<
handle
>
&
;
/// Helper class which loads arguments for C++ functions called from Python
...
...
@@ -1271,11 +1255,19 @@ template <typename... Args>
class
argument_loader
{
using
indices
=
make_index_sequence
<
sizeof
...(
Args
)
>
;
using
check_args_kwargs
=
args_kwargs_must_be_last
<
intrinsic_t
<
Args
>
...
>
;
template
<
typename
Arg
>
using
argument_is_args
=
std
::
is_same
<
intrinsic_t
<
Arg
>
,
args
>
;
template
<
typename
Arg
>
using
argument_is_kwargs
=
std
::
is_same
<
intrinsic_t
<
Arg
>
,
kwargs
>
;
// Get args/kwargs argument positions relative to the end of the argument list:
static
constexpr
auto
args_pos
=
constexpr_first
<
argument_is_args
,
Args
...
>
()
-
(
int
)
sizeof
...(
Args
),
kwargs_pos
=
constexpr_first
<
argument_is_kwargs
,
Args
...
>
()
-
(
int
)
sizeof
...(
Args
);
static
constexpr
bool
args_kwargs_are_last
=
kwargs_pos
>=
-
1
&&
args_pos
>=
kwargs_pos
-
1
;
static_assert
(
args_kwargs_are_last
,
"py::args/py::kwargs are only permitted as the last argument(s) of a function"
);
public:
static
constexpr
bool
has_kwargs
=
check_args_kwargs
::
has_kwargs
;
static
constexpr
bool
has_args
=
check_args_kwargs
::
has_args
;
static
constexpr
bool
has_kwargs
=
kwargs_pos
<
0
;
static
constexpr
bool
has_args
=
args_pos
<
0
;
static
PYBIND11_DESCR
arg_names
()
{
return
detail
::
concat
(
make_caster
<
Args
>::
name
()...);
}
...
...
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