digitalmars.D.bugs - [Issue 11615] New: Syntax to indicate auto return type is const
- d-bugmail puremagic.com (44/44) Nov 27 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11615
https://d.puremagic.com/issues/show_bug.cgi?id=11615 Summary: Syntax to indicate auto return type is const Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: joseph.wakeling webdrake.net 2013-11-27 01:28:42 PST --- This enhancement request is a result of the following discussion on D.learn: http://forum.dlang.org/thread/mailman.34.1385370339.3242.digitalmars-d-learn puremagic.com Consider a struct or class which contains a method that allows one to access internal data, e.g.: struct Foo { int[] _arr = [0, 1, 2, 3, 4]; auto arr() property { return _arr; } } The problem with this is that what is returned by the .arr property allows write access to the internal array _arr. This can be solved by making the return type declaration more explicit: const(int)[] arr() property { return _arr; } However, it would be nice to be able to indicate and obtain such non-writeable return types with the use of auto. The syntax const(auto) seems nice here. The fundamental goal would be simply: "You can't write to this data via this handle." The aim is to simplify generic programming situations by allowing the programmer to specifically protect against any accidental opening up of private data to external write access. Note that applying the regular const keyword won't work here, because this implies a const _method_ (which is a stricter requirement than just a const return type). -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 27 2013