Can anyone explain why the _List_const_iterator would be using _List_node_base and downcast it to _List_node when needed? -- I think there must be some reason behind this.
Thanks
struct _List_node_base
{
_List_node_base* _M_next; ///< Self-explanatory
_List_node_base* _M_prev; ///< Self-explanatory
// ...
};
template<typename _Tp>
struct _List_node : public _List_node_base
{
_Tp _M_data; ///< User's data.
};
template<typename _Tp>
struct _List_const_iterator {
// Must downcast from List_node_base to _List_node to get to
// _M_data.
reference operator*() const
{ return static_cast<_Node*>(_M_node)->_M_data; }
// ...
// The only member points to the %list element.
const _List_node_base* _M_node; ///WHY NOT USING _List_node here?
};