N
Nephi Immortal
I was curious to examine Microsoft’s source code. The headers are
string, xmemory, and xutility. I could see container class and proxy
class. They inherit into _String_val and _String_val inherits into
basic_string.
Why are several classes needed? Why not create single basic_string
class? Look at Microsoft’s code here.
struct _Container_base12;
struct _Iterator_base12;
// CLASS _Container_proxy
struct _Container_proxy
{ // store head of iterator chain and back pointer
_Container_proxy()
: _Mycont(0), _Myfirstiter(0)
{ // construct from pointers
}
const _Container_base12 *_Mycont;
_Iterator_base12 *_Myfirstiter;
};
struct _CRTIMP2_PURE _Container_base12
{ // store pointer to _Container_proxy
public:
_Container_base12()
: _Myproxy(0)
{ // construct childless container
}
_Container_base12(const _Container_base12&)
: _Myproxy(0)
{ // copy a container
}
_Container_base12& operator=(const _Container_base12&)
{ // assign a container
return (*this);
}
~_Container_base12()
{ // destroy the container
_Orphan_all();
}
_Iterator_base12 **_Getpfirst() const
{ // get address of iterator chain
return (_Myproxy == 0 ? 0 : &_Myproxy->_Myfirstiter);
}
void _Orphan_all(); // orphan all iterators
void _Swap_all(_Container_base12&); // swap all iterators
_Container_proxy *_Myproxy;
};
string, xmemory, and xutility. I could see container class and proxy
class. They inherit into _String_val and _String_val inherits into
basic_string.
Why are several classes needed? Why not create single basic_string
class? Look at Microsoft’s code here.
struct _Container_base12;
struct _Iterator_base12;
// CLASS _Container_proxy
struct _Container_proxy
{ // store head of iterator chain and back pointer
_Container_proxy()
: _Mycont(0), _Myfirstiter(0)
{ // construct from pointers
}
const _Container_base12 *_Mycont;
_Iterator_base12 *_Myfirstiter;
};
struct _CRTIMP2_PURE _Container_base12
{ // store pointer to _Container_proxy
public:
_Container_base12()
: _Myproxy(0)
{ // construct childless container
}
_Container_base12(const _Container_base12&)
: _Myproxy(0)
{ // copy a container
}
_Container_base12& operator=(const _Container_base12&)
{ // assign a container
return (*this);
}
~_Container_base12()
{ // destroy the container
_Orphan_all();
}
_Iterator_base12 **_Getpfirst() const
{ // get address of iterator chain
return (_Myproxy == 0 ? 0 : &_Myproxy->_Myfirstiter);
}
void _Orphan_all(); // orphan all iterators
void _Swap_all(_Container_base12&); // swap all iterators
_Container_proxy *_Myproxy;
};