string's class question

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;
};
 
B

Bo Persson

Nephi said:
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()
{ // construct from pointers
}

const _Container_base12 *_Mycont;
_Iterator_base12 *_Myfirstiter;
};

That looks like code used for iterator debugging in debug mode.
Putting it in a base class perhaps help sharing this code with other
containers?

Anyway, this is just an implementation detail that doesn't matter
much. A library is allowed to organize the code the way it wants to.


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top