Real World usage of D, Today (was Re: challenge #2: implement the varargs_reduce metafunction)

Sean Kelly sean at
Sat Jan 27 09:34:48 PST 2007

Andrei Alexandrescu (See Website For Email) wrote:
> Kevin Bealer wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
> [about deducing storage types]
>>> The syntax that I am proposing does away with storageof and is very 
>>> much in spirit with the current D:
>>> S int foo(S, T)(S T t) { }
>>> It does exactly what it says it does, in a clear and terse manner, 
>>> and is 100% within the spirit of existing D:
>>> * It's customized on symbols S and T
>>> * It's matching (by sheer position of S and T) the storage (i.e., all 
>>> of the gooey fuzzy nice information about the argument passed) and 
>>> the type of the incoming argument
>>> * In this example it uses the storage in the result type (e.g. const 
>>> goes to const)
>>> * Inside the function can easily use either T separately or S T as a 
>>> group that transports the storage around. You have total flexibility 
>>> (and don't forget that juxtaposition is always easier than extraction).
>>> So far we're only thinking of storage-like attributes, but a good 
>>> deal of information can be encoded under the loose declaration of 
>>> "storage".
>>> Andrei
>> I like this; does this mean that when declaring an instance, you would 
>> do something like this?  Or do the 'const' parts get deduced?
>> alias Foo!(const, int) TheFoo;
> The intent is to deduce the storage, but specifying it explicitly works 
> just as well.
> There is strong resistance against my notation because manipulating the 
> storage class separately is something entirely new, which means a lot of 
> work in the compiler implementation. Also, S is not a type but a (new 
> kind of) alias, which might confuse people who read:
> template Foo(S, T)
> {
>   ...
> }
> and expect S and T to be types, just to discover in the body of the 
> template that S is actually a qualifier.
> The strawman we're discussing now looks like this:
> void foo(auto T)(T t) { }
> meaning, T will match whatever you throw at foo, including storage:
> int a = 5;
> foo(a);     // T == inout int
> foo(a + 1); // T == int

So how would one declare such a type?  typeof(T) perhaps?  I imagine 
there must be some way to separate the storage class from the type for 
this to work.


More information about the Digitalmars-d mailing list