From 50b032ebc0519a2b2585c499b9901fde9a0eccee Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 8 Apr 2022 20:03:46 +0100 Subject: [PATCH] Make intrusive_list_node's next/prev private Tromey noticed that intrusive_list_node leaves its data members public, which seems sub-optimal. This commit makes intrusive_list_node's data fields private. intrusive_list_iterator, intrusive_list_reverse_iterator, and intrusive_list do need to access the fields, so they are made friends. Change-Id: Ia8b306b40344cc218d423c8dfb8355207a612ac5 --- gdbsupport/intrusive_list.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gdbsupport/intrusive_list.h b/gdbsupport/intrusive_list.h index 77eeeeec5fd..6812266159a 100644 --- a/gdbsupport/intrusive_list.h +++ b/gdbsupport/intrusive_list.h @@ -24,15 +24,26 @@ /* A list node. The elements put in an intrusive_list either inherit from this, or have a field of this type. */ template -struct intrusive_list_node +class intrusive_list_node { +public: bool is_linked () const { return next != INTRUSIVE_LIST_UNLINKED_VALUE; } +private: T *next = INTRUSIVE_LIST_UNLINKED_VALUE; T *prev = INTRUSIVE_LIST_UNLINKED_VALUE; + + template + friend struct intrusive_list_iterator; + + template + friend struct intrusive_list_reverse_iterator; + + template + friend struct intrusive_list; }; /* Follows a couple types used by intrusive_list as template parameter to find -- 2.30.2