Do non-member functions improve encapsulation in D?
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 21 09:40:57 PDT 2014
On Monday, 21 April 2014 at 16:35:23 UTC, Artur Skawina via
Digitalmars-d wrote:
> On 04/21/14 14:45, Steven Schveighoffer via Digitalmars-d wrote:
>> Reasons off the top of my head not to make them module
>> functions:
>
> [...]
>
> Functions, unlike methods, do not work with rvalues.
>
> Ie
>
> struct S {
> long[999999] data;
> auto f() { return data[0]; }
> }
>
> auto g(ref S _this) { with (_this) return data[1]; }
>
> void main() {
> auto a = S().f();
> auto b = S().g();
> }
>
> artur
Shouldn't this be possible if you want to make g a template
function and use auto ref? Regardless, it doesn't. Probably a
compiler bug:
struct S {
long[999999] data;
auto f() { return data[0]; }
}
//No good
//auto g(T: S)(auto ref T _this) { with (_this) return data[1];
}
//Doesn't work either
//auto g()(auto ref S _this) { with (_this) return data[1]; }
void main() {
auto a = S().f();
auto b = S().g();
}
More information about the Digitalmars-d
mailing list