Can you constrain a type based on properties of what it is being referenced by?

aliak something at something.com
Fri Feb 2 14:19:37 UTC 2018


To further explain what I mean:

struct A if (!is(this == immutable) && !is(this == shared))
{
}

shared a = A() // error
auto a = A() // ok
immutable a = A() // error
const a = A() // ok

Fake syntax above of course.

I was thinking about this because I read a few posts about const, 
and approaching it via allowing an object to define a head 
mutable version of itself (see post in general forum by Simon for 
details [1])

And there're few constructs like RefCounted which don't make 
sense with an immutable qualifier.

And then there're situations where a mutable version does not 
make sense (I think this would be a much bigger application), ie: 
handles, resource identifiers, application configuration details, 
etc.

[1] 
https://forum.dlang.org/thread/cpxfgdmklgusodqouqdr@forum.dlang.org



More information about the Digitalmars-d-learn mailing list