Additional type information

Idan Arye via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 11:11:51 PDT 2015


On Monday, 16 March 2015 at 17:21:10 UTC, Volodymyr wrote:
> "const" and "ref" actually don't change type but add(remove?) 
> some constraints. They are somthing like tags on type. Extended 
> tags system can add more constraints! E. g. to manage objects 
> allocated using different allocators and prevent minxing memory 
> operations based on different allocators:
>
> @allocatedBy(GCAllocator) auto a = new Widget;
> auto b = new Widget; // deduce @allocatedBy(GCAlloactor)
>
> @allocatedBy(Mallocator) auto c = // allocate array on OS heap
> c ~= [3, 4, 5]; // Error! Allocator don't match. This operator 
> use GC
> // Or even more:
> c ~= [3, 4, 5]; // extend array using Mallocator
>
> These tags may be created by user, cooperate with annotations 
> on functions or types (they are annotations), be removed or 
> added with "cast", take part in overloading, apply automatic 
> deduction for itself. It is compile time type informaion that 
> can be used if needed and ommited if not.
>
> So how about the thing?

But `const` and `ref` do change type - 
http://dpaste.dzfl.pl/57b4086c5644.

There simply is an implicit conversions between them and the 
unqualified types.


More information about the Digitalmars-d mailing list