🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1565

Re: Why no iterator::operator T*() in STL?

#1565
From: Herb Sutter
Date: Thu, 03 Aug 1995 15:56
34 lines
1848 bytes
In article <3vo6iv$grf@metro.ucc.su.OZ.AU>,
   maxtal@Physics.usyd.edu.au (John Max Skaller) wrote:
>In article <1995Jul19.180847.17243@ptolemy-ethernet.arc.nasa.gov>,
>Paul J. Lucas <pjl@kronos.arc.nasa.gov> wrote:
>>	Why shouldn't I be able to do:
>>
>>		list< int > x;
>>		list< int >::iterator i;
>>		int *p = i;	// use list< int >::operator int*()

Do you mean list<int>::iterator::operator int*() here?

>>
>>	i.e., convert the iterator to its underlying pointer?
>
>	Use:
>
>	int *p = &*i;

Right.  Also, Paul, for an entertaining treatment of why implicit conversions 
(such as the operator int*() above) can become quite evil and foul-smelling in 
practice even for their original programmer, see Scott Meyers' column in this 
month's C/C++ User's Journal.

This is one of the rare examples where an otherwise neat and clean-cut 
standards-conforming C++ compiler will go out of its way to silently and 
mericlessly destroy your code given the slightest excuse, and will go about 
doing so in the most devilishly difficult-to-debug way it can find to boot... 
:-)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herb Sutter                 2228 Urwin, Ste 102         voice (416) 618-0184
Connected Object Solutions  Oakville ON Canada L6L 2T2    fax (905) 847-6019
Technical Details
Message-ID: <3vqrbp$1n4@steel.interlog.com>
Path: arc1-ca.pugleaf.net!interlog.com!herbs
References: <1995Jul19.180847.17243@ptolemy-ethernet.arc.nasa.gov> <3vo6iv$grf@metro.ucc.su.OZ.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!interlog.com!herbs
From: herbs@interlog.com (Herb Sutter)
Newsgroups: comp.std.c++
Subject: Re: Why no iterator::operator T*() in STL?
Date: Thu, 03 Aug 95 15:56:35 GMT
Organization: Daystar Software Systems Design Inc.
Message-ID: <3vqrbp$1n4@steel.interlog.com>
References: <1995Jul19.180847.17243@ptolemy-ethernet.arc.nasa.gov> <3vo6iv$grf@metro.ucc.su.OZ.AU>
NNTP-Posting-Host: herbs.interlog.com
Keywords: STL iterator pointer conversion
X-Newsreader: News Xpress Version 1.0 Beta #3