Additional type information

Volodymyr via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 10:21:08 PDT 2015


"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?


More information about the Digitalmars-d mailing list