diff --git a/Orthtree/include/CGAL/Orthtree.h b/Orthtree/include/CGAL/Orthtree.h index 03a18ac0c4f..d2fa0b3e0df 100644 --- a/Orthtree/include/CGAL/Orthtree.h +++ b/Orthtree/include/CGAL/Orthtree.h @@ -48,9 +48,52 @@ namespace CGAL { -namespace internal { +namespace Orthtree_impl { + BOOST_MPL_HAS_XXX_TRAIT_DEF(Node_data) -} + +template +struct Node_data_wrapper; + +template +struct Node_data_wrapper +{ + using Node_index = typename GT::Node_index; + using Node_data = typename GT::Node_data; + Properties::Experimental::Property_array_handle m_node_contents; + + template + Node_data_wrapper(Property_container& node_properties) + : m_node_contents(node_properties.template get_or_add_property("contents").first) + {} + + const Node_data& operator[](Node_index n) const + { + return m_node_contents[n]; + } + + Node_data& operator[](Node_index n) + { + return m_node_contents[n]; + } +}; + +template +struct Node_data_wrapper +{ + using Node_index = typename GT::Node_index; + using Node_data = void*; + + template + Node_data_wrapper(Property_container&) {} + + void* operator[](Node_index) const + { + return nullptr; + } +}; + +} // end of Orthtree_impl namespace /*! \ingroup PkgOrthtreeRef @@ -72,20 +115,7 @@ BOOST_MPL_HAS_XXX_TRAIT_DEF(Node_data) */ template class Orthtree { - template - struct Node_data_selector {}; - - template - struct Node_data_selector { - using type = typename A::Node_data; - }; - - template - struct Node_data_selector { - using type = void; - }; - - static inline constexpr bool has_data = internal::has_Node_data::value; + static inline constexpr bool has_data = Orthtree_impl::has_Node_data::value; public: /// \name Template Types @@ -104,7 +134,7 @@ public: using Adjacency = typename Traits::Adjacency; ///< Adjacency type. using Node_index = typename Traits::Node_index; ///< Index of a given node in the tree; the root always has index 0. - using Node_data = typename Node_data_selector::type; + using Node_data = typename Orthtree_impl::Node_data_wrapper::Node_data; /// @} @@ -178,7 +208,7 @@ private: // data members : Traits m_traits; /* the tree traits */ Node_property_container m_node_properties; - std::conditional_t, void*> m_node_contents; + Orthtree_impl::Node_data_wrapper m_node_contents; Property_array m_node_depths; Property_array m_node_coordinates; Property_array> m_node_parents; @@ -190,14 +220,6 @@ private: // data members : Cartesian_ranges cartesian_range; /* a helper to easily iterate over coordinates of points */ - template> - auto init_node_contents(std::true_type) -> std::enable_if_t - { - return Property_array(m_node_properties.template get_or_add_property("contents").first); - } - - void* init_node_contents(std::false_type) { return nullptr; } - public: /// \name Constructor @@ -219,7 +241,7 @@ public: */ explicit Orthtree(Traits traits) : m_traits(traits), - m_node_contents(init_node_contents(std::bool_constant())), + m_node_contents(m_node_properties), m_node_depths(m_node_properties.template get_or_add_property("depths", 0).first), m_node_coordinates(m_node_properties.template get_or_add_property("coordinates").first), m_node_parents(m_node_properties.template get_or_add_property>("parents").first), @@ -250,7 +272,7 @@ public: Orthtree(const Orthtree& other) : m_traits(other.m_traits), m_node_properties(other.m_node_properties), - m_node_contents(init_node_contents(std::bool_constant())), + m_node_contents(m_node_properties), m_node_depths(m_node_properties.template get_property("depths")), m_node_coordinates(m_node_properties.template get_property("coordinates")), m_node_parents(m_node_properties.template get_property>("parents")), @@ -261,7 +283,7 @@ public: Orthtree(Orthtree&& other) : m_traits(other.m_traits), m_node_properties(std::move(other.m_node_properties)), - m_node_contents(init_node_contents(std::bool_constant())), + m_node_contents(m_node_properties), m_node_depths(m_node_properties.template get_property("depths")), m_node_coordinates(m_node_properties.template get_property("coordinates")), m_node_parents(m_node_properties.template get_property>("parents")), @@ -723,18 +745,18 @@ public: } /*! - \brief retrieves a reference to the Node_data associated with the node specified by `n`. + \brief retrieves a reference to the `Node_data` associated with the node specified by `n` if + `GeomTraits` is a model of `OrthtreeTraitswithData`, and `nullptr` otherwise. */ - template - auto data(Node_index n) -> std::enable_if_t{ + auto data(Node_index n){ return m_node_contents[n]; } /*! - \brief retrieves a const reference to the Node_data associated with the node specified by `n`. + \brief retrieves a const reference to the `Node_data` associated with the node specified by `n` if + `GeomTraits` is a model of `OrthtreeTraitswithData`, and `nullptr` otherwise. */ - template - auto data(Node_index n) const -> std::enable_if_t { + auto data(Node_index n) const{ return m_node_contents[n]; }