Skip to content

Added CRTP to Node #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions include/interval-tree/interval_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ namespace lib_interval_tree
// ############################################################################################################
template <
typename numerical_type = default_interval_value_type,
typename interval_type_ = interval<numerical_type, closed>>
typename interval_type_ = interval<numerical_type, closed>,
typename derived = void>
class node
{
protected:
using node_type = node<numerical_type, interval_type_>;
using node_type =
std::conditional_t<std::is_same<derived, void>::value, node<numerical_type, interval_type_>, derived>;

public:
using interval_type = interval_type_;
Expand All @@ -217,7 +219,7 @@ namespace lib_interval_tree
friend void increment_reverse(T& iter);

public:
node(node* parent, interval_type interval)
node(node_type* parent, interval_type interval)
: interval_{std::move(interval)}
, max_{interval.high()}
, parent_{parent}
Expand Down Expand Up @@ -265,23 +267,23 @@ namespace lib_interval_tree
/**
* Returns the parent node up the tree.
*/
node const* parent() const
node_type const* parent() const
{
return parent_;
}

/**
* Returns the left node (readonly).
*/
node const* left() const
node_type const* left() const
{
return left_;
}

/**
* Returns the right node (readonly).
*/
node const* right() const
node_type const* right() const
{
return right_;
}
Expand Down Expand Up @@ -338,9 +340,9 @@ namespace lib_interval_tree
protected:
interval_type interval_;
value_type max_;
node* parent_;
node* left_;
node* right_;
node_type* parent_;
node_type* left_;
node_type* right_;
rb_color color_;
};
// ############################################################################################################
Expand Down Expand Up @@ -513,7 +515,7 @@ namespace lib_interval_tree
throw std::out_of_range("interval_tree_iterator out of bounds");
}

typename value_type::interval_type* operator->() const
typename value_type::interval_type const* operator->() const
{
if (node_)
return node_->interval();
Expand Down
2 changes: 1 addition & 1 deletion include/interval-tree/interval_tree_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace lib_interval_tree
template <typename IntervalT, typename tree_hooks>
class interval_tree;

template <typename numerical_type, typename interval_type>
template <typename numerical_type, typename interval_type, typename derived>
class node;

template <typename node_type, typename owner_type, typename tree_hooks>
Expand Down
Loading