digitalmars.D.learn - Why do std.traits use template foo(args...) instead of foo(alias arg)
- Mathias LANG (3/3) Dec 18 2014 An exemple being fullyQualifiedName:
- Low Functioning (2/5) Dec 18 2014 http://dlang.org/variadic-function-templates.html
- ketmar via Digitalmars-d-learn (31/38) Dec 18 2014 On Thu, 18 Dec 2014 15:52:06 +0000
- Steven Schveighoffer (7/20) Dec 18 2014 s/types/keywords
- ketmar via Digitalmars-d-learn (5/31) Dec 18 2014 On Thu, 18 Dec 2014 11:26:20 -0500
- Dicebot (9/12) Dec 18 2014 Full pattern looks like this:
- Mathias LANG (3/17) Dec 18 2014 Thanks for the precision. Is it something that is going to be
- Dicebot (6/8) Dec 18 2014 It is something that most likely would have been designed
An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415 I don't get this pattern. Is it documented somewhere ?
Dec 18 2014
On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415 I don't get this pattern. Is it documented somewhere ?http://dlang.org/variadic-function-templates.html
Dec 18 2014
On Thu, 18 Dec 2014 15:52:06 +0000 Low Functioning via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:.d#L415An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/traits=that's not a question about "what it does?", but the question about "why it did this way?" the answer is simple: `alias` arguments can't accept types. i.e. template t0(T...) if (T.length =3D=3D 1) { enum t0 =3D T[0].stringof; } template t1(alias T) { enum t1 =3D T.stringof; } pragma(msg, t0!int); pragma(msg, t1!int); int test.d(11): Error: template instance t1!int does not match template decla= ration t1(alias T) test.d(11): while evaluating pragma(msg, t1!int) but: int a; pragma(msg, t0!a); pragma(msg, t1!a); gives: a a i.e. (T...) can accept both types and symbols, and `alias` can accept only symbols. `fullyQualifiedName` then checks if T is symbol or type: static if (is(T)) ... // T is a type, process as type else ... // T is a symbold, process as symbolI don't get this pattern. Is it documented somewhere ?=20 http://dlang.org/variadic-function-templates.html
Dec 18 2014
On 12/18/14 11:21 AM, ketmar via Digitalmars-d-learn wrote:On Thu, 18 Dec 2014 15:52:06 +0000 Low Functioning via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:s/types/keywords alias can accept types as long as they are symbols. For instance: struct S {} pragma(msg, t1!S); // works. -SteveOn Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:that's not a question about "what it does?", but the question about "why it did this way?" the answer is simple: `alias` arguments can't accept types. i.e.An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/traits..d#L415 I don't get this pattern. Is it documented somewhere ?http://dlang.org/variadic-function-templates.html
Dec 18 2014
On Thu, 18 Dec 2014 11:26:20 -0500 Steven Schveighoffer via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:On 12/18/14 11:21 AM, ketmar via Digitalmars-d-learn wrote:ts..d#L415On Thu, 18 Dec 2014 15:52:06 +0000 Low Functioning via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/trai=yes, thank you. bad wording on my side.=20 s/types/keywords =20 alias can accept types as long as they are symbols. =20 For instance: =20 struct S {} =20 pragma(msg, t1!S); // works.that's not a question about "what it does?", but the question about "why it did this way?" the answer is simple: `alias` arguments can't accept types. i.e.I don't get this pattern. Is it documented somewhere ?http://dlang.org/variadic-function-templates.html
Dec 18 2014
On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415 I don't get this pattern. Is it documented somewhere ?Full pattern looks like this: template foo(T...) if (T.length == 1) This is a way to workaround D template argument limitation - you can't have any parameter that accepts both types and symbols (`alias T` and `T` at once) other than variadic parameter. Limit variadic length to 1 and you emulate such "accepts anything" parameter.
Dec 18 2014
On Thursday, 18 December 2014 at 16:10:31 UTC, Dicebot wrote:On Thursday, 18 December 2014 at 15:48:02 UTC, Mathias LANG wrote:Thanks for the precision. Is it something that is going to be fixed, or is it by design ?An exemple being fullyQualifiedName: https://github.com/D-Programming-Language/phobos/blob/master/std/traits.d#L415 I don't get this pattern. Is it documented somewhere ?Full pattern looks like this: template foo(T...) if (T.length == 1) This is a way to workaround D template argument limitation - you can't have any parameter that accepts both types and symbols (`alias T` and `T` at once) other than variadic parameter. Limit variadic length to 1 and you emulate such "accepts anything" parameter.
Dec 18 2014
On Thursday, 18 December 2014 at 17:20:28 UTC, Mathias LANG wrote:Thanks for the precision. Is it something that is going to be fixed, or is it by design ?It is something that most likely would have been designed differently if we had another chance (aka D3) but unlikely to change in D2 as existing pattern works good enough in practice. It is confusing but usually only needed for power user libraries thus learning curve impact is low.
Dec 18 2014