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
34d308ad
Commit
34d308ad
authored
Jan 22, 2017
by
Jason Rhinelander
Committed by
Wenzel Jakob
Jan 31, 2017
Browse files
Move constexpr_first/last to common.h
This keeps it with constexpr_sum and the other metafunctions.
parent
3b4b9211
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
include/pybind11/cast.h
include/pybind11/cast.h
+0
-19
include/pybind11/common.h
include/pybind11/common.h
+20
-0
No files found.
include/pybind11/cast.h
View file @
34d308ad
...
...
@@ -1314,25 +1314,6 @@ private:
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.
/// A fancier version below can collect any argument, but this one is optimal for simple calls.
template
<
return_value_policy
policy
>
...
...
include/pybind11/common.h
View file @
34d308ad
...
...
@@ -449,6 +449,26 @@ constexpr size_t constexpr_sum() { return 0; }
template
<
typename
T
,
typename
...
Ts
>
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.
template
<
template
<
class
>
class
Predicate
,
class
Default
,
class
...
Ts
>
struct
first_of
;
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