\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 4.14 - 2D and 3D Linear Geometry Kernel
Upgrading from CGAL::Object to boost::variant

Code can be upgraded by using either boost::get or the boost::static_visitor<T>.

#include <CGAL/intersections.h>
template<typename R>
struct Intersection_visitor : public boost::static_visitor<> {
void operator()(const Point_2& p) const
{ // Point_2
}
void operator()(const Segment_2& s) const
{ // Segment_2
}
};
template <class R>
void foo(Segment_2<R> seg, Line_2<R> lin)
{
CGAL::Object obj = intersection(seg, lin);
if(const Point_2* foo = object_cast<Point_2>(&obj)) {
// Point_2
} else if(const Segment_2* foo = object_cast<Segment_2>(&obj)) {
// Segment_2
} else {
// empty
}
// becomes
auto result = intersection(seg, lin);
if(result) {
if(const Point_2* foo = boost::get<Point_2>(&*result)) {
// Point_2
} else if(const Segment_2* foo = boost::get<Segment_2>(&*result)) {
// Segment_2
}
} else {
// empty
}
// or with boost::static_visitor<T>
if(result) { boost::apply_visitor(Intersection_visitor(), *result); }
else { // empty
}
}