On Sunday, 23 October 2016 at 06:36:21 UTC, Jonathan M Davis
wrote:
You can mark a parameter as ref, and you get something similar
to C++'s &, except that it only works on parameters, return
types, and the variable for the current element in a foreach
loop (you can't declare local variables
On Sunday, October 23, 2016 06:13:29 lumpyzhu via Digitalmars-d wrote:
> thanks..
> but structs are copy by value,
> In C++, I can use reference to avoid value-copy,
>
> --
> class MyClass {};
> void myFunc(const MyClass& a, MyClass& b) {...};
>
> {
>
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis
wrote:
On Thursday, October 20, 2016 06:59:12 lumpyzhu via
Digitalmars-d wrote:
std.stdio.File has reference counter inside,
why not std.stdio.File is class?
By using a struct with a reference count, you get deterministic
On Thursday, 20 October 2016 at 12:24:14 UTC, ketmar wrote:
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis
wrote:
In general, in D, if you don't need inheritance and
polymorphism, you probably shouldn't be using a class.
and even if you need, most of the time it is better to
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis
wrote:
In general, in D, if you don't need inheritance and
polymorphism, you probably shouldn't be using a class.
and even if you need, most of the time it is better to write
templated free functions with constraints instead. ;-)
On Thursday, 20 October 2016 at 07:40:05 UTC, Jonathan M Davis
wrote:
User-defined types that manage system resources are pretty much
always better off as structs so that they can have
deterministic destruction.
They could be reference counted classes if it played well with
the language.
On Thursday, October 20, 2016 06:59:12 lumpyzhu via Digitalmars-d wrote:
> std.stdio.File has reference counter inside,
> why not std.stdio.File is class?
By using a struct with a reference count, you get deterministic destruction,
and the file will be closed as soon as the reference count hits
std.stdio.File has reference counter inside,
why not std.stdio.File is class?