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=="<<"))
{
// Sign never changes during left shift
data = data.opShl(u);
} else
data = data.opBinary!(op)(u);
}
else
{
data = data.opShr(u);
data = data.opBinary!(op)(u);
if (data.isZero())
sign = false;
}

View file

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

View file

@ -599,7 +599,8 @@ public:
// All of these member functions create a new BigUint.
// 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);
uint bits = cast(uint) y & BIGDIGITSHIFTMASK;
@ -622,7 +623,8 @@ public:
}
// 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);
if (isZero()) return this;

View file

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

View file

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