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
34d308ad
Commit
34d308ad
authored
Jan 22, 2017
by
Jason Rhinelander
Committed by
Wenzel Jakob
Jan 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move constexpr_first/last to common.h
This keeps it with constexpr_sum and the other metafunctions.
parent
3b4b9211
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
include/pybind11/cast.h
+0
-19
include/pybind11/common.h
+20
-0
No files found.
include/pybind11/cast.h
View file @
34d308ad
...
@@ -1314,25 +1314,6 @@ private:
...
@@ -1314,25 +1314,6 @@ private:
std
::
tuple
<
make_caster
<
Args
>
...
>
value
;
std
::
tuple
<
make_caster
<
Args
>
...
>
value
;
};
};
NAMESPACE_BEGIN
(
constexpr_impl
)
/// Implementation details for constexpr functions
constexpr
int
first
(
int
i
)
{
return
i
;
}
template
<
typename
T
,
typename
...
Ts
>
constexpr
int
first
(
int
i
,
T
v
,
Ts
...
vs
)
{
return
v
?
i
:
first
(
i
+
1
,
vs
...);
}
constexpr
int
last
(
int
/*i*/
,
int
result
)
{
return
result
;
}
template
<
typename
T
,
typename
...
Ts
>
constexpr
int
last
(
int
i
,
int
result
,
T
v
,
Ts
...
vs
)
{
return
last
(
i
+
1
,
v
?
i
:
result
,
vs
...);
}
NAMESPACE_END
(
constexpr_impl
)
/// Return the index of the first type in Ts which satisfies Predicate<T>
template
<
template
<
typename
>
class
Predicate
,
typename
...
Ts
>
constexpr
int
constexpr_first
()
{
return
constexpr_impl
::
first
(
0
,
Predicate
<
Ts
>::
value
...);
}
/// Return the index of the last type in Ts which satisfies Predicate<T>
template
<
template
<
typename
>
class
Predicate
,
typename
...
Ts
>
constexpr
int
constexpr_last
()
{
return
constexpr_impl
::
last
(
0
,
-
1
,
Predicate
<
Ts
>::
value
...);
}
/// Helper class which collects only positional arguments for a Python function call.
/// Helper class which collects only positional arguments for a Python function call.
/// A fancier version below can collect any argument, but this one is optimal for simple calls.
/// A fancier version below can collect any argument, but this one is optimal for simple calls.
template
<
return_value_policy
policy
>
template
<
return_value_policy
policy
>
...
...
include/pybind11/common.h
View file @
34d308ad
...
@@ -449,6 +449,26 @@ constexpr size_t constexpr_sum() { return 0; }
...
@@ -449,6 +449,26 @@ constexpr size_t constexpr_sum() { return 0; }
template
<
typename
T
,
typename
...
Ts
>
template
<
typename
T
,
typename
...
Ts
>
constexpr
size_t
constexpr_sum
(
T
n
,
Ts
...
ns
)
{
return
size_t
{
n
}
+
constexpr_sum
(
ns
...);
}
constexpr
size_t
constexpr_sum
(
T
n
,
Ts
...
ns
)
{
return
size_t
{
n
}
+
constexpr_sum
(
ns
...);
}
NAMESPACE_BEGIN
(
constexpr_impl
)
/// Implementation details for constexpr functions
constexpr
int
first
(
int
i
)
{
return
i
;
}
template
<
typename
T
,
typename
...
Ts
>
constexpr
int
first
(
int
i
,
T
v
,
Ts
...
vs
)
{
return
v
?
i
:
first
(
i
+
1
,
vs
...);
}
constexpr
int
last
(
int
/*i*/
,
int
result
)
{
return
result
;
}
template
<
typename
T
,
typename
...
Ts
>
constexpr
int
last
(
int
i
,
int
result
,
T
v
,
Ts
...
vs
)
{
return
last
(
i
+
1
,
v
?
i
:
result
,
vs
...);
}
NAMESPACE_END
(
constexpr_impl
)
/// Return the index of the first type in Ts which satisfies Predicate<T>. Returns sizeof...(Ts) if
/// none match.
template
<
template
<
typename
>
class
Predicate
,
typename
...
Ts
>
constexpr
int
constexpr_first
()
{
return
constexpr_impl
::
first
(
0
,
Predicate
<
Ts
>::
value
...);
}
/// Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
template
<
template
<
typename
>
class
Predicate
,
typename
...
Ts
>
constexpr
int
constexpr_last
()
{
return
constexpr_impl
::
last
(
0
,
-
1
,
Predicate
<
Ts
>::
value
...);
}
// Extracts the first type from the template parameter pack matching the predicate, or Default if none match.
// Extracts the first type from the template parameter pack matching the predicate, or Default if none match.
template
<
template
<
class
>
class
Predicate
,
class
Default
,
class
...
Ts
>
struct
first_of
;
template
<
template
<
class
>
class
Predicate
,
class
Default
,
class
...
Ts
>
struct
first_of
;
template
<
template
<
class
>
class
Predicate
,
class
Default
>
struct
first_of
<
Predicate
,
Default
>
{
template
<
template
<
class
>
class
Predicate
,
class
Default
>
struct
first_of
<
Predicate
,
Default
>
{
...
...
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