digitalmars.D.learn - Tail-constness of class parameters
- =?UTF-8?B?Tm9yZGzDtnc=?= (26/26) Dec 25 2017 In a graph library I'm working on I have the following algorithm
- ag0aep6g (2/3) Dec 25 2017 https://dlang.org/phobos/std_typecons.html#Rebindable
- =?UTF-8?B?Tm9yZGzDtnc=?= (2/3) Dec 25 2017 Thanks.
In a graph library I'm working on I have the following algorithm
bool hasContext(Node sub, // TODO in
Node sup) nothrow // TODO in
{
Node curr = sub;
while (true)
{
Node ctx = curr.context;
if (!ctx) { break;}
if (ctx is sup)
return true;
else
curr = ctx;
}
return false;
}
When I qualify the parameters `sub`, `sup` and `curr` with const,
the assignment
curr = ctx;
fails.
1. Is there a way to express tail-constness on the parameters
without having to qualify this function with trusted to enable
an ugly const-cast to allow the assignment `curr = ctx` to
compile?
2. An alternative solution is to make the function recursive. But
will that be as efficient?
Dec 25 2017
On Monday, 25 December 2017 at 14:49:11 UTC, Nordlöw wrote:1. Is there a way to express tail-constness on the parametershttps://dlang.org/phobos/std_typecons.html#Rebindable
Dec 25 2017
On Monday, 25 December 2017 at 15:16:55 UTC, ag0aep6g wrote:https://dlang.org/phobos/std_typecons.html#RebindableThanks.
Dec 25 2017








=?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com>