Jump to page: 1 2
Thread overview
[Issue 17206] [Tracking] Check that opEquals and toHash are both defined or neither are defined
[Issue 17206] Checks that opEquals and toHash are both defined or neither are defined
Mar 28, 2018
Jack Stouffer
Mar 28, 2018
Jack Stouffer
Mar 28, 2018
Jack Stouffer
Mar 28, 2018
Jack Stouffer
Apr 10, 2018
Jack Stouffer
Jul 02, 2018
Nathan S.
Dec 17, 2022
Iain Buclaw
March 28, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jack@jackstouffer.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All
           Severity|enhancement                 |normal

--- Comment #1 from Jack Stouffer <jack@jackstouffer.com> ---
I'm turning this into a tracking issue.

--
March 28, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |18673


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=18673
[Issue 18673] std.socket.InternetAddress has opEquals but no toHash
--
March 28, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |18674, 18675, 18676, 18677,
                   |                            |18678


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=18674
[Issue 18674] std.json.JSONValue has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18675
[Issue 18675] std.experimental.checkedint.Checked has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18676
[Issue 18676] std.datetime.date.DateTime has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18677
[Issue 18677] std.datetime.date.Date has opCmp but no toHash
https://issues.dlang.org/show_bug.cgi?id=18678
[Issue 18678] std.datetime.date.TimeOfDay has opCmp but no toHash
--
March 28, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |18679, 18680, 18681, 18682,
                   |                            |18683, 18684, 18685, 18686,
                   |                            |18687
            Summary|Checks that opEquals and    |[Tracking] Check that
                   |toHash are both defined or  |opEquals and toHash are
                   |neither are defined         |both defined or neither are
                   |                            |defined


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=18679
[Issue 18679] std.complex.opEquals has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18680
[Issue 18680] std.random.LinearCongruentialEngine has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18681
[Issue 18681] std.random.XorshiftEngine has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18682
[Issue 18682] std.typecons.Nullable has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18683
[Issue 18683] std.containers.rbtree.RedBlackTree has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18684
[Issue 18684] std.containers.array.Array has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18685
[Issue 18685] std.containers.slist.SList has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18686
[Issue 18686] std.containers.dlist.DList has opEquals but no toHash
https://issues.dlang.org/show_bug.cgi?id=18687
[Issue 18687] std.numeric.CustomFloat has opEquals but no toHash
--
March 29, 2018
https://issues.dlang.org/show_bug.cgi?id=17206
Issue 17206 depends on issue 18678, which changed state.

Issue 18678 Summary: std.datetime.date.TimeOfDay has opCmp but no toHash https://issues.dlang.org/show_bug.cgi?id=18678

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--
March 29, 2018
https://issues.dlang.org/show_bug.cgi?id=17206
Issue 17206 depends on issue 18677, which changed state.

Issue 18677 Summary: std.datetime.date.Date has opCmp but no toHash https://issues.dlang.org/show_bug.cgi?id=18677

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--
March 29, 2018
https://issues.dlang.org/show_bug.cgi?id=17206
Issue 17206 depends on issue 18676, which changed state.

Issue 18676 Summary: std.datetime.date.DateTime has opCmp but no toHash https://issues.dlang.org/show_bug.cgi?id=18676

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--
April 10, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |18742


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=18742
[Issue 18742] std.regex: Using CodePointSet in AAs breaks if reference count
changes
--
July 02, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Nathan S. <n8sh.secondary@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |n8sh.secondary@hotmail.com

--- Comment #2 from Nathan S. <n8sh.secondary@hotmail.com> ---
Half of this is wrong.  For a type to be usable as a key in an associative array it must be true that "a == b" implies "a.toHash() == b.toHash()", so when there is a non-default `==` there should also be a custom `toHash` to maintain this property. But the reverse is not true: defining a non-default `toHash` does not require a custom `opEquals`, because the default `==` is already the strictest possible condition that satisfies "a == a" (since structs can be relocated).

--
July 03, 2018
https://issues.dlang.org/show_bug.cgi?id=17206

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> ---
No, toHash doesn't necessarily have to follow the semantics of default opEquals.

Example:

struct S1(bool customTohash)
{
    string s;
    static if(customTohash)
    {
        size_t toHash() const
        {
            return cast(size_t)s.ptr + s.length; // use string identity
        }

        /+ really should define this
        bool opEquals(const(S1) other) const { return other.s is s; }
        +/
    }
}

void main()
{
    bool[S1!false] aa1;
    aa1[S1!false("hello".idup)] = true;
    aa1[S1!false("hello".idup)] = true;
    assert(aa1.length == 1);

    bool[S1!true] aa2;
    aa2[S1!true("hello".idup)] = true;
    aa2[S1!true("hello".idup)] = true;
    assert(aa2.length == 1); // fails
}

--
« First   ‹ Prev
1 2