Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
144546e1
Commit
144546e1
authored
Dec 17, 2021
by
Evgeny Yakimov
Committed by
GitHub
Dec 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add std::optional declarations for C++17 (GH-3294)
Closes
https://github.com/cython/cython/issues/3293
parent
4da6a663
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
+106
-0
Cython/Includes/libcpp/optional.pxd
Cython/Includes/libcpp/optional.pxd
+34
-0
tests/run/cpp_stl_optional.pyx
tests/run/cpp_stl_optional.pyx
+72
-0
No files found.
Cython/Includes/libcpp/optional.pxd
0 → 100644
View file @
144546e1
from
libcpp
cimport
bool
cdef
extern
from
"<optional>"
namespace
"std"
nogil
:
cdef
cppclass
nullopt_t
:
nullopt_t
()
cdef
nullopt_t
nullopt
cdef
cppclass
optional
[
T
]:
ctypedef
T
value_type
optional
()
optional
(
nullopt_t
)
optional
(
optional
&
)
except
+
optional
(
T
&
)
except
+
bool
has_value
()
T
&
value
()
T
&
value_or
[
U
](
U
&
default_value
)
void
swap
(
optional
&
)
void
reset
()
T
&
emplace
(...)
T
&
operator
*
()
#T* operator->() # Not Supported
optional
&
operator
=
(
optional
&
)
optional
&
operator
=
[
U
](
U
&
)
bool
operator
bool
()
bool
operator
!
()
bool
operator
==
[
U
](
optional
&
,
U
&
)
bool
operator
!=
[
U
](
optional
&
,
U
&
)
bool
operator
<
[
U
](
optional
&
,
U
&
)
bool
operator
>
[
U
](
optional
&
,
U
&
)
bool
operator
<=
[
U
](
optional
&
,
U
&
)
bool
operator
>=
[
U
](
optional
&
,
U
&
)
optional
[
T
]
make_optional
[
T
](...)
except
+
tests/run/cpp_stl_optional.pyx
0 → 100644
View file @
144546e1
# ticket: 3293
# mode: run
# tag: cpp, cpp17, werror
from
cython.operator
cimport
dereference
as
deref
from
libcpp.optional
cimport
optional
,
nullopt
,
make_optional
from
libcpp.string
cimport
string
from
libcpp.pair
cimport
pair
def
simple_test
():
"""
>>> simple_test()
"""
cdef
optional
[
int
]
o
assert
(
not
o
.
has_value
())
o
=
5
assert
(
o
.
has_value
())
assert
(
o
.
value
()
==
5
)
o
.
reset
()
assert
(
not
o
.
has_value
())
def
operator_test
():
"""
>>> operator_test()
"""
cdef
optional
[
int
]
o1
,
o2
# operator bool
assert
(
not
o1
)
o1
=
5
assert
(
o1
)
# operator *
assert
(
deref
(
o1
)
==
5
)
# operator =,==,!=,>,<,>=,<=
assert
(
not
o1
==
o2
)
assert
(
o1
!=
o2
)
o2
=
o1
assert
(
o1
==
o2
)
assert
(
not
o1
>
o2
)
assert
(
not
o1
<
o2
)
assert
(
o1
>=
o2
)
assert
(
o1
<=
o2
)
# operators =,== for other types (all related operators are identical)
o1
=
6
assert
(
o1
==
6
)
o2
=
nullopt
assert
(
o2
==
nullopt
)
def
misc_methods_test
():
"""
>>> misc_methods_test()
"""
# make_optional
cdef
optional
[
int
]
o
o
=
make_optional
[
int
](
5
)
assert
(
o
==
5
)
# swap
o
.
swap
(
optional
[
int
](
6
))
assert
(
o
==
6
)
# emplace
cdef
optional
[
pair
[
int
,
int
]]
op
cdef
pair
[
int
,
int
]
*
val_ptr
=
&
op
.
emplace
(
1
,
2
)
assert
(
op
.
has_value
())
assert
(
op
.
value
()
==
pair
[
int
,
int
](
1
,
2
))
assert
(
&
op
.
value
()
==
val_ptr
)
# check returned reference
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