D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7840 - $ property for arrays
Summary: $ property for arrays
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-05 18:05 UTC by bearophile_hugs
Modified: 2019-08-29 17:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-04-05 18:05:40 UTC
This is a low-priority and low-importance "enhancement suggestion" (it's not even an enhancement request because I am not sure if this is a good idea. I will close it if you think it's a bad idea).

Currently you are allowed to use $ to denote array lengths inside their [], like this:
arr[$ - 1]

The idea here is to extend the $ syntax as suffix too, something like this:


@property size_t __dollar(T)(in T[] a) pure nothrow {
    return a.length;
}
void main() {
    int[5] a;
    auto len = a.$;
}


This shortens the code, and this code isn't harder to understand because D programmers already know that $ means the length of the array.
Comment 1 yebblies 2013-01-16 18:56:38 UTC
I would consider this a bad idea, but that's just me.
Comment 2 Mathias LANG 2019-08-29 17:34:05 UTC
Yup, sounds like a bad idea, and I'm pretty sure a lot of people would oppose this.
So going to close this as non-actionable.