Proper way to handle "alias this" deprecation for classes
Chris Piker
chris at hoopjump.com
Sun May 7 17:55:29 UTC 2023
Hi D
One of the dependencies for my project has a class that makes use
of the `alias x this` construct. According to dmd 2.103, alias
this is deprecated for classes, so I'd like to correct the
problem.
Is there a specific paragraph or two that I can read to find out
what is the appropriate replacement construct? On a related
note, has anyone created a code maintenance guide to help
work-a-day programmers navigate recent changes to the D language?
For reference, here's a the code in question (from dpq2,
result.d):
```d
package immutable final class ResultContainer
{
version(Dpq2_Dynamic)
{
import dpq2.dynloader: ReferenceCounter;
private ReferenceCounter dynLoaderRefCnt;
}
// ResultContainer allows only one copy of PGresult* due to
avoid
// double free. For the same reason this class is declared as
final.
private PGresult* result;
alias result this; //<---- Deprecation Warning Here
package this(immutable PGresult* r)
{
assert(r);
result = r;
version(Dpq2_Dynamic) dynLoaderRefCnt =
ReferenceCounter(true);
}
...
```
Thanks for any pointers,
More information about the Digitalmars-d-learn
mailing list