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
82ece940
Commit
82ece940
authored
Mar 29, 2017
by
Dean Moldovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace first_of_t with exactly_one_t
parent
1ac19036
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
20 deletions
+24
-20
include/pybind11/attr.h
+1
-1
include/pybind11/common.h
+20
-13
include/pybind11/pybind11.h
+3
-6
No files found.
include/pybind11/attr.h
View file @
82ece940
...
@@ -456,7 +456,7 @@ using is_call_guard = is_instantiation<call_guard, T>;
...
@@ -456,7 +456,7 @@ using is_call_guard = is_instantiation<call_guard, T>;
/// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found)
/// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found)
template
<
typename
...
Extra
>
template
<
typename
...
Extra
>
using
extract_guard_t
=
typename
first_of
_t
<
is_call_guard
,
call_guard
<>
,
Extra
...
>::
type
;
using
extract_guard_t
=
typename
exactly_one
_t
<
is_call_guard
,
call_guard
<>
,
Extra
...
>::
type
;
/// Check the number of named arguments at compile time
/// Check the number of named arguments at compile time
template
<
typename
...
Extra
,
template
<
typename
...
Extra
,
...
...
include/pybind11/common.h
View file @
82ece940
...
@@ -502,20 +502,27 @@ constexpr int constexpr_first() { return constexpr_impl::first(0, Predicate<Ts>:
...
@@ -502,20 +502,27 @@ constexpr int constexpr_first() { return constexpr_impl::first(0, Predicate<Ts>:
template
<
template
<
typename
>
class
Predicate
,
typename
...
Ts
>
template
<
template
<
typename
>
class
Predicate
,
typename
...
Ts
>
constexpr
int
constexpr_last
()
{
return
constexpr_impl
::
last
(
0
,
-
1
,
Predicate
<
Ts
>::
value
...);
}
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.
/// Return the Nth element from the parameter pack
template
<
template
<
class
>
class
Predicate
,
class
Default
,
class
...
Ts
>
struct
first_of
;
template
<
size_t
N
,
typename
T
,
typename
...
Ts
>
template
<
template
<
class
>
class
Predicate
,
class
Default
>
struct
first_of
<
Predicate
,
Default
>
{
struct
pack_element
{
using
type
=
typename
pack_element
<
N
-
1
,
Ts
...
>::
type
;
};
using
type
=
Default
;
template
<
typename
T
,
typename
...
Ts
>
};
struct
pack_element
<
0
,
T
,
Ts
...
>
{
using
type
=
T
;
};
template
<
template
<
class
>
class
Predicate
,
class
Default
,
class
T
,
class
...
Ts
>
struct
first_of
<
Predicate
,
Default
,
T
,
Ts
...
>
{
/// Return the one and only type which matches the predicate, or Default if none match.
using
type
=
typename
std
::
conditional
<
/// If more than one type matches the predicate, fail at compile-time.
Predicate
<
T
>::
value
,
template
<
template
<
typename
>
class
Predicate
,
typename
Default
,
typename
...
Ts
>
T
,
struct
exactly_one
{
typename
first_of
<
Predicate
,
Default
,
Ts
...
>::
type
static
constexpr
auto
found
=
constexpr_sum
(
Predicate
<
Ts
>::
value
...);
>::
type
;
static_assert
(
found
<=
1
,
"Found more than one type matching the predicate"
);
static
constexpr
auto
index
=
found
?
constexpr_first
<
Predicate
,
Ts
...
>
()
:
0
;
using
type
=
conditional_t
<
found
,
typename
pack_element
<
index
,
Ts
...
>::
type
,
Default
>
;
};
};
template
<
template
<
class
>
class
Predicate
,
class
Default
,
class
...
T
>
using
first_of_t
=
typename
first_of
<
Predicate
,
Default
,
T
...
>::
type
;
template
<
template
<
typename
>
class
P
,
typename
Default
>
struct
exactly_one
<
P
,
Default
>
{
using
type
=
Default
;
};
template
<
template
<
typename
>
class
Predicate
,
typename
Default
,
typename
...
Ts
>
using
exactly_one_t
=
typename
exactly_one
<
Predicate
,
Default
,
Ts
...
>::
type
;
/// Defer the evaluation of type T until types Us are instantiated
/// Defer the evaluation of type T until types Us are instantiated
template
<
typename
T
,
typename
...
/*Us*/
>
struct
deferred_type
{
using
type
=
T
;
};
template
<
typename
T
,
typename
...
/*Us*/
>
struct
deferred_type
{
using
type
=
T
;
};
...
...
include/pybind11/pybind11.h
View file @
82ece940
...
@@ -888,9 +888,9 @@ class class_ : public detail::generic_type {
...
@@ -888,9 +888,9 @@ class class_ : public detail::generic_type {
public
:
public
:
using
type
=
type_
;
using
type
=
type_
;
using
type_alias
=
detail
::
first_of
_t
<
is_subtype
,
void
,
options
...
>
;
using
type_alias
=
detail
::
exactly_one
_t
<
is_subtype
,
void
,
options
...
>
;
constexpr
static
bool
has_alias
=
!
std
::
is_void
<
type_alias
>::
value
;
constexpr
static
bool
has_alias
=
!
std
::
is_void
<
type_alias
>::
value
;
using
holder_type
=
detail
::
first_of
_t
<
is_holder
,
std
::
unique_ptr
<
type
>
,
options
...
>
;
using
holder_type
=
detail
::
exactly_one
_t
<
is_holder
,
std
::
unique_ptr
<
type
>
,
options
...
>
;
using
instance_type
=
detail
::
instance
<
type
,
holder_type
>
;
using
instance_type
=
detail
::
instance
<
type
,
holder_type
>
;
static_assert
(
detail
::
all_of
<
is_valid_class_option
<
options
>
...
>::
value
,
static_assert
(
detail
::
all_of
<
is_valid_class_option
<
options
>
...
>::
value
,
...
@@ -1158,15 +1158,12 @@ public:
...
@@ -1158,15 +1158,12 @@ public:
using
class_
<
Type
>::
def
;
using
class_
<
Type
>::
def
;
using
class_
<
Type
>::
def_property_readonly_static
;
using
class_
<
Type
>::
def_property_readonly_static
;
using
Scalar
=
typename
std
::
underlying_type
<
Type
>::
type
;
using
Scalar
=
typename
std
::
underlying_type
<
Type
>::
type
;
template
<
typename
T
>
using
arithmetic_tag
=
std
::
is_same
<
T
,
arithmetic
>
;
template
<
typename
...
Extra
>
template
<
typename
...
Extra
>
enum_
(
const
handle
&
scope
,
const
char
*
name
,
const
Extra
&
...
extra
)
enum_
(
const
handle
&
scope
,
const
char
*
name
,
const
Extra
&
...
extra
)
:
class_
<
Type
>
(
scope
,
name
,
extra
...),
m_entries
(),
m_parent
(
scope
)
{
:
class_
<
Type
>
(
scope
,
name
,
extra
...),
m_entries
(),
m_parent
(
scope
)
{
constexpr
bool
is_arithmetic
=
constexpr
bool
is_arithmetic
=
detail
::
any_of
<
std
::
is_same
<
arithmetic
,
Extra
>
...
>::
value
;
!
std
::
is_same
<
detail
::
first_of_t
<
arithmetic_tag
,
void
,
Extra
...
>
,
void
>::
value
;
auto
m_entries_ptr
=
m_entries
.
inc_ref
().
ptr
();
auto
m_entries_ptr
=
m_entries
.
inc_ref
().
ptr
();
def
(
"__repr__"
,
[
name
,
m_entries_ptr
](
Type
value
)
->
pybind11
::
str
{
def
(
"__repr__"
,
[
name
,
m_entries_ptr
](
Type
value
)
->
pybind11
::
str
{
...
...
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