Skip to main content
added 36 characters in body
Source Link

I would use

~node() noexcept {
  while (next) {
    nextstd::shared_ptr<node> =t;
    std::shared_ptr<node>swap(t,next)->next;>next);
    next = t;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node (by assigning to it next->next), and finally destroying temporary and so on.

I would use

~node() noexcept {
  while (next) {
    next = std::shared_ptr<node>(next)->next;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node (by assigning to it next->next), and finally destroying temporary and so on.

I would use

~node() noexcept {
  while (next) {
    std::shared_ptr<node> t;
    std::swap(t,next->next);
    next = t;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node (by assigning to it next->next), and finally destroying temporary and so on.

added 32 characters in body
Source Link

I would use

~node() noexcept {
  while (next) {
    next = std::shared_ptr<node>(next)->next;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node (by assigning to it next->next), and finally destroying temporary and so on.

I would use

~node() noexcept {
  while (next) {
    next = std::shared_ptr<node>(next)->next;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node, and finally destroying temporary and so on.

I would use

~node() noexcept {
  while (next) {
    next = std::shared_ptr<node>(next)->next;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node (by assigning to it next->next), and finally destroying temporary and so on.

Source Link

I would use

~node() noexcept {
  while (next) {
    next = std::shared_ptr<node>(next)->next;
  }
}

The idea is to erase the list tail in a node destructor by holding  the pointer to the next node in temporary, then removing the pointer from the current node, and finally destroying temporary and so on.