On Saturday, 9 January 2021 at 21:57:43 UTC, sighoya wrote:
On Saturday, 9 January 2021 at 20:20:38 UTC, Q. Schroll wrote:
That's not what I mean. You copy the reference. That's not
what referencing meant.
Derived d = new Derived();
Base* bp = &d; // fails
const(Base) cbp = &d; // compil
On Saturday, 9 January 2021 at 20:20:38 UTC, Q. Schroll wrote:
That's not what I mean. You copy the reference. That's not what
referencing meant.
Derived d = new Derived();
Base* bp = &d; // fails
const(Base) cbp = &d; // compiles.
Generally, allowing covariant assignment for the Ptr, i
On Saturday, 9 January 2021 at 20:39:26 UTC, Ali Çehreli wrote:
On 1/9/21 12:35 PM, Ali Çehreli wrote:
> alias lightLoadOperation = memoize!heavyLoadOperation;
>
>const l = lightLoadOperation();
Well, that doesn't work the way you want but this does:
if (args.length == 1) {
writefln!
Explicit with a lambda:
import std;
int heavyLoadOperation() {
writeln("Expensive!");
return uniform(0, 10);
}
void main(string[] args) {
const l = {
bool inited = false;
static int i;
if (!inited) {
i = heavyLoadOperation();
}
return i;
}();
if (args.length
On 1/9/21 12:35 PM, Ali Çehreli wrote:
> alias lightLoadOperation = memoize!heavyLoadOperation;
>
>const l = lightLoadOperation();
Well, that doesn't work the way you want but this does:
if (args.length == 1) {
writefln!"Using lazy variable: %s %s"(lightLoadOperation(),
lightLoadOper
On Saturday, 9 January 2021 at 20:00:35 UTC, Jacob Carlborg wrote:
On 2021-01-09 19:16, Q. Schroll wrote:
Say I have a class hierarchy like this:
class Base { }
class Derived : Base { }
A Derived object cannot be referenced as a Base object, but as
a const(Base) object. That makes sense t
In c# we can do something like this:
static Lazy lazy =
new Lazy
(() => heavyLoadOperation());
static T value { get { return lazy.Value; } }
and heavyLoadOperation() is only called when variable "value" is
actually used. How can I do something like this in D?
I've tried
On 2021-01-09 19:16, Q. Schroll wrote:
Say I have a class hierarchy like this:
class Base { }
class Derived : Base { }
A Derived object cannot be referenced as a Base object, but as a
const(Base) object. That makes sense to me.
It can:
Base b = new Derived();
One can replace Base by a
Why does dirEntries in std/file.d do that (POSIX version)?:
for (dirent* fdata; (fdata = readdir(_stack[$-1].h))
!= null; )
{
// Skip "." and ".."
if (core.stdc.string.strcmp(&fdata.d_name[0],
".") &&
core.stdc.string.
Say I have a class hierarchy like this:
class Base { }
class Derived : Base { }
A Derived object cannot be referenced as a Base object, but as a
const(Base) object. That makes sense to me.
One can replace Base by a @system delegate type (SysDG) and
Derived by a @safe delegate type (SafeDG)
10 matches
Mail list logo