ref on hidden this param
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sun Oct 5 06:56:27 UTC 2025
On 05/10/2025 7:49 PM, TwoOfCups wrote:
> On Sunday, 5 October 2025 at 05:58:10 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> On 05/10/2025 6:55 PM, TwoOfCups wrote:
>>> Well in my case I am wanting it for a specific templated
>>> serialization scenario where the serializer has the ability to use a
>>> proxy type to serialize as a proxy type instead of serializing it
>>> directly. And i was wanting to serialize objects as a uuid and on
>>> deserialization do a look up to find it but would need to reassign
>>> the lvalue to make it work..
>>
>> A small example of this, where the proposed feature is used would be
>> very welcome.
>>
>> I'm having trouble picturing the types and their interaction to each
>> other.
>
> ```
> class C {
> int uuid;
> int toSerial(){ // int is the proxy type
> return uuid;
> }
> void fromSerial(int i){
> // do uuid lookup and assign this if this could be ref
> }
> }
>
> ...
>
> during serialization check if type has a toSerial and call that instead
> of serialized directly, in this case uuid will be written instead of the
> class contents. the actual class contents will be serialized else where
> ```
Okay so the class is memorized (somehow, doesn't matter).
You have the ability to access and reflect upon the class at compile time.
Why not use a static method instead?
```d
class C {
...
static C fromSerial(int i) {
C self = ...; // lookup i for C
return self;
}
}
```
More information about the Digitalmars-d
mailing list