mirror of https://github.com/CGAL/cgal
Added conversion from optional<variant<...>>
This commit is contained in:
parent
ba7f258db8
commit
b4c1504975
|
|
@ -34,6 +34,7 @@
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
|
|
@ -111,9 +112,14 @@ class Object
|
||||||
Object(const T& t) {
|
Object(const T& t) {
|
||||||
// we cannot invoke another ctor from here, so we have to behave
|
// we cannot invoke another ctor from here, so we have to behave
|
||||||
// like the copy ctor of our base
|
// like the copy ctor of our base
|
||||||
CGAL::Object tmp = boost::apply_visitor(Object_from_variant(), t);
|
if(t) {
|
||||||
|
CGAL::Object tmp = boost::apply_visitor(Object_from_variant(), *t);
|
||||||
this->ptr = tmp.ptr;
|
this->ptr = tmp.ptr;
|
||||||
(this->ptr)->add_reference();
|
(this->ptr)->add_reference();
|
||||||
|
} else {
|
||||||
|
typedef Wrapper<Empty> Wrap;
|
||||||
|
ptr = new Wrap(Empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,15 @@
|
||||||
#include <CGAL/Object.h>
|
#include <CGAL/Object.h>
|
||||||
#include <CGAL/assertions.h>
|
#include <CGAL/assertions.h>
|
||||||
|
|
||||||
|
#include <boost/variant.hpp>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
void test_object() {
|
void test_object() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
double j = 0.0;
|
double j = 0.0;
|
||||||
boost::variant<int, char, double> v = 23;
|
boost::optional< boost::variant<int, char, double> > v(23);
|
||||||
CGAL::Object o = v;
|
CGAL::Object o = v;
|
||||||
|
CGAL_assertion(!o.empty());
|
||||||
CGAL_assertion(CGAL::assign(i, o));
|
CGAL_assertion(CGAL::assign(i, o));
|
||||||
CGAL_assertion(i == 23);
|
CGAL_assertion(i == 23);
|
||||||
//reassign the variant and assign it again
|
//reassign the variant and assign it again
|
||||||
|
|
@ -16,6 +20,10 @@ void test_object() {
|
||||||
CGAL_assertion(!CGAL::assign(i, o));
|
CGAL_assertion(!CGAL::assign(i, o));
|
||||||
CGAL_assertion(CGAL::assign(j, o));
|
CGAL_assertion(CGAL::assign(j, o));
|
||||||
CGAL_assertion(j == 2.0);
|
CGAL_assertion(j == 2.0);
|
||||||
|
//empty optional
|
||||||
|
boost::optional< boost::variant<int, char, double> > v2;
|
||||||
|
CGAL::Object o2 = v2;
|
||||||
|
CGAL_assertion(o2.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue