|
|
|
|
|
by WalterBright
1298 days ago
|
|
Adds: 1. convenience 2. attractive appearance 3. ubiquity 4. better error messages (because compiler knows what they are) 5. one construct instead of two (vector and span) 6. overflow behavior selectable with compiler switch For example: #include <vector>
std::vector<int> v;
vs: int[] v;
Many D users have remarked that it's the single best feature of D. |
|
The primary goal of "concepts" appears to be to mitigate the awful error messages, but even for that it fails.
For example, let's imagine Hashable from any other language, and look at a C++ concept version:
and an implementation: Now how do we make sure Thing is actually going to conform to Hashable? with an assert of course, why would we want anything so gauche as declarative syntax? You can see the brilliant syntax explicitly disallows us specifying constraints on a concept, and instead we have to use the && expression. My personal belief here is that the banning of constraints in the template name is simply to force people to use logical composition so the people who thought of it can claim people like it.