From b4c150497532296cf8d7e4d9a1011d2f5046f8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Wed, 22 Jun 2011 15:27:48 +0000 Subject: [PATCH] Added conversion from optional> --- STL_Extension/include/CGAL/Object.h | 12 +++++++++--- STL_Extension/test/STL_Extension/test_Object.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/STL_Extension/include/CGAL/Object.h b/STL_Extension/include/CGAL/Object.h index c2fe6452540..7cddf7ec320 100644 --- a/STL_Extension/include/CGAL/Object.h +++ b/STL_Extension/include/CGAL/Object.h @@ -34,6 +34,7 @@ #include #include +#include namespace CGAL { @@ -111,9 +112,14 @@ class Object Object(const T& t) { // we cannot invoke another ctor from here, so we have to behave // like the copy ctor of our base - CGAL::Object tmp = boost::apply_visitor(Object_from_variant(), t); - this->ptr = tmp.ptr; - (this->ptr)->add_reference(); + if(t) { + CGAL::Object tmp = boost::apply_visitor(Object_from_variant(), *t); + this->ptr = tmp.ptr; + (this->ptr)->add_reference(); + } else { + typedef Wrapper Wrap; + ptr = new Wrap(Empty()); + } } template diff --git a/STL_Extension/test/STL_Extension/test_Object.cpp b/STL_Extension/test/STL_Extension/test_Object.cpp index cfcc861db64..e55d796185b 100644 --- a/STL_Extension/test/STL_Extension/test_Object.cpp +++ b/STL_Extension/test/STL_Extension/test_Object.cpp @@ -3,11 +3,15 @@ #include #include +#include +#include + void test_object() { int i = 0; double j = 0.0; - boost::variant v = 23; + boost::optional< boost::variant > v(23); CGAL::Object o = v; + CGAL_assertion(!o.empty()); CGAL_assertion(CGAL::assign(i, o)); CGAL_assertion(i == 23); //reassign the variant and assign it again @@ -16,6 +20,10 @@ void test_object() { CGAL_assertion(!CGAL::assign(i, o)); CGAL_assertion(CGAL::assign(j, o)); CGAL_assertion(j == 2.0); + //empty optional + boost::optional< boost::variant > v2; + CGAL::Object o2 = v2; + CGAL_assertion(o2.empty()); } int main() {