Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #10004 > unrolled thread

string's class question

Started byNephi Immortal <immortalnephi@gmail.com>
First post2011-09-09 14:40 -0700
Last post2011-09-10 08:31 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c++


Contents

  string's class question Nephi Immortal <immortalnephi@gmail.com> - 2011-09-09 14:40 -0700
    Re: string's class question "Bo Persson" <bop@gmb.dk> - 2011-09-10 08:31 +0200

#10004 — string's class question

FromNephi Immortal <immortalnephi@gmail.com>
Date2011-09-09 14:40 -0700
Subjectstring's class question
Message-ID<a8059453-ba33-43fa-a907-e3785429d38b@s2g2000vby.googlegroups.com>
	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;
	};

[toc] | [next] | [standalone]


#10014

From"Bo Persson" <bop@gmb.dk>
Date2011-09-10 08:31 +0200
Message-ID<9d0ekoFkjfU1@mid.individual.net>
In reply to#10004
Nephi Immortal wrote:
> 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;
> };
>
>

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web