Re: Better way to compromise on the lack of template alias resolution stuff?

2023-03-15 Thread Elfstone via Digitalmars-d-learn
On Wednesday, 15 March 2023 at 19:22:32 UTC, Paul Backus wrote: On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote: [...] Currently the best workaround for this is to define `Vector` as a `struct` with `alias this` instead of as an `alias`: ```d struct Matrix(S, size_t M, size_t N) {

Re: Better way to compromise on the lack of template alias resolution stuff?

2023-03-15 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote: I went back to some of my old code and couldn't stand what I had ended up with - If I already have a well-defined `Vector`, why do I have to write extra code to implement `isVector`, and use `isVector` instead of simply declaring the pa

Re: Better way to compromise on the lack of template alias resolution stuff?

2023-03-14 Thread Elfstone via Digitalmars-d-learn
eters, because D simply won't match template alias parameters, and I could not find a way to create a constraint based on an existing alias, which defeats the supposed meaning and purpose of `alias`. I hope some Samaritan in the community will actually "see the value" in this, pic

Re: Better way to compromise on the lack of template alias resolution stuff?

2023-03-14 Thread ionkare via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote: ```D struct Matrix(S, size_t M, size_t N) { } alias Vector(S, size_t N) = Matrix!(S, N, 1); enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it doesn't work enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N);

Better way to compromise on the lack of template alias resolution stuff?

2023-03-14 Thread Elfstone via Digitalmars-d-learn
```D struct Matrix(S, size_t M, size_t N) { } alias Vector(S, size_t N) = Matrix!(S, N, 1); enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it doesn't work enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N); // the "correct" way and how much I like to REPEAT myself!

Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Elfstone via Digitalmars-d-learn
On Friday, 24 February 2023 at 15:28:18 UTC, Steven Schveighoffer wrote: On 2/24/23 7:00 AM, Elfstone wrote: Seems like the same bug is still there after ten years. `static` should not affect module-level functions, but also, this code should work without `static`. Reported, not sure if t

Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Paul Backus via Digitalmars-d-learn
On Friday, 24 February 2023 at 14:22:17 UTC, user1234 wrote: you can break using `goto`, restore `static` everywhere, and using local introspection determine whether the result exists. ```d struct Bar { @("hello") int t; } static bool hasAttribute(alias F, T)() { static foreach

Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/23 7:00 AM, Elfstone wrote: Seems like the same bug is still there after ten years. `static` should not affect module-level functions, but also, this code should work without `static`. Reported, not sure if there's a previous bug, it was hard to come up with a good description:

Re: Template alias parameter: error: need 'this' for ...

2023-02-24 Thread user1234 via Digitalmars-d-learn
On Friday, 24 February 2023 at 12:00:41 UTC, Elfstone wrote: Seems like the same bug is still there after ten years. ```d struct Bar { @("hello") int t; } static bool hasAttribute(alias F, T)() { bool result = false;

Template alias parameter: error: need 'this' for ...

2023-02-24 Thread Elfstone via Digitalmars-d-learn
https://forum.dlang.org/post/imnannjdgtjnlzevh...@forum.dlang.org On Saturday, 24 August 2013 at 11:47:43 UTC, Matej Nanut wrote: On Friday, 23 August 2013 at 22:54:33 UTC, Jonathan M Davis wrote: Because without static it's a member variable, which means that you have to have a constructed obj

Re: Template + alias + basic type depends on another parameter = broken?

2023-02-23 Thread Elfstone via Digitalmars-d-learn
On Wednesday, 22 February 2023 at 20:20:46 UTC, Dark Hole wrote: I'm trying to rewrite really old D code. There was fragment like that: ```d template Foo(T, T[] Array) { // ... } // ... Bar[] arr; Foo!(Bar, arr); ``` This gives error `can't read arr in compile time`. Small changes: ```d t

Re: Template + alias + basic type depends on another parameter = broken?

2023-02-22 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 22 February 2023 at 20:20:46 UTC, Dark Hole wrote: ```d template Foo(T, alias T[] Array) { // ... } // ... Bar[] arr; Foo!(Bar, arr); ``` This is valid D, but it doesn't work. It gives error "Error: template instance `Foo!(Bar, arr)` does not match template declaration `Foo(T

Template + alias + basic type depends on another parameter = broken?

2023-02-22 Thread Dark Hole via Digitalmars-d-learn
I'm trying to rewrite really old D code. There was fragment like that: ```d template Foo(T, T[] Array) { // ... } // ... Bar[] arr; Foo!(Bar, arr); ``` This gives error `can't read arr in compile time`. Small changes: ```d template Foo(T, alias T[] Array) { // ... } // ... Bar[] arr; Foo

Re: Template alias as template specialisation not recognized.

2021-01-15 Thread Basile B. via Digitalmars-d-learn
On Saturday, 16 January 2021 at 01:21:24 UTC, Paul wrote: I'm having issues when trying to use a template alias as a template specialisation. When using the following: alias Vec(uint size, Type) = Mat!(size, 1, Type); void setUniform(V : Vec!(L, bool), int L)(string name, V

Re: Template alias as template specialisation not recognized.

2021-01-15 Thread Paul via Digitalmars-d-learn
On Saturday, 16 January 2021 at 01:38:38 UTC, Paul Backus wrote: You have encountered issue 1807: https://issues.dlang.org/show_bug.cgi?id=1807 Ah I see, thank you, sad to see several DIP's I'd be interested in are postponed :( Thanks for the workaround hint, I'll probably be using that.

Re: Template alias as template specialisation not recognized.

2021-01-15 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 16 January 2021 at 01:21:24 UTC, Paul wrote: I'm having issues when trying to use a template alias as a template specialisation. When using the following: alias Vec(uint size, Type) = Mat!(size, 1, Type); void setUniform(V : Vec!(L, bool), int L)(string name, V

Template alias as template specialisation not recognized.

2021-01-15 Thread Paul via Digitalmars-d-learn
I'm having issues when trying to use a template alias as a template specialisation. When using the following: alias Vec(uint size, Type) = Mat!(size, 1, Type); void setUniform(V : Vec!(L, bool), int L)(string name, V value) {...} Vec!(4, bool) a; setUniform("test",

Re: template alias argument accepts only class/interface types.

2019-02-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.02.19 23:30, Alexandru Ermicioi wrote: According to https://dlang.org/spec/template.html#TemplateAliasParameter, simple types and arrays are excluded from the list of supported "alias X" arguments. I'm wondering why do we have such limitation? Is there any reasoning at limiting primitive

template alias argument accepts only class/interface types.

2019-02-23 Thread Alexandru Ermicioi via Digitalmars-d-learn
Perhaps I missed somewhere, but it seems that you can pass only classes or interfaces to alias argument of a template. Trying to pass another type (such as int, int[]) yields an error. Example of issue: void test(alias T)(int o) { import std.stdio; writeln("coo"

Re: Can you tell if an template alias parameter is of a specific template?

2018-08-05 Thread aliak via Digitalmars-d-learn
On Saturday, 4 August 2018 at 12:54:49 UTC, Steven Schveighoffer wrote: Once you have an alias, it's the original thing in all respects. So there's no way to get the specific alias that was used. That's not a bug, but a feature. Aha. Thanks. I've tried std.traits.TemplateOf and __traits

Re: Can you tell if an template alias parameter is of a specific template?

2018-08-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/18 12:17 PM, aliak wrote: Hi Is there a way to tell if an alias is to a template? I'm writing some algorithms and I need to distinguish between a binary predicate that provides "less than" and one that provides "equal to" semantics. So I have these two templates: template eq(alias pr

Re: Can you tell if an template alias parameter is of a specific template?

2018-08-03 Thread aliak via Digitalmars-d-learn
On Friday, 3 August 2018 at 19:10:45 UTC, Hakan Aras wrote: I don't think you can distinguish between entities evaluated through different templates. TemplateOf will paradoxically not work on pure templates of the form "template X() {}" only things like template functions and template structs.

Re: Can you tell if an template alias parameter is of a specific template?

2018-08-03 Thread Hakan Aras via Digitalmars-d-learn
I don't think you can distinguish between entities evaluated through different templates. TemplateOf will paradoxically not work on pure templates of the form "template X() {}" only things like template functions and template structs. isSame, is, and isInstanceOf will only work on the fully eva

Can you tell if an template alias parameter is of a specific template?

2018-08-03 Thread aliak via Digitalmars-d-learn
Hi Is there a way to tell if an alias is to a template? I'm writing some algorithms and I need to distinguish between a binary predicate that provides "less than" and one that provides "equal to" semantics. So I have these two templates: template eq(alias pred) { alias eq = pred; } temp

Re: Member function passed through template alias only requiring `this` in certain conditions?

2018-07-19 Thread Timoses via Digitalmars-d-learn
On Thursday, 19 July 2018 at 22:16:22 UTC, Ali Çehreli wrote: On 07/19/2018 08:12 AM, Emma wrote: > [...] > If I try to compile it, dmd complains, which I guess makes sense: > > --- > Error: need this for bar of type void() > Error: need this for baz of type void() > --- > > [...] I think it's a

Re: Member function passed through template alias only requiring `this` in certain conditions?

2018-07-19 Thread Ali Çehreli via Digitalmars-d-learn
On 07/19/2018 08:12 AM, Emma wrote: > void test(alias fn1, alias fn2)() > { > fn1(); > fn2(); > } > > struct Foo > { > void foo() > { > test!(bar, baz); > } > > void bar() > {} > > void baz() > {} > } > --- > > If I try to compile it, dmd comp

Member function passed through template alias only requiring `this` in certain conditions?

2018-07-19 Thread Emma via Digitalmars-d-learn
Hello, I’ve got this piece of code: --- import std.stdio; void test(alias fn1, alias fn2)() { fn1(); fn2(); } struct Foo { void foo() { test!(bar, baz); } void bar() {} void baz() {} } --- If I try to compile it, dmd complains, which I guess makes

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 13:01:20 UTC, Timoses wrote: Aw, okay, then that won't work. Still, this looks like it should work: void foo(F, T)(T param) { writeln("Called with type: ", T.stringof); } alias tfoo = ApplyLeft!(foo, int); tfoo!string("hi"); // tfoo("hi"); // Error

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 11:55:15 UTC, Simen Kjærås wrote: On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote: Would be nice if std.meta.ApplyLeft did the job here.. Is there no way of achieving that? [snip] Would have to find a way to determine whether Template would resolve to a function

Re: template alias that includes a parameter

2018-07-01 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote: Would be nice if std.meta.ApplyLeft did the job here.. Is there no way of achieving that? [snip] Would have to find a way to determine whether Template would resolve to a function or not. Can't find anything in Traits[1] or std.traits[2].

Re: template alias that includes a parameter

2018-07-01 Thread Timoses via Digitalmars-d-learn
On Sunday, 1 July 2018 at 01:48:15 UTC, Simen Kjærås wrote: I'd send you straight to std.meta.ApplyLeft, but it seems to do the wrong thing here, in that it doesn't handle IFTI. This thing does: void fooImpl(int n, T)(const T line) { } unittest { alias fun = applyLeft!(fooImpl, 3);

Re: template alias that includes a parameter

2018-06-30 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 30 June 2018 at 21:11:54 UTC, Anonymouse wrote: I have a template that I want to provide easy aliases for, where the aliases includes (partially applies?) a template parameter. void fooImpl(char token, T)(const T line) { // ... } alias quoteFoo(T) = fooImpl!('"', T); alias s

Re: template alias that includes a parameter

2018-06-30 Thread Timoses via Digitalmars-d-learn
;fooImpl!('"', string); auto singlequoteFooString = &fooImpl!('\'', string); void main() { quoteFooString("test quote"); singlequoteFooString("test single quote"); import std.meta; // std/meta.d(1232): Error: template instance `Template!'"'` does not match template //alias quoteFoo = ApplyLeft!(fooImpl, '"'); //quoteFoo(3); }

template alias that includes a parameter

2018-06-30 Thread Anonymouse via Digitalmars-d-learn
I have a template that I want to provide easy aliases for, where the aliases includes (partially applies?) a template parameter. void fooImpl(char token, T)(const T line) { // ... } alias quoteFoo(T) = fooImpl!('"', T); alias singlequoteFoo(T) = fooImpl!('\'', T); void main() { quoteF

Re: Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Juanjo Alvarez via Digitalmars-d-learn
Thanks to both, I got it. Type templates for generic types, and alias for other things knowing that the instantiation is by symbol. Yes, the "alias this" in my message was a (double) brainfart, I actually wanted to write "alias template". In this case both functions had the same assembler b

Re: Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Nicholas Wilson via Digitalmars-d-learn
nd the only diffence is that the call to writevalue1 does a "mov -0x8(%rdi),%edi" just before the callq instruction. (As noted by Mike the examples you present are actually template alias parameters, not alias this which affects name lookup.) There are three kinds of template p

Re: Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 11:06:13 UTC, Juanjo Alvarez wrote: Hi! With "alias this" accepting runtime variables I'm struggling to FYI, you are not talking about "alias this", but "alias template parameters", two very different concepts. understand the difference between a generic funct

Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Juanjo Alvarez via Digitalmars-d-learn
Hi! With "alias this" accepting runtime variables I'm struggling to understand the difference between a generic function with an "alias this" parameter and another one with a "runtime" parameter of template type. Example: // example code import std.stdio: writeln; void writevalue

Re: template alias parameter vs type parameter.

2017-03-22 Thread Daniel Nielsen via Digitalmars-d-learn
On Wednesday, 22 March 2017 at 18:12:31 UTC, Yuxuan Shui wrote: Hi, Is there any difference, when a type is passed into an alias parameter vs into a type parameter? alias parameters fail with builtin types, ex. 'int'. hopefully this will be corrected one day.

template alias parameter vs type parameter.

2017-03-22 Thread Yuxuan Shui via Digitalmars-d-learn
Hi, Is there any difference, when a type is passed into an alias parameter vs into a type parameter?

IFTI with template alias fails in D, works in C++

2015-08-12 Thread Timothee Cour via Digitalmars-d-learn
main.d: -- struct A(T, int D) { this(string ignore){} } alias B(T)=A!(T, 1); void fun1(T)(A!(T,1) a) { } void fun2(T)(B!T a) { } unittest{ auto a=A!(double,1)("a"); assert(is(typeof(a) == B!double)); fun1(a);//ok fun2!double(a);//ok // no IFTI here: //fun2(a);//not ok:

Re: Multiple template alias parameters

2015-05-09 Thread Artur Skawina via Digitalmars-d-learn
> functions. The grammar does not allow this syntax: >>> >>> ``` >>> template (alias Modules ...) { >>> ... >>> ``` >> >> The grammar allows omitting the 'alias' keyword. >> >> artur > > alias parameters are diffe

Re: Multiple template alias parameters

2015-05-08 Thread anonymous via Digitalmars-d-learn
On Friday, 8 May 2015 at 22:29:28 UTC, Biotronic wrote: Sadly, the ... syntax precludes the use of __LINE__ and __FILE__. :( You can put them in the runtime parameters: void traceVars(alias T, U...)(size_t line = __LINE__, string file = __FILE__) { import std.stdio : writeln; wr

Re: Multiple template alias parameters

2015-05-08 Thread Biotronic via Digitalmars-d-learn
On Friday, 8 May 2015 at 21:56:56 UTC, Brian Schott wrote: Allowing "template Tem(alias Args ...)" syntax would let me trace multiple variables at once. Actually, this already works: void traceVars(alias T, U...)() { import std.stdio : writeln; writeln(T.stringof, ": ", T); static

Re: Multiple template alias parameters

2015-05-08 Thread Brian Schott via Digitalmars-d-learn
On Friday, 8 May 2015 at 12:44:31 UTC, Artur Skawina wrote: On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: The problem occurs when I want to register multiple modules to scan for functions. The grammar does not allow this syntax: ``` template (alias Modules

Re: Multiple template alias parameters

2015-05-08 Thread Brian Schott via Digitalmars-d-learn
On Friday, 8 May 2015 at 02:03:17 UTC, Rikki Cattermole wrote: Can you not use something like this? Yes. I was getting confused by another problem that I had just worked on before this one.

Re: Multiple template alias parameters

2015-05-08 Thread Artur Skawina via Digitalmars-d-learn
On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: > The problem occurs when I want to register multiple modules to scan for > functions. The grammar does not allow this syntax: > > ``` > template (alias Modules ...) { > ... > ``` The grammar allows omittin

Re: Multiple template alias parameters

2015-05-07 Thread Rikki Cattermole via Digitalmars-d-learn
his syntax: ``` template (alias Modules ...) { ... ``` Any ideas (besides "STRING MIXINS EVERYWHERE")? Can you not use something like this? import std.stdio; import std.traits; void main() { func!(std.stdio, std.traits)(); } void func(T...)() { pr

Multiple template alias parameters

2015-05-07 Thread Brian Schott via Digitalmars-d-learn
the implementation, which is ugly because Phobos is missing a lot of functionality, but that's not the topic I'm discussing here). The problem occurs when I want to register multiple modules to scan for functions. The grammar does not allow this syntax: ``` template (ali

Re: UFCS on template alias ?

2015-02-21 Thread bearophile via Digitalmars-d-learn
Baz: Is this a normal behaviour ? Try to move the definition of "poly" to module-level scope. This is a design decision to avoid other troubles. Bye, bearophile

UFCS on template alias ?

2015-02-21 Thread Baz via Digitalmars-d-learn
Is this a normal behaviour ? --- void main() { import std.algorithm; auto list = [0,1,2,3]; alias poly = map; list.poly!(a => a + a); } --- outputs: "Error: no property 'poly' for type 'int[]'"

Re: Template alias parameters to local variables

2014-09-17 Thread via Digitalmars-d-learn
On Saturday, 13 September 2014 at 11:34:01 UTC, Marc Schütz wrote: Consider the following code: alias Sink = scope void delegate(const(char)[]); private template generateAliases(int __i, __vars...) { import std.conv : to; static if(__i < __vars.length)

Re: Template alias parameters to local variables

2014-09-14 Thread via Digitalmars-d-learn
On Sunday, 14 September 2014 at 09:29:16 UTC, Kagamin wrote: Doesn't this cause infinite recursion? No, because the inner templates are instantiated with different first template parameters. Even if all template parameters were the same, it would only be a runtime recursion.

Re: Template alias parameters to local variables

2014-09-14 Thread Kagamin via Digitalmars-d-learn
Doesn't this cause infinite recursion?

Template alias parameters to local variables

2014-09-13 Thread via Digitalmars-d-learn
Consider the following code: alias Sink = scope void delegate(const(char)[]); private template generateAliases(int __i, __vars...) { import std.conv : to; static if(__i < __vars.length) enum generateAliases = "alias " ~ __vars[__i].stringof ~ " =

Re: Template alias parameter: error: need 'this' for ...

2013-08-24 Thread Matej Nanut
On Friday, 23 August 2013 at 22:54:33 UTC, Jonathan M Davis wrote: Because without static it's a member variable, which means that you have to have a constructed object to access it (since it's part of the object). When you declare a variable in a class or struct static, then there's only one f

Re: Template alias parameter: error: need 'this' for ...

2013-08-23 Thread Jonathan M Davis
On Friday, August 23, 2013 23:28:46 Matej Nanut wrote: > Hello! > > I've run into this issue that I don't understand, maybe someone > can enlighten me. :) > > This code: > --- > struct Thing > { > int i; > } > > void main() > { > t!(Thing.i)(); > } > > void t(alias a)() > { > return; > } > ---

Template alias parameter: error: need 'this' for ...

2013-08-23 Thread Matej Nanut
Hello! I've run into this issue that I don't understand, maybe someone can enlighten me. :) This code: --- struct Thing { int i; } void main() { t!(Thing.i)(); } void t(alias a)() { return; } --- fails to compile with: ‘Error: need 'this' for 't' of type 'pure nothrow @safe voi

Re: Template alias parameter does not accept types

2013-05-09 Thread Steven Schveighoffer
On Thu, 09 May 2013 10:00:45 -0400, Dicebot wrote: Feels like I am the only one who wants to restrict rules, not relax them =/ But, erm, you don't need alias accepting literals for old syntax! Strings are valid as template value parameters: http://dpaste.1azy.net/54e5d3f2 Hm.. maybe it

Re: Template alias parameter does not accept types

2013-05-09 Thread Dicebot
Feels like I am the only one who wants to restrict rules, not relax them =/ But, erm, you don't need alias accepting literals for old syntax! Strings are valid as template value parameters: http://dpaste.1azy.net/54e5d3f2

Re: Template alias parameter does not accept types

2013-05-09 Thread Steven Schveighoffer
ing it for template alias parameters does is enable the whole std.algorithm acceptance of a string literal for function lambdas. Arguably, this is no longer needed due to the new lambda syntax (but I think we have found other uses for it). It has also caused some headaches: map!"a.x"(

Re: Template alias parameter does not accept types

2013-05-09 Thread bearophile
Kenji Hara: AFAIK, there is no plan for fix. The behavior is currently a part of language design. Considering matters of D semantic uniformity, and the code shown by Dicebot: template Hello(T...) if (T.length == 1) { static if (is(T[0])) // ... else // ... } The

Re: Template alias parameter does not accept types

2013-05-09 Thread Dicebot
On Thursday, 9 May 2013 at 13:27:35 UTC, Steven Schveighoffer wrote: template GetString(T) if (is(T == int) || is(T == float) || ...) { enum string GetString = T.stringof; } Current idiomatic D way to handle both built-in types and symbols looks like this: template Hello(T...) if (T.l

Re: Template alias parameter does not accept types

2013-05-09 Thread Kenji Hara
On Thursday, 9 May 2013 at 12:09:03 UTC, Dicebot wrote: On Thursday, 9 May 2013 at 11:19:38 UTC, bearophile wrote: It will be fixed. Ugh, proof-link? I have always thought it is by design and that actually makes sense. AFAIK, there is no plan for fix. The behavior is currently a part of la

Re: Template alias parameter does not accept types

2013-05-09 Thread bearophile
Steven Schveighoffer: Do you have evidence of an official statement to the contrary? Here I don't have evidence, just faith :-) Bye, bearophile

Re: Template alias parameter does not accept types

2013-05-09 Thread Steven Schveighoffer
; } There may even already be a template for detecting a builtin type, not sure. On Thu, 09 May 2013 07:19:37 -0400, bearophile wrote: Template alias arguments don't yet accept built-in types as int. It will be fixed. I don't think this is true, alias strictly accepts symb

Re: Template alias parameter does not accept types

2013-05-09 Thread Dicebot
On Thursday, 9 May 2013 at 11:19:38 UTC, bearophile wrote: It will be fixed. Ugh, proof-link? I have always thought it is by design and that actually makes sense.

Re: Template alias parameter does not accept types

2013-05-09 Thread Anonimous
On Thursday, 9 May 2013 at 10:59:02 UTC, ref2401 wrote: Version D 2.062 http://dlang.org/template.html#TemplateAliasParameter Is is said in the documentation that is's possible but i get compile time error. template GetString(alias Arg) { enum string GetString = Arg.stringof; } void m

Re: Template alias parameter does not accept types

2013-05-09 Thread bearophile
ref2401: template GetString(alias Arg) { enum string GetString = Arg.stringof; } ... writeln(GetString!int); // Error: template instance Template alias arguments don't yet accept built-in types as int. It will be fixed. Bye, bearophile

Template alias parameter does not accept types

2013-05-09 Thread ref2401
Version D 2.062 http://dlang.org/template.html#TemplateAliasParameter Is is said in the documentation that is's possible but i get compile time error. template GetString(alias Arg) { enum string GetString = Arg.stringof; } void main(string[] argv) { writeln(GetString!"1234");

Re: unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread ref2401
i'm using VisualD. this assertion fails assert(msg == "Null reference message"); in my actual code instead of variable _message an exception is thrown if (obj is null) == true. i'm using the unittest block to test exception throwing. ... this(T obj) { if (obj is

Re: unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread Steven Schveighoffer
On Tue, 07 May 2013 10:58:09 -0400, ref2401 wrote: Version D 2.062 class MyClass {} struct MyStruct(T) if (is(T == class)) { string _message = "nothing"; this(T obj) { if (obj is null){ _message = "Null reference message";

unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread ref2401
Version D 2.062 class MyClass {} struct MyStruct(T) if (is(T == class)) { string _message = "nothing"; this(T obj) { if (obj is null){ _message = "Null reference message"; } else{

Re: Template alias parameter does not accept functions

2013-02-27 Thread Nick Treleaven
On 27/02/2013 18:06, Dicebot wrote: Ye, lambda litteral issue is different one. OK. My code example: http://dpaste.1azy.net/b06370ea The problem may be related to optional parentheses and stringof, and may be a compiler bug. You can pass function names as a template alias parameter

Re: Template alias parameter does not accept functions

2013-02-27 Thread Dicebot
Fuck. Optional. Parens. Thank you. I have tried some other code than .stringof but guess it invoked Symbols somewhere silently, too.

Re: Template alias parameter does not accept functions

2013-02-27 Thread Dicebot
Ye, lambda litteral issue is different one. My code example: http://dpaste.1azy.net/b06370ea

Re: Template alias parameter does not accept functions

2013-02-27 Thread Nick Treleaven
On 27/02/2013 17:38, Nick Treleaven wrote: On 27/02/2013 15:20, Dicebot wrote: Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround? Actua

Re: Template alias parameter does not accept functions

2013-02-27 Thread Nick Treleaven
On 27/02/2013 15:20, Dicebot wrote: Looking here: http://dlang.org/template.html#TemplateAliasParameter There are no function symbols in the list. And quick check that it won't compile. Two questions arise: a) Why so? b) Is there a workaround? This has sometimes come up in the NG, with some s

Re: Template alias parameter does not accept functions

2013-02-27 Thread Dicebot
Actually it looks like a somewhat broken behavior as it works for parameter-less functions.

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread Rob T
On Sunday, 25 November 2012 at 16:42:03 UTC, Maxim Fomin wrote: Recently I saw a major pull affecting this behavior, so in 2.061 the situation may be changed (I haven't bother to figure yet). In practice this makes a tricky thing to understand what S() is and creates a problem when you e.x. hea

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread comco
On Sunday, 25 November 2012 at 16:01:39 UTC, Ali Çehreli wrote: Could you please create a bug report: http://d.puremagic.com/issues/ Ali Filed an issue 9078.

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread Maxim Fomin
On Sunday, 25 November 2012 at 15:27:53 UTC, comco wrote: A!B(...) defines a struct A with B typed in as Method, so call to method(s); is the same as B(string) Why is that? Here method is an instance of the type Method, not the type Method itself, so by saying `method(s)` we can't mean a cons

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread Ali Çehreli
On 11/25/2012 07:27 AM, comco wrote: > >> A!B(...) defines a struct A with B typed in as Method, so call to >> method(s); is the same as B(string) > Why is that? Here method is an instance of the type Method, not the type > Method itself, That could be case but you original code did use a type na

Re: constructor instead of opCall for an instance of a template alias

2012-11-25 Thread comco
A!B(...) defines a struct A with B typed in as Method, so call to method(s); is the same as B(string) Why is that? Here method is an instance of the type Method, not the type Method itself, so by saying `method(s)` we can't mean a constructor. Something very strange happens... I have a simple

Re: constructor instead of opCall for an instance of a template alias

2012-11-24 Thread Rob T
On Saturday, 24 November 2012 at 20:34:39 UTC, comco wrote: I have the following snippet: struct A(alias Method) { string s; this(Method method) { method(s); // 5 } } struct B { this(int i) { } void opCall(string s) { } } void main() { A!B(B(0)); } This code

constructor instead of opCall for an instance of a template alias

2012-11-24 Thread comco
I have the following snippet: struct A(alias Method) { string s; this(Method method) { method(s); // 5 } } struct B { this(int i) { } void opCall(string s) { } } void main() { A!B(B(0)); } This code fails to compile with the following errors: test.d(5): Error:

Re: Strange template alias behaviour

2012-11-18 Thread Simen Kjaeraas
On 2012-05-18 17:11, Maxim Fomin wrote: Changing template parameter to Bar.f or bar.f affects value of bar.f.data. Seems to be a bug. It's a bug. Further reduction: import std.stdio; mixin template Foo() { string data = "default"; } struct Bar { mixin Foo f; } string get_data(alias u

Re: Strange template alias behaviour

2012-11-18 Thread Maxim Fomin
Reduced: import std.stdio; mixin template Foo() { string data = "default"; } class Bar { string data; mixin Foo f; } void check_data(alias M, T)(T obj) { writeln(M.stringof); writeln(obj.data); writeln(obj.f.data); } void main() { Bar bar = new Bar; bar.data = "Bar"; bar.f.d

Re: Template mixin identifier as template alias parameter

2012-11-11 Thread David Nadlinger
On Sunday, 11 November 2012 at 10:36:42 UTC, Jacob Carlborg wrote: This won't work. The "node" template doesn't evaluate to a type and you wouldn't use it as a mixin if it did. You _can_ actually use an identifier for mixin templates, it is used to disambiguate in case of name collisions. As

Re: Template mixin identifier as template alias parameter

2012-11-11 Thread Jack Applegame
On Sunday, 11 November 2012 at 10:36:42 UTC, Jacob Carlborg wrote: This won't work. The "node" template doesn't evaluate to a type and you wouldn't use it as a mixin if it did. But this is works! Why? mixin template node() { alias int E; E prev, next; } struct list(alias N) { N.E head;

Re: Template mixin identifier as template alias parameter

2012-11-11 Thread Jacob Carlborg
On 2012-11-11 10:04, Jack Applegame wrote: I'm trying creating template for intrusive double-linked list: mixin template node() { static if(is(this == struct)) alias typeof(this)* E; else alias typeof(this) E; E prev, next; } class A { mixin node L1; mixin node L2; } T

Template mixin identifier as template alias parameter

2012-11-11 Thread Jack Applegame
I'm trying creating template for intrusive double-linked list: mixin template node() { static if(is(this == struct)) alias typeof(this)* E; else alias typeof(this) E; E prev, next; } struct list(alias N) { N.E head; N.E tail; } class A { mixin node; } list!A l; All works g

Re: Function overload with template alias error

2011-12-24 Thread Timon Gehr
On 12/24/2011 11:23 AM, André Stein wrote: Hi, I'm trying to write a template function which takes a templated alias to another type: struct test(T) { } template aliasT(T) { alias test!(T) aliasT; } void foo(T)(test!T t) { // works } void foo2(T)(aliasT!T t) { // doesn't work } int main(str

Function overload with template alias error

2011-12-24 Thread André Stein
Hi, I'm trying to write a template function which takes a templated alias to another type: struct test(T) { } template aliasT(T) { alias test!(T) aliasT; } void foo(T)(test!T t) { // works } void foo2(T)(aliasT!T t) { // doesn't work } int main(string[] args) { test!(int) t; al

Re: template alias parameters

2011-04-06 Thread Jesse Phillips
enuhtac Wrote: > Hi, > > I'm playing around with template alias parameters. At the moment I'm > considering the following simple code: > > struct A > {}; > > struct B( T ) > { > T t; > }; > > struct C( alias T ) > { >

template alias parameters

2011-04-06 Thread enuhtac
Hi, I'm playing around with template alias parameters. At the moment I'm considering the following simple code: struct A {}; struct B( T ) { T t; }; struct C( alias T ) { T t; }; void main() { B!A a; C!A b; } What exactly is the difference between a and b? Both seem

Re: Error in "Template Alias Parameter" example in the documentation

2011-03-17 Thread Jesse Phillips
simendsjo Wrote: > Are these pages written using DDoc? Is it possible to extract and compile the > examples to > ensure they are correct? And perhaps use asserts instead of/in addition to > comments where > possible (Asserts are used many places already)? > Executable and verifiable examples cou

Error in "Template Alias Parameter" example in the documentation

2011-03-17 Thread simendsjo
This example comes from http://digitalmars.com/d/2.0/template.html int x; template Foo(alias X) { static int* p = &X; } void test() { alias Foo!(x) bar; *bar.p = 3; // set x to 3 static int y; alias Foo!(y) abc; *abc.p = 3; // set y to 3 } Compiling this

Re: template alias

2011-01-23 Thread Simen kjaeraas
Luke J. West wrote: Hi, I don't want to keep typing isNumeric!T | isSomeChar!T. I want to type isBuiltIn!T instead, but am trying to work out how to implement it. Something like template isBuiltInT(T) {const bool t=isNumeric!T | isSomeChar!T};} alias isBuiltInT.t isBuiltIn; But that doesn

Re: template alias

2011-01-23 Thread Andrej Mitrovic
Use the eponymous trick: import std.stdio; import std.traits; template isBuiltInT(T) { enum isBuiltInT = isNumeric!T || isSomeChar!T; } void main() { assert(isBuiltInT!(int)); assert(isBuiltInT!(char)); }

  1   2   >