D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3988 - Provide canonical example for operator overloading
Summary: Provide canonical example for operator overloading
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL: http://digitalmars.com/d/2.0/operator...
Keywords: spec
Depends on:
Blocks:
 
Reported: 2010-03-19 23:19 UTC by Jerry Quinn
Modified: 2014-02-15 02:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jerry Quinn 2010-03-19 23:19:43 UTC
At first glance, the new operator overloading syntax looks cumbersome by comparison to C++.  Adding the following example to the D docs would make it clear what the advantage of the new syntax is, as well as not requiring people to reinvent it repeatedly:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=101636

2. Use one mixin expression:

T opBinary(string op)(T rhs) {
     return mixin("data "~op~" rhs.data");
}