Getting the const-correctness of Object sorted once and for all

Jonathan M Davis jmdavisProg at gmx.com
Sun May 13 14:19:18 PDT 2012


On Sunday, May 13, 2012 13:54:48 Jonathan M Davis wrote:
> On Sunday, May 13, 2012 17:39:44 Stewart Gordon wrote:
> > http://d.puremagic.com/issues/show_bug.cgi?id=1824
> > 
> > This has gone on for too long.
> > 
> > Object.toString, .toHash, .opCmp and .opEquals should all be const.  (It's
> > also been stated somewhere that they should be pure and nothrow, or
> > something like that, but I forget where.)
> > 
> > This makes it a nightmare to use const objects in data structures, among
> > other things, at best forcing the use of ugly workarounds.  There are
> > probably other, more serious effects of this that can't easily be worked
> > around.
> > 
> > It seems that the main obstacle is rewriting the relevant methods in
> > std.stream.  The current implementation doesn't make sense anyway -
> > reading
> > the entire contents of a file is certainly not the way to generate a hash
> > or string representation of the stream.  I'm thinking the hash should
> > probably be the stream handle, and the string representation could perhaps
> > be the full pathname of the file.  Of course, what it should be for
> > non-file streams is another matter.  (This would be a change at the API
> > level, but when the API's as fundamentally flawed as this....)
> > 
> > Are there any other bits of druntime/Phobos that need to be sorted out
> > before these methods can be declared const/pure/nothrow once and for all?
> > 
> > Stewart.
> 
> toHash, opCmp, opEquals, and toString will _all_ be required to be const
> @safe pure nothrow. Some work has been done towards that, but it hasn't
> been completed. One of the major obstacles is the inability for stuff such
> as format, to!string, or Appender to be pure right now. A number of
> druntime functions are going to need to be marked as pure for that to
> happen (particilurly reserve and capacity, but there are probably others).
> Some effort has been put in that area recently, but it hasn't been
> completed.

There's probably some AA-related stuff which has issues too. I'm not sure what 
all of the major obstacles are, but some of them have been being worked on 
with the goal of making object const-correct in the near future.

- Jonathan M Davis


More information about the Digitalmars-d mailing list