What is the shortest way to define an immutable token of unique type?

Petar Petar
Sun Mar 14 19:35:25 UTC 2021


On Sunday, 14 March 2021 at 19:23:33 UTC, Adam D. Ruppe wrote:
> On Sunday, 14 March 2021 at 19:10:19 UTC, Petar Kirov 
> [ZombineDev] wrote:
>> Unfortunately, unlike struct values, classes objects can't 
>> pass through from CTFE to RT, which makes them limited for 
>> certain use cases (e.g. you can't put the statement above at 
>> the module scope).
>
> Yes they can. The limitation is class objects cannot be enums 
> and passing as template arguments is not allowed (I believe the 
> error is caught at codegen though so avoid codegen, avoid 
> error, but still).
>
> [...]

I think my point still stands :P

You can use class objects inside CTFE, but they can't exit 
unchanged - you can't really use them to initialize class 
variables and more importantly, if you convert a class object to 
a struct value, you loose the object identity, so you can't quite 
emulate [1].

[1]: https://developer.mozilla.org/en-US/docs/Glossary/Symbol



More information about the Digitalmars-d mailing list