Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
eigenpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
eigenpy
Commits
0afe3c9c
Commit
0afe3c9c
authored
1 year ago
by
Wilson Jallet
Browse files
Options
Downloads
Patches
Plain Diff
optional: add support for std::optional under cpp17
parent
3666ff02
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/eigenpy/optional.hpp
+31
-2
31 additions, 2 deletions
include/eigenpy/optional.hpp
with
31 additions
and
2 deletions
include/eigenpy/optional.hpp
+
31
−
2
View file @
0afe3c9c
...
...
@@ -8,17 +8,28 @@
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/eigen-from-python.hpp"
#include
<boost/optional.hpp>
#ifdef EIGENPY_WITH_CXX17_SUPPORT
#include
<optional>
#endif
#ifndef EIGENPY_DEFAULT_OPTIONAL
#define EIGENPY_DEFAULT_OPTIONAL boost::optional
#endif
namespace
boost
{
namespace
python
{
namespace
converter
{
template
<
typename
T
>
struct
expected_pytype_for_arg
<
EIGENPY_DEFAULT_OPTIONAL
<
T
>
>
struct
expected_pytype_for_arg
<
boost
::
optional
<
T
>
>
:
expected_pytype_for_arg
<
T
>
{};
#ifdef EIGENPY_WITH_CXX17_SUPPORT
template
<
typename
T
>
struct
expected_pytype_for_arg
<
std
::
optional
<
T
>
>
:
expected_pytype_for_arg
<
T
>
{};
#endif
}
// namespace converter
}
// namespace python
}
// namespace boost
...
...
@@ -26,6 +37,24 @@ struct expected_pytype_for_arg<EIGENPY_DEFAULT_OPTIONAL<T> >
namespace
eigenpy
{
namespace
detail
{
/// Helper struct to decide which type is the "none" type for a specific optional<T> implementation.
template
<
template
<
typename
>
class
OptionalTpl
>
struct
nullopt_helper
{};
template
<
>
struct
nullopt_helper
<
boost
::
optional
>
{
typedef
boost
::
none_t
type
;
static
type
value
()
{
return
boost
::
none
;
}
};
#ifdef EIGENPY_WITH_CXX17_SUPPORT
template
<
>
struct
nullopt_helper
<
std
::
optional
>
{
typedef
std
::
nullopt_t
type
;
static
type
value
()
{
return
std
::
nullopt
;
}
};
#endif
template
<
typename
T
,
template
<
typename
>
class
OptionalTpl
=
EIGENPY_DEFAULT_OPTIONAL
>
struct
OptionalToPython
{
...
...
@@ -80,7 +109,7 @@ void OptionalFromPython<T, OptionalTpl>::construct(
->
storage
.
bytes
;
if
(
obj_ptr
==
Py_None
)
{
new
(
storage
)
OptionalTpl
<
T
>
(
boost
::
none
);
new
(
storage
)
OptionalTpl
<
T
>
(
nullopt_helper
<
OptionalTpl
>::
value
()
);
}
else
{
const
T
value
=
bp
::
extract
<
T
>
(
obj_ptr
);
new
(
storage
)
OptionalTpl
<
T
>
(
value
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment