www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Hopefully not-too-obvious observation

reply Jerry <jlquinn optonline.net> writes:
Hi folks,

I was looking at writing a hash-like class with a specific operator and
disliking the syntax of:

T opBinary(string op)(U key) if (op == "in") {}

When it occurred to me that it could be simply tightened up as:

T opBinary(string op : "in")(U key) {}

Any thoughts?  Is this bad style?

Thanks
Jerry
Jul 17 2013
next sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On 2013-07-18, 04:50, Jerry wrote:

 Hi folks,

 I was looking at writing a hash-like class with a specific operator and
 disliking the syntax of:

 T opBinary(string op)(U key) if (op == "in") {}

 When it occurred to me that it could be simply tightened up as:

 T opBinary(string op : "in")(U key) {}

 Any thoughts?  Is this bad style?
It's how I write my operator overloads unless the function should match several of them. So no, I think it's good style. But that's just, like, my opinion, man. -- Simen
Jul 18 2013
prev sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Wed, 17 Jul 2013 22:50:09 -0400
schrieb Jerry <jlquinn optonline.net>:

 Hi folks,
 
 I was looking at writing a hash-like class with a specific operator and
 disliking the syntax of:
 
 T opBinary(string op)(U key) if (op == "in") {}
 
 When it occurred to me that it could be simply tightened up as:
 
 T opBinary(string op : "in")(U key) {}
 
 Any thoughts?  Is this bad style?
 
 Thanks
 Jerry
I write it like that, too. It's more readable with the "in" closer to the method name. -- Marco
Jul 19 2013