digitalmars.D - isRef, isLazy, isOut
- Eldar Insafutdinov (8/8) Dec 19 2009 Following the commits to the dmd repository I found these traits impleme...
- Andrei Alexandrescu (3/12) Dec 19 2009 I asked in vain for is(var == ref), is(var == out) etc.
- Walter Bright (2/3) Dec 19 2009 That's because 'is' works with types, not symbols. It didn't fit.
- Chris Nicholson-Sauls (3/7) Dec 20 2009 is(typeof(var) == ref) ?
- Walter Bright (2/9) Dec 20 2009 No, because ref is not part of the type. It's a storage class.
- Andrei Alexandrescu (6/16) Dec 20 2009 Speaking of isLazy - any fresh ideas on dissing lazy? FWIW we can
- Kasumi Hanazuki (16/20) Dec 20 2009 Nobody seemed to mention in the last thread, but D already has the
- Max Samukha (20/23) Dec 20 2009 Will there be a way to get storage classes from function symbols or type...
- Eldar Insafutdinov (2/34) Dec 20 2009 Please, please...
Following the commits to the dmd repository I found these traits implemented. The idea is good, but the API chosen does not look right. Why not have __traits(storageClass, symbol) and a enum which defines the return value: enum StorageClass { None, Ref, Lazy, Out } One could write templates isRef, isLazy etc on top of that if he/she really needs. IMO this is a cleaner way to implement this particular feature.
Dec 19 2009
Eldar Insafutdinov wrote:Following the commits to the dmd repository I found these traits implemented. The idea is good, but the API chosen does not look right. Why not have __traits(storageClass, symbol) and a enum which defines the return value: enum StorageClass { None, Ref, Lazy, Out } One could write templates isRef, isLazy etc on top of that if he/she really needs. IMO this is a cleaner way to implement this particular feature.I asked in vain for is(var == ref), is(var == out) etc. Andrei
Dec 19 2009
Andrei Alexandrescu wrote:I asked in vain for is(var == ref), is(var == out) etc.That's because 'is' works with types, not symbols. It didn't fit.
Dec 19 2009
Walter Bright wrote:Andrei Alexandrescu wrote:is(typeof(var) == ref) ? -- Chris Nicholson-SaulsI asked in vain for is(var == ref), is(var == out) etc.That's because 'is' works with types, not symbols. It didn't fit.
Dec 20 2009
Chris Nicholson-Sauls wrote:Walter Bright wrote:No, because ref is not part of the type. It's a storage class.Andrei Alexandrescu wrote:is(typeof(var) == ref) ?I asked in vain for is(var == ref), is(var == out) etc.That's because 'is' works with types, not symbols. It didn't fit.
Dec 20 2009
Walter Bright wrote:Chris Nicholson-Sauls wrote:Speaking of isLazy - any fresh ideas on dissing lazy? FWIW we can replace it with the conversion of expressions to delegates. The resulting situation is liable to a few ambiguities but is much better than lazy. AndreiWalter Bright wrote:No, because ref is not part of the type. It's a storage class.Andrei Alexandrescu wrote:is(typeof(var) == ref) ?I asked in vain for is(var == ref), is(var == out) etc.That's because 'is' works with types, not symbols. It didn't fit.
Dec 20 2009
(2009/12/21 4:43), Andrei Alexandrescu wrote:Speaking of isLazy - any fresh ideas on dissing lazy? FWIW we can replace it with the conversion of expressions to delegates. The resulting situation is liable to a few ambiguities but is much better than lazy.Nobody seemed to mention in the last thread, but D already has the implicit expression-to-delegate conversion in the type-safe variadic parameters. (only available in the last part of parameters though...) Can we merge lazy with it? ---- void f(void delegate()[1] gs...) { gs[0](); gs[0](); } void g() { writeln(42); } void main() { f(g()); }
Dec 20 2009
On 19.12.2009 23:00, Walter Bright wrote:Andrei Alexandrescu wrote:Will there be a way to get storage classes from function symbols or types? Currently, we have to use a Signature template that, along with parameter and return types, extracts storage classes by parsing the value of parameter type tuple's stringof. Ugly and unreliable. We need a way to do it without resorting to hacks. Something in this vein: enum StorageClasses { ... } class A { ref int foo(const ref int a, lazy int b) const; void bar(out a); } assert(__traits(storageClasses, A.foo) == StorageClasses.Const | StorageClasses.Ref); assert(__traits(parameterStorageClasses, A.foo) == [StorageClasses.Const | StorageClasses.Ref, StorageClasses.Lazy]); See also http://d.puremagic.com/issues/show_bug.cgi?id=1818I asked in vain for is(var == ref), is(var == out) etc.That's because 'is' works with types, not symbols. It didn't fit.
Dec 20 2009
Max Samukha Wrote:On 19.12.2009 23:00, Walter Bright wrote:Please, please...Andrei Alexandrescu wrote:Will there be a way to get storage classes from function symbols or types? Currently, we have to use a Signature template that, along with parameter and return types, extracts storage classes by parsing the value of parameter type tuple's stringof. Ugly and unreliable. We need a way to do it without resorting to hacks. Something in this vein: enum StorageClasses { ... } class A { ref int foo(const ref int a, lazy int b) const; void bar(out a); } assert(__traits(storageClasses, A.foo) == StorageClasses.Const | StorageClasses.Ref); assert(__traits(parameterStorageClasses, A.foo) == [StorageClasses.Const | StorageClasses.Ref, StorageClasses.Lazy]); See also http://d.puremagic.com/issues/show_bug.cgi?id=1818I asked in vain for is(var == ref), is(var == out) etc.That's because 'is' works with types, not symbols. It didn't fit.
Dec 20 2009