Skip to content

Commit

Permalink
Using c++17 standard library (#7526)
Browse files Browse the repository at this point in the history
use std::shared_ptr, std::optional, std::variant, ...

These are important changes since they appear in the CGAL API and thus
are breaking changes.

includes #7416
  • Loading branch information
sloriot authored Aug 18, 2023
2 parents b534d12 + d6c04e3 commit 5a962eb
Show file tree
Hide file tree
Showing 587 changed files with 4,601 additions and 4,893 deletions.
2 changes: 1 addition & 1 deletion AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Provides the operator:
`return_type operator()(const Query& q, const Primitive::Datum& d)`,
which computes the intersection between `q` and `d`. The type of the returned object
must be a `boost::optional` of a `boost::variant` of the possible intersection types.
must be a `std::optional` of a `std::variant` of the possible intersection types.
*/
typedef unspecified_type Intersect_3;

Expand Down
6 changes: 3 additions & 3 deletions AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class AABBRayIntersectionTraits {
/*!
A functor object to compute the distance between the source of a ray and its
closest intersection point between the ray and a primitive or a bounding box.
An empty `boost::optional` is returned, if there is no intersection.
An empty `std::optional` is returned, if there is no intersection.
When there is an intersection, an object of type `FT` is returned such that
if `i1` and `i2` are two intersection points, then `i1` is closer to the source
of the ray than `i2` iff `n1 < n2`, `n1` and `n2` being the numbers returned for `i1` and `i2`
respectively.
Provides the operators:
`boost::optional<FT> operator()(const Ray_3& r, const Bounding_box& bbox)`.
`boost::optional<std::pair<FT, Intersection_and_primitive_id<Ray_3>::%Type > >
`std::optional<FT> operator()(const Ray_3& r, const Bounding_box& bbox)`.
`std::optional<std::pair<FT, Intersection_and_primitive_id<Ray_3>::%Type > >
operator()(const Ray_3& r, const Primitive& primitive)`.
A common algorithm to compute the intersection between a bounding box and a ray is <A
Expand Down
4 changes: 2 additions & 2 deletions AABB_tree/doc/AABB_tree/Concepts/AABBTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ typedef unspecified_type Do_intersect;

/*!
A functor object to compute the intersection of a query and a primitive. Provides the operator:
`boost::optional<Intersection_and_primitive_id<Query>::%Type > operator()(const Query & q, const Primitive& primitive);` which returns the intersection as a pair composed of an object and a primitive id, iff the query intersects the primitive.
`std::optional<Intersection_and_primitive_id<Query>::%Type > operator()(const Query & q, const Primitive& primitive);` which returns the intersection as a pair composed of an object and a primitive id, iff the query intersects the primitive.
\cgalHeading{Note on Backward Compatibility}
Before the release 4.3 of \cgal, the return type of this function used to be `boost::optional<Object_and_primitive_id>`.
Before the release 4.3 of \cgal, the return type of this function used to be `std::optional<Object_and_primitive_id>`.
*/
typedef unspecified_type Intersection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef boost::optional< Tree::Intersection_and_primitive_id<Segment>::Type > Segment_intersection;
typedef boost::optional< Tree::Intersection_and_primitive_id<Plane>::Type > Plane_intersection;
typedef std::optional< Tree::Intersection_and_primitive_id<Segment>::Type > Segment_intersection;
typedef std::optional< Tree::Intersection_and_primitive_id<Plane>::Type > Plane_intersection;
typedef Tree::Primitive_id Primitive_id;

int main()
Expand Down Expand Up @@ -57,7 +57,7 @@ int main()
if(intersection)
{
// gets intersection object
const Point* p = boost::get<Point>(&(intersection->first));
const Point* p = std::get_if<Point>(&(intersection->first));
if(p)
std::cout << "intersection object is a point " << *p << std::endl;

Expand All @@ -81,7 +81,7 @@ int main()
if(plane_intersection)
{

if(boost::get<Segment>(&(plane_intersection->first)))
if(std::get_if<Segment>(&(plane_intersection->first)))
std::cout << "intersection object is a segment" << std::endl;
}

Expand Down
6 changes: 3 additions & 3 deletions AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type> Ray_intersection;
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type> Ray_intersection;

struct Skip
{
Expand Down Expand Up @@ -70,8 +70,8 @@ int main(int argc, char* argv[])
Ray_intersection intersection = tree.first_intersection(ray, skip);
if(intersection)
{
if(boost::get<Point>(&(intersection->first))){
const Point* p = boost::get<Point>(&(intersection->first) );
if(std::get_if<Point>(&(intersection->first))){
const Point* p = std::get_if<Point>(&(intersection->first) );
std::cout << *p << std::endl;
}
}
Expand Down
18 changes: 9 additions & 9 deletions AABB_tree/include/CGAL/AABB_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <CGAL/Kernel_23/internal/Has_boolean_tags.h>


#include <boost/optional.hpp>
#include <optional>

/// \file AABB_traits.h

Expand All @@ -39,7 +39,7 @@ template <class T>
struct Remove_optional { typedef T type; };

template <class T>
struct Remove_optional< ::boost::optional<T> > { typedef T type; };
struct Remove_optional< ::std::optional<T> > { typedef T type; };

//helper controlling whether extra data should be stored in the AABB_tree traits class
template <class Primitive, bool has_shared_data=Has_nested_type_Shared_data<Primitive>::value>
Expand Down Expand Up @@ -85,7 +85,7 @@ struct AABB_traits_base_2<GeomTraits,true>{
typedef typename CGAL::Bbox_3 Bounding_box;

struct Intersection_distance {
boost::optional<FT> operator()(const Ray_3& ray, const Bounding_box& bbox) const {
std::optional<FT> operator()(const Ray_3& ray, const Bounding_box& bbox) const {
FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903
FT t_far = DBL_MAX;

Expand All @@ -101,7 +101,7 @@ struct AABB_traits_base_2<GeomTraits,true>{
for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) {
if(*direction_iter == 0) {
if((*source_iter < (bbox.min)(i)) || (*source_iter > (bbox.max)(i))) {
return boost::none;
return std::nullopt;
}
} else {
FT t1 = ((bbox.min)(i) - *source_iter) / *direction_iter;
Expand All @@ -118,7 +118,7 @@ struct AABB_traits_base_2<GeomTraits,true>{
// t_far = t2;

if(t_near > t_far || t_far < FT(0.))
return boost::none;
return std::nullopt;
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ class AABB_traits

/// `Intersection_and_primitive_id<Query>::%Type::first_type` is found according to
/// the result type of `GeomTraits::Intersect_3::operator()`. If it is
/// `boost::optional<T>` then it is `T`, and the result type otherwise.
/// `std::optional<T>` then it is `T`, and the result type otherwise.
template<typename Query>
struct Intersection_and_primitive_id {
typedef decltype(
Expand Down Expand Up @@ -364,12 +364,12 @@ class AABB_traits
Intersection(const AABB_traits<GeomTraits,AABBPrimitive,BboxMap>& traits)
:m_traits(traits) {}
template<typename Query>
boost::optional< typename Intersection_and_primitive_id<Query>::Type >
std::optional< typename Intersection_and_primitive_id<Query>::Type >
operator()(const Query& query, const typename AT::Primitive& primitive) const {
auto inter_res = GeomTraits().intersect_3_object()(query, internal::Primitive_helper<AT>::get_datum(primitive,m_traits));
if (!inter_res)
return boost::none;
return boost::make_optional( std::make_pair(*inter_res, primitive.id()) );
return std::nullopt;
return std::make_optional( std::make_pair(*inter_res, primitive.id()) );
}
};

Expand Down
18 changes: 9 additions & 9 deletions AABB_tree/include/CGAL/AABB_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <CGAL/AABB_tree/internal/AABB_search_tree.h>
#include <CGAL/AABB_tree/internal/Has_nested_type_Shared_data.h>
#include <CGAL/AABB_tree/internal/Primitive_helper.h>
#include <boost/optional.hpp>
#include <optional>

#ifdef CGAL_HAS_THREADS
#include <CGAL/mutex.h>
Expand Down Expand Up @@ -270,7 +270,7 @@ namespace CGAL {
/// \tparam Query must be a type for which `Do_intersect` operators are
/// defined in the traits class `AABBTraits`.
template <typename Query>
boost::optional<Primitive_id> any_intersected_primitive(const Query& query) const;
std::optional<Primitive_id> any_intersected_primitive(const Query& query) const;
///@}

/// \name Intersections
Expand All @@ -293,7 +293,7 @@ namespace CGAL {
/// \tparam Query must be a type for which `Do_intersect` and `Intersection` operators are
/// defined in the traits class `AABBTraits`.
template <typename Query>
boost::optional< typename Intersection_and_primitive_id<Query>::Type >
std::optional< typename Intersection_and_primitive_id<Query>::Type >
any_intersection(const Query& query) const;


Expand All @@ -317,12 +317,12 @@ namespace CGAL {
/// `AABBTraits` must be a model of `AABBRayIntersectionTraits` to
/// call this member function.
template<typename Ray, typename SkipFunctor>
boost::optional< typename Intersection_and_primitive_id<Ray>::Type >
std::optional< typename Intersection_and_primitive_id<Ray>::Type >
first_intersection(const Ray& query, const SkipFunctor& skip) const;

/// \cond
template<typename Ray>
boost::optional< typename Intersection_and_primitive_id<Ray>::Type >
std::optional< typename Intersection_and_primitive_id<Ray>::Type >
first_intersection(const Ray& query) const
{
return first_intersection(query, [](Primitive_id){ return false; });
Expand All @@ -342,12 +342,12 @@ namespace CGAL {
/// `AABBTraits` must be a model of `AABBRayIntersectionTraits` to
/// call this member function.
template<typename Ray, typename SkipFunctor>
boost::optional<Primitive_id>
std::optional<Primitive_id>
first_intersected_primitive(const Ray& query, const SkipFunctor& skip) const;

/// \cond
template<typename Ray>
boost::optional<Primitive_id>
std::optional<Primitive_id>
first_intersected_primitive(const Ray& query) const
{
return first_intersected_primitive(query, [](Primitive_id){ return false; });
Expand Down Expand Up @@ -963,7 +963,7 @@ namespace CGAL {

template <typename Tr>
template <typename Query>
boost::optional< typename AABB_tree<Tr>::template Intersection_and_primitive_id<Query>::Type >
std::optional< typename AABB_tree<Tr>::template Intersection_and_primitive_id<Query>::Type >
AABB_tree<Tr>::any_intersection(const Query& query) const
{
using namespace CGAL::internal::AABB_tree;
Expand All @@ -975,7 +975,7 @@ namespace CGAL {

template <typename Tr>
template <typename Query>
boost::optional<typename AABB_tree<Tr>::Primitive_id>
std::optional<typename AABB_tree<Tr>::Primitive_id>
AABB_tree<Tr>::any_intersected_primitive(const Query& query) const
{
using namespace CGAL::internal::AABB_tree;
Expand Down
29 changes: 14 additions & 15 deletions AABB_tree/include/CGAL/AABB_tree/internal/AABB_ray_intersection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

#include <functional>
#include <type_traits>
#include <boost/optional.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <optional>
# if defined(BOOST_MSVC)
# pragma warning(push)
# pragma warning(disable: 4996)
Expand All @@ -43,7 +42,7 @@ class AABB_ray_intersection {
public:
AABB_ray_intersection(const AABBTree& tree) : tree_(tree) {}

boost::optional< Ray_intersection_and_primitive_id >
std::optional< Ray_intersection_and_primitive_id >
ray_intersection(const Ray& query, SkipFunctor skip) const {
// We hit the root, now continue on the children. Keep track of
// nb_primitives through a variable in each Node on the stack. In
Expand All @@ -63,7 +62,7 @@ class AABB_ray_intersection {

Heap_type pq;
// pq.reserve(tree_.size() / 2);
boost::optional< Ray_intersection_and_primitive_id >
std::optional< Ray_intersection_and_primitive_id >
intersection, /* the temporary for calculating the result */
p; /* the current best intersection */

Expand All @@ -84,7 +83,7 @@ class AABB_ray_intersection {
if(!skip(current.node->left_data().id()) /* && do_intersect_obj(query, current.node->left_data()) */) {
intersection = intersection_obj(query, current.node->left_data());
if(intersection) {
FT ray_distance = boost::apply_visitor(param_visitor, intersection->first);
FT ray_distance = std::visit(param_visitor, intersection->first);
if(ray_distance < t) {
t = ray_distance;
p = intersection;
Expand All @@ -96,7 +95,7 @@ class AABB_ray_intersection {
if(!skip(current.node->right_data().id()) /* && do_intersect_obj(query, current.node->right_data()) */) {
intersection = intersection_obj(query, current.node->right_data());
if(intersection) {
FT ray_distance = boost::apply_visitor(param_visitor, intersection->first);
FT ray_distance = std::visit(param_visitor, intersection->first);
if(ray_distance < t) {
t = ray_distance;
p = intersection;
Expand All @@ -111,7 +110,7 @@ class AABB_ray_intersection {
if(!skip(current.node->left_data().id()) /* && do_intersect_obj(query, current.node->left_data()) */) {
intersection = intersection_obj(query, current.node->left_data());
if(intersection) {
FT ray_distance = boost::apply_visitor(param_visitor, intersection->first);
FT ray_distance = std::visit(param_visitor, intersection->first);
if(ray_distance < t) {
t = ray_distance;
p = intersection;
Expand All @@ -121,7 +120,7 @@ class AABB_ray_intersection {

// right child
const Node* child = &(current.node->right_child());
boost::optional< FT > dist = intersection_distance_obj(query, child->bbox());
std::optional< FT > dist = intersection_distance_obj(query, child->bbox());
if(dist)
pq.push(Node_ptr_with_ft(child, *dist, 2));

Expand All @@ -130,7 +129,7 @@ class AABB_ray_intersection {
default: // Children both inner nodes
{
const Node* child = &(current.node->left_child());
boost::optional<FT> dist = intersection_distance_obj(query, child->bbox());
std::optional<FT> dist = intersection_distance_obj(query, child->bbox());
if(dist)
pq.push(Node_ptr_with_ft(child, *dist, current.nb_primitives/2));

Expand Down Expand Up @@ -198,7 +197,7 @@ class AABB_ray_intersection {

template<typename AABBTraits>
template<typename Ray, typename SkipFunctor>
boost::optional< typename AABB_tree<AABBTraits>::template Intersection_and_primitive_id<Ray>::Type >
std::optional< typename AABB_tree<AABBTraits>::template Intersection_and_primitive_id<Ray>::Type >
AABB_tree<AABBTraits>::first_intersection(const Ray& query,
const SkipFunctor& skip) const {
static_assert(std::is_same<Ray, typename AABBTraits::Ray_3>::value,
Expand All @@ -219,22 +218,22 @@ AABB_tree<AABBTraits>::first_intersection(const Ray& query,
break;
}
}
return boost::none;
return std::nullopt;
}

template<typename AABBTraits>
template<typename Ray, typename SkipFunctor>
boost::optional<typename AABB_tree<AABBTraits>::Primitive_id>
std::optional<typename AABB_tree<AABBTraits>::Primitive_id>
AABB_tree<AABBTraits>::first_intersected_primitive(const Ray& query,
const SkipFunctor& skip) const
{
boost::optional<
std::optional<
typename AABB_tree<AABBTraits>::
template Intersection_and_primitive_id<Ray>::Type > res =
first_intersection(query, skip);
if ( (bool) res )
return boost::make_optional( res->second );
return boost::none;
return std::make_optional( res->second );
return std::nullopt;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


#include <CGAL/AABB_tree/internal/AABB_node.h>
#include <boost/optional.hpp>
#include <optional>

namespace CGAL {

Expand Down Expand Up @@ -69,7 +69,7 @@ class First_intersection_traits

public:
typedef
boost::optional< typename AABBTraits::template Intersection_and_primitive_id<Query>::Type >
std::optional< typename AABBTraits::template Intersection_and_primitive_id<Query>::Type >
Result;
public:
First_intersection_traits(const AABBTraits& traits)
Expand Down Expand Up @@ -124,7 +124,7 @@ class Listing_intersection_traits

void intersection(const Query& query, const Primitive& primitive)
{
boost::optional< typename AABBTraits::template Intersection_and_primitive_id<Query>::Type >
std::optional< typename AABBTraits::template Intersection_and_primitive_id<Query>::Type >
intersection = m_traits.intersection_object()(query, primitive);

if(intersection)
Expand Down Expand Up @@ -211,7 +211,7 @@ class First_primitive_traits
{
if( m_traits.do_intersect_object()(query, primitive) )
{
m_result = boost::optional<typename Primitive::Id>(primitive.id());
m_result = std::optional<typename Primitive::Id>(primitive.id());
m_is_found = true;
}
}
Expand All @@ -221,12 +221,12 @@ class First_primitive_traits
return m_traits.do_intersect_object()(query, node.bbox());
}

boost::optional<typename Primitive::Id> result() const { return m_result; }
std::optional<typename Primitive::Id> result() const { return m_result; }
bool is_intersection_found() const { return m_is_found; }

private:
bool m_is_found;
boost::optional<typename Primitive::Id> m_result;
std::optional<typename Primitive::Id> m_result;
const AABBTraits& m_traits;
};

Expand Down
Loading

0 comments on commit 5a962eb

Please sign in to comment.