@@ -8,6 +8,9 @@ import ConstructionBase: getproperties, constructorof, setproperties
88@inline function structural_eq (o1, o2)
99 getproperties (o1) == getproperties (o2)
1010end
11+ @inline function structural_isequal (o1, o2)
12+ isequal (getproperties (o1), getproperties (o2))
13+ end
1114
1215start_hash (o, h, typesalt:: Nothing ) = Base. hash (typeof (o), h)
1316start_hash (o, h, typesalt) = Base. hash (typesalt, h)
@@ -41,7 +44,8 @@ function def_kwconstructor(T, propertynames)
4144end
4245
4346const BATTERIES_DEFAULTS = (
44- eq = true ,
47+ eq = true ,
48+ isequal = true ,
4549 hash = true ,
4650 kwconstructor = false ,
4751 selfconstructor = true ,
@@ -53,6 +57,7 @@ const BATTERIES_DEFAULTS = (
5357
5458const BATTERIES_DOCSTRINGS = (
5559 eq = " Define `Base.(==)` structurally." ,
60+ isequal = " Define `Base.isequal` structurally." ,
5661 hash = " Define `Base.hash` structurally." ,
5762 kwconstructor = " Add a keyword constructor." ,
5863 selfconstructor = " Add a constructor of the for `T(self::T) = self`" ,
@@ -150,6 +155,10 @@ macro batteries(T, kw...)
150155 def = :(Base.:(== )(o1:: $T , o2:: $T ) = $ (structural_eq)(o1, o2))
151156 push! (ret. args, def)
152157 end
158+ if nt. isequal
159+ def = :(Base. isequal (o1:: $T , o2:: $T ) = $ (structural_isequal)(o1, o2))
160+ push! (ret. args, def)
161+ end
153162 if nt. kwshow
154163 def = :(Base. show (io:: IO , o:: $T ) = $ (kwshow)(io, o))
155164 push! (ret. args, def)
0 commit comments