Why I can't call toHash in const context?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Aug 6 11:53:56 PDT 2013


On Tue, Aug 06, 2013 at 08:44:51PM +0200, Borislav Kosharov wrote:
> On Tuesday, 6 August 2013 at 18:18:43 UTC, Peter Alexander wrote:
> >On Tuesday, 6 August 2013 at 18:14:29 UTC, Borislav Kosharov
> >wrote:
> >>Am I missing something?
> >
> >It's a long story :-)
> >
> >Issue 1824 - Object not const correct
> >http://d.puremagic.com/issues/show_bug.cgi?id=1824
> >
> >Issue 9771 - Remove toHash from Object
> >http://d.puremagic.com/issues/show_bug.cgi?id=9771
> >
> >http://forum.dlang.org/thread/jtlj1k$1fdj$1@digitalmars.com#post-jtlj1k:241fdj:241:40digitalmars.com
> 
> Also what is the way of calculating hashes for basic types like int
> and string. Those types don't inherit from Object, right? Is there
> some std function like hash(T)(T value) that is universal or
> something?

Currently, the most reliable way to get hashes for basic types that also
matches what AA's use, is to do this:

	int x = 123;	// or, int[] x = [1,2,3], etc.
	auto hash = typeid(x).getHash(&x);

I say "currently" because this is likely to change in the future when we
clean up the AA implementation.


T

-- 
War doesn't prove who's right, just who's left. -- BSD Games' Fortune


More information about the Digitalmars-d mailing list