| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
March 16, 2015 Additional type information | ||||
|---|---|---|---|---|
| ||||
"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? | ||||
March 16, 2015 Re: Additional type information | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Volodymyr | 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. | |||
March 16, 2015 Re: Additional type information | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On Monday, 16 March 2015 at 18:11:52 UTC, Idan Arye wrote:
> But `const` and `ref` do change type - http://dpaste.dzfl.pl/57b4086c5644.
>
> There simply is an implicit conversions between them and the unqualified types.
`const` does, but `ref` doesn't. You can check that by inserting `pragma(msg, typeof(x));` into the functions in your example. But there's nevertheless overloading for `ref`.
| |||
March 17, 2015 Re: Additional type information | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | On Monday, 16 March 2015 at 19:52:07 UTC, Marc Schütz wrote:
> `const` does, but `ref` doesn't. You can check that by inserting `pragma(msg, typeof(x));` into the functions in your example. But there's nevertheless overloading for `ref`.
Yeah... You are right, it is unclear and bad example :)
And the tags may change a type because they change some rules for the type.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply