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
70ed2a48
Commit
70ed2a48
authored
Jan 22, 2017
by
Jason Rhinelander
Committed by
Wenzel Jakob
Jan 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use constexpr_first for args/kwargs positional checks
parent
34d308ad
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
19 deletions
+11
-19
include/pybind11/cast.h
+11
-19
No files found.
include/pybind11/cast.h
View file @
70ed2a48
...
@@ -1248,22 +1248,6 @@ NAMESPACE_BEGIN(detail)
...
@@ -1248,22 +1248,6 @@ NAMESPACE_BEGIN(detail)
// forward declaration
// forward declaration
struct
function_record
;
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
>
&
;
using
function_arguments
=
const
std
::
vector
<
handle
>
&
;
/// Helper class which loads arguments for C++ functions called from Python
/// Helper class which loads arguments for C++ functions called from Python
...
@@ -1271,11 +1255,19 @@ template <typename... Args>
...
@@ -1271,11 +1255,19 @@ template <typename... Args>
class
argument_loader
{
class
argument_loader
{
using
indices
=
make_index_sequence
<
sizeof
...(
Args
)
>
;
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
:
public
:
static
constexpr
bool
has_kwargs
=
check_args_kwargs
::
has_kwargs
;
static
constexpr
bool
has_kwargs
=
kwargs_pos
<
0
;
static
constexpr
bool
has_args
=
check_args_kwargs
::
has_args
;
static
constexpr
bool
has_args
=
args_pos
<
0
;
static
PYBIND11_DESCR
arg_names
()
{
return
detail
::
concat
(
make_caster
<
Args
>::
name
()...);
}
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