April 22, 2014
On 04/22/2014 02:06 PM, Brian Schott wrote:
> On Tuesday, 22 April 2014 at 17:43:58 UTC, Daniel Murphy wrote:
>> Of course we can.
> 
> We have "alias a = b;" and "alias b a;", so there's precedent for having two ways of doing exactly the same thing.
Except that's another case of "we had one way to do it, we want to move to a different way", isn't it?

-- 
Matt Soucy
http://msoucy.me/
April 22, 2014
Brian Schott:

> We have "alias a = b;" and "alias b a;", so there's precedent for having two ways of doing exactly the same thing.

I've just filed a bug report:
https://issues.dlang.org/show_bug.cgi?id=12615

Bye,
bearophile
April 22, 2014
On Tuesday, 22 April 2014 at 15:50:21 UTC, Daniel Murphy wrote:
> "Andrej Mitrovic"  wrote in message news:ifghzjafvfqrqkhlpinc@forum.dlang.org...
>
>> Old-style operator overloads (such as opCom, opAnd, etc) have largely been superseded by new-style templated operator overloads (opUnary, opBinary, etc).
>
> I prefer the old ones mainly because the names are better and the code easier to read.  When you are implementing one operator per function (ie most of the time) the extra template syntax is just unnecessary noise.
>
> T opMul(T other)
>
> vs
>
> T opBinary(string op : "*")(T other)
>
> The old names were chosen to match what the operations were supposed to be, not for the syntax.  In that regard the new syntax is a step backwards.

Does this work if test is in a different module from main?

struct test
{
	private int opBinary(string op: "*")(test other) { return 3; }
	public alias opMul = opBinary!"*";
}

void main()
{
	test t1 = test();
	test t2 = test();
	auto n = t1 * t2;
	assert(n == 3);
}
April 22, 2014
On Tuesday, 22 April 2014 at 21:35:31 UTC, Meta wrote:
> Does this work if test is in a different module from main?
>
> struct test
> {
> 	private int opBinary(string op: "*")(test other) { return 3; }
> 	public alias opMul = opBinary!"*";
> }
>
> void main()
> {
> 	test t1 = test();
> 	test t2 = test();
> 	auto n = t1 * t2;
> 	assert(n == 3);
> }

And it appears it does.
April 23, 2014
On 22/04/14 20:06, Brian Schott wrote:

> We have "alias a = b;" and "alias b a;", so there's precedent for having
> two ways of doing exactly the same thing.

I believe that for aliasing function pointers only the latter syntax works.

-- 
/Jacob Carlborg
April 23, 2014
On Tue, 22 Apr 2014 18:54:41 -0400, Meta <jared771@gmail.com> wrote:

> On Tuesday, 22 April 2014 at 21:35:31 UTC, Meta wrote:
>> Does this work if test is in a different module from main?
>>
>> struct test
>> {
>> 	private int opBinary(string op: "*")(test other) { return 3; }
>> 	public alias opMul = opBinary!"*";
>> }
>>
>> void main()
>> {
>> 	test t1 = test();
>> 	test t2 = test();
>> 	auto n = t1 * t2;
>> 	assert(n == 3);
>> }
>
> And it appears it does.

This changes the dynamics. opMul is not a template, which is important for classes.

This also works, and if encapsulated into a mixin, will be a drop-in fix for existing opMul and friends code:

struct test
{
   alias opBinary(string op: "*") = blah; // to demonstrate it's not actually calling opMul because of old-style operators

   int blah(test other) {return 3;}
}

BTW, I don't know when template alias got so cool, but I like it :)

-Steve
April 23, 2014
Jacob Carlborg:

> I believe that for aliasing function pointers only the latter syntax works.

It's a bug that needs to be fixed before the deprecation of old style alias syntax...

Bye,
bearophile
1 2
Next ›   Last »