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
ab4677ad
Unverified
Commit
ab4677ad
authored
1 year ago
by
Joris Vaillant
Browse files
Options
Downloads
Patches
Plain Diff
core: Fix build issue with std::variant
parent
bfb0c322
No related branches found
Branches containing commit
No related tags found
Loading
Pipeline
#35868
passed with warnings
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/eigenpy/variant.hpp
+26
-10
26 additions, 10 deletions
include/eigenpy/variant.hpp
with
26 additions
and
10 deletions
include/eigenpy/variant.hpp
+
26
−
10
View file @
ab4677ad
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include
<boost/python.hpp>
#include
<boost/python.hpp>
#include
<boost/variant.hpp>
#include
<boost/variant.hpp>
#include
<boost/mpl/for_each.hpp>
#include
<boost/mpl/for_each.hpp>
#include
<boost/mpl/vector.hpp>
#ifdef EIGENPY_WITH_CXX17_SUPPORT
#ifdef EIGENPY_WITH_CXX17_SUPPORT
#include
<variant>
#include
<variant>
...
@@ -23,6 +24,10 @@ namespace details {
...
@@ -23,6 +24,10 @@ namespace details {
template
<
typename
ResultType
,
typename
Variant
>
template
<
typename
ResultType
,
typename
Variant
>
struct
VariantVisitorType
{};
struct
VariantVisitorType
{};
/// Allow to get all alternatives in a boost::mpl vector
template
<
typename
Variant
>
struct
VariantAlternatives
{};
#ifdef EIGENPY_WITH_CXX17_SUPPORT
#ifdef EIGENPY_WITH_CXX17_SUPPORT
/// std::variant implementation
/// std::variant implementation
...
@@ -31,13 +36,18 @@ struct VariantVisitorType<ResultType, std::variant<Alternatives...> > {
...
@@ -31,13 +36,18 @@ struct VariantVisitorType<ResultType, std::variant<Alternatives...> > {
typedef
std
::
variant
<
Alternatives
...
>
variant_type
;
typedef
std
::
variant
<
Alternatives
...
>
variant_type
;
typedef
ResultType
result_type
;
typedef
ResultType
result_type
;
template
<
typename
Visitor
>
template
<
typename
Visitor
,
typename
Visitable
>
static
result_type
visit
(
Visitor
&&
visitor
,
Alternatives
&&
...
alternatives
)
{
static
result_type
visit
(
Visitor
&&
visitor
,
Visitable
&&
v
)
{
return
std
::
visit
(
std
::
forward
<
Visitor
>
(
visitor
),
return
std
::
visit
(
std
::
forward
<
Visitor
>
(
visitor
),
std
::
forward
<
Alternatives
>
(
alternatives
)...
);
std
::
forward
<
Visitable
>
(
v
)
);
}
}
};
};
template
<
typename
...
Alternatives
>
struct
VariantAlternatives
<
std
::
variant
<
Alternatives
...
>>
{
typedef
boost
::
mpl
::
vector
<
Alternatives
...
>
types
;
};
#endif
#endif
/// boost::variant implementation
/// boost::variant implementation
...
@@ -53,6 +63,11 @@ struct VariantVisitorType<ResultType, boost::variant<Alternatives...> >
...
@@ -53,6 +63,11 @@ struct VariantVisitorType<ResultType, boost::variant<Alternatives...> >
}
}
};
};
template
<
typename
...
Alternatives
>
struct
VariantAlternatives
<
boost
::
variant
<
Alternatives
...
>>
{
typedef
typename
boost
::
variant
<
Alternatives
...
>::
types
types
;
};
/// Convert {boost,std}::variant<class...> alternative to a Python object.
/// Convert {boost,std}::variant<class...> alternative to a Python object.
/// This converter copy the alternative.
/// This converter copy the alternative.
template
<
typename
Variant
>
template
<
typename
Variant
>
...
@@ -61,8 +76,8 @@ struct VariantValueToObject : VariantVisitorType<PyObject*, Variant> {
...
@@ -61,8 +76,8 @@ struct VariantValueToObject : VariantVisitorType<PyObject*, Variant> {
typedef
typename
Base
::
result_type
result_type
;
typedef
typename
Base
::
result_type
result_type
;
typedef
typename
Base
::
variant_type
variant_type
;
typedef
typename
Base
::
variant_type
variant_type
;
static
result_type
convert
(
const
variant_type
&
gm
)
{
static
result_type
convert
(
const
variant_type
&
v
)
{
return
Base
::
visit
(
VariantValueToObject
(),
gm
);
return
Base
::
visit
(
VariantValueToObject
(),
v
);
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -81,8 +96,8 @@ struct VariantRefToObject : VariantVisitorType<PyObject*, Variant> {
...
@@ -81,8 +96,8 @@ struct VariantRefToObject : VariantVisitorType<PyObject*, Variant> {
typedef
typename
Base
::
result_type
result_type
;
typedef
typename
Base
::
result_type
result_type
;
typedef
typename
Base
::
variant_type
variant_type
;
typedef
typename
Base
::
variant_type
variant_type
;
static
result_type
convert
(
const
variant_type
&
gm
)
{
static
result_type
convert
(
const
variant_type
&
v
)
{
return
Base
::
visit
(
VariantRefToObject
(),
gm
);
return
Base
::
visit
(
VariantRefToObject
(),
v
);
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -102,8 +117,8 @@ struct VariantConverter {
...
@@ -102,8 +117,8 @@ struct VariantConverter {
template
<
class
T
>
template
<
class
T
>
struct
apply
{
struct
apply
{
struct
type
{
struct
type
{
PyObject
*
operator
()(
const
variant_type
&
gm
)
const
{
PyObject
*
operator
()(
const
variant_type
&
v
)
const
{
return
VariantRefToObject
<
variant_type
>::
convert
(
gm
);
return
VariantRefToObject
<
variant_type
>::
convert
(
v
);
}
}
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
...
@@ -169,8 +184,9 @@ struct VariantConverter {
...
@@ -169,8 +184,9 @@ struct VariantConverter {
static
void
registration
()
{
static
void
registration
()
{
typedef
details
::
VariantValueToObject
<
variant_type
>
variant_to_value
;
typedef
details
::
VariantValueToObject
<
variant_type
>
variant_to_value
;
typedef
typename
details
::
VariantAlternatives
<
variant_type
>::
types
types
;
boost
::
python
::
to_python_converter
<
variant_type
,
variant_to_value
>
();
boost
::
python
::
to_python_converter
<
variant_type
,
variant_to_value
>
();
boost
::
mpl
::
for_each
<
typename
variant_type
::
types
>
(
boost
::
mpl
::
for_each
<
types
>
(
details
::
VariantImplicitlyConvertible
<
variant_type
>
());
details
::
VariantImplicitlyConvertible
<
variant_type
>
());
}
}
};
};
...
...
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