Merge pull request #7098 from JinShil/depD1ops

Replace D1 operator overloads with D2 operator overloads
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2019-07-04 07:11:38 +02:00 committed by GitHub
commit 07034ea4e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 25 deletions

View file

@ -277,10 +277,11 @@ public:
else if ((y > 0) == (op=="<<")) else if ((y > 0) == (op=="<<"))
{ {
// Sign never changes during left shift // Sign never changes during left shift
data = data.opShl(u); data = data.opBinary!(op)(u);
} else }
else
{ {
data = data.opShr(u); data = data.opBinary!(op)(u);
if (data.isZero()) if (data.isZero())
sign = false; sign = false;
} }

View file

@ -2075,8 +2075,8 @@ public:
* shared between BitArray objects. i.e. D dynamic array * shared between BitArray objects. i.e. D dynamic array
* concatenation semantics are not followed) * concatenation semantics are not followed)
*/ */
BitArray opOpAssign(string op)(bool b) pure nothrow
BitArray opCatAssign(bool b) pure nothrow if (op == "~")
{ {
length = _len + 1; length = _len + 1;
this[_len - 1] = b; this[_len - 1] = b;
@ -2105,8 +2105,8 @@ public:
/*************************************** /***************************************
* ditto * ditto
*/ */
BitArray opOpAssign(string op)(BitArray b) pure nothrow
BitArray opCatAssign(BitArray b) pure nothrow if (op == "~")
{ {
auto istart = _len; auto istart = _len;
length = _len + b.length; length = _len + b.length;
@ -2139,7 +2139,8 @@ public:
/*************************************** /***************************************
* Support for binary operator ~ for `BitArray`. * Support for binary operator ~ for `BitArray`.
*/ */
BitArray opCat(bool b) const pure nothrow BitArray opBinary(string op)(bool b) const pure nothrow
if (op == "~")
{ {
BitArray r; BitArray r;
@ -2150,7 +2151,8 @@ public:
} }
/** ditto */ /** ditto */
BitArray opCat_r(bool b) const pure nothrow BitArray opBinaryRight(string op)(bool b) const pure nothrow
if (op == "~")
{ {
BitArray r; BitArray r;
@ -2162,7 +2164,8 @@ public:
} }
/** ditto */ /** ditto */
BitArray opCat(BitArray b) const pure nothrow BitArray opBinary(string op)(BitArray b) const pure nothrow
if (op == "~")
{ {
BitArray r; BitArray r;

View file

@ -599,7 +599,8 @@ public:
// All of these member functions create a new BigUint. // All of these member functions create a new BigUint.
// return x >> y // return x >> y
BigUint opShr(Tulong)(Tulong y) pure nothrow const if (is (Tulong == ulong)) BigUint opBinary(string op, Tulong)(Tulong y) pure nothrow const
if (op == ">>" && is (Tulong == ulong))
{ {
assert(y>0); assert(y>0);
uint bits = cast(uint) y & BIGDIGITSHIFTMASK; uint bits = cast(uint) y & BIGDIGITSHIFTMASK;
@ -622,7 +623,8 @@ public:
} }
// return x << y // return x << y
BigUint opShl(Tulong)(Tulong y) pure nothrow const if (is (Tulong == ulong)) BigUint opBinary(string op, Tulong)(Tulong y) pure nothrow const
if (op == "<<" && is (Tulong == ulong))
{ {
assert(y>0); assert(y>0);
if (isZero()) return this; if (isZero()) return this;

View file

@ -1069,14 +1069,16 @@ public:
is(typeof(opLogic!(T, op)(lhs)))) is(typeof(opLogic!(T, op)(lhs))))
{ return opLogic!(T, op)(lhs); } { return opLogic!(T, op)(lhs); }
///ditto ///ditto
VariantN opCat(T)(T rhs) VariantN opBinary(string op, T)(T rhs)
if (op == "~")
{ {
auto temp = this; auto temp = this;
temp ~= rhs; temp ~= rhs;
return temp; return temp;
} }
// ///ditto // ///ditto
// VariantN opCat_r(T)(T rhs) // VariantN opBinaryRight(string op, T)(T rhs)
// if (op == "~")
// { // {
// VariantN temp = rhs; // VariantN temp = rhs;
// temp ~= this; // temp ~= this;

View file

@ -693,7 +693,7 @@ class Element : Item
this(string name, string interior=null) @safe pure this(string name, string interior=null) @safe pure
{ {
this(new Tag(name)); this(new Tag(name));
if (interior.length != 0) opCatAssign(new Text(interior)); if (interior.length != 0) opOpAssign!("~")(new Text(interior));
} }
/** /**
@ -722,7 +722,8 @@ class Element : Item
* element ~= new Text("hello"); * element ~= new Text("hello");
* -------------- * --------------
*/ */
void opCatAssign(Text item) @safe pure void opOpAssign(string op)(Text item) @safe pure
if (op == "~")
{ {
texts ~= item; texts ~= item;
appendItem(item); appendItem(item);
@ -740,7 +741,8 @@ class Element : Item
* element ~= new CData("hello"); * element ~= new CData("hello");
* -------------- * --------------
*/ */
void opCatAssign(CData item) @safe pure void opOpAssign(string op)(CData item) @safe pure
if (op == "~")
{ {
cdatas ~= item; cdatas ~= item;
appendItem(item); appendItem(item);
@ -758,7 +760,8 @@ class Element : Item
* element ~= new Comment("hello"); * element ~= new Comment("hello");
* -------------- * --------------
*/ */
void opCatAssign(Comment item) @safe pure void opOpAssign(string op)(Comment item) @safe pure
if (op == "~")
{ {
comments ~= item; comments ~= item;
appendItem(item); appendItem(item);
@ -776,7 +779,8 @@ class Element : Item
* element ~= new ProcessingInstruction("hello"); * element ~= new ProcessingInstruction("hello");
* -------------- * --------------
*/ */
void opCatAssign(ProcessingInstruction item) @safe pure void opOpAssign(string op)(ProcessingInstruction item) @safe pure
if (op == "~")
{ {
pis ~= item; pis ~= item;
appendItem(item); appendItem(item);
@ -796,7 +800,8 @@ class Element : Item
* // appends element representing <br /> * // appends element representing <br />
* -------------- * --------------
*/ */
void opCatAssign(Element item) @safe pure void opOpAssign(string op)(Element item) @safe pure
if (op == "~")
{ {
elements ~= item; elements ~= item;
appendItem(item); appendItem(item);
@ -811,16 +816,16 @@ class Element : Item
private void parse(ElementParser xml) private void parse(ElementParser xml)
{ {
xml.onText = (string s) { opCatAssign(new Text(s)); }; xml.onText = (string s) { opOpAssign!("~")(new Text(s)); };
xml.onCData = (string s) { opCatAssign(new CData(s)); }; xml.onCData = (string s) { opOpAssign!("~")(new CData(s)); };
xml.onComment = (string s) { opCatAssign(new Comment(s)); }; xml.onComment = (string s) { opOpAssign!("~")(new Comment(s)); };
xml.onPI = (string s) { opCatAssign(new ProcessingInstruction(s)); }; xml.onPI = (string s) { opOpAssign!("~")(new ProcessingInstruction(s)); };
xml.onStartTag[null] = (ElementParser xml) xml.onStartTag[null] = (ElementParser xml)
{ {
auto e = new Element(xml.tag); auto e = new Element(xml.tag);
e.parse(xml); e.parse(xml);
opCatAssign(e); opOpAssign!("~")(e);
}; };
xml.parse(); xml.parse();