Re: How to unpack template parameters,Or how to forward parameters?

2022-05-06 Thread zjh via Digitalmars-d-learn
On Friday, 6 May 2022 at 05:44:39 UTC, vit wrote: Try this: Very Good,Thank you very much!

Re: How to unpack template parameters,Or how to forward parameters?

2022-05-05 Thread vit via Digitalmars-d-learn
On Friday, 6 May 2022 at 00:41:18 UTC, zjh wrote: Hello everyone,I have following function: ```d import core.stdc.stdio; void f(int i,int j){ printf("%i,%i",i,j); } ``` I want to forward `int[N]` to `(int i,int j)` etc. How can I write a forwarding function? ```d void ff(alias

How to unpack template parameters,Or how to forward parameters?

2022-05-05 Thread zjh via Digitalmars-d-learn
Hello everyone,I have following function: ```d import core.stdc.stdio; void f(int i,int j){ printf("%i,%i",i,j); } ``` I want to forward `int[N]` to `(int i,int j)` etc. How can I write a forwarding function? ```d void ff(alias g,int...I)(int[2]k){ g(k[I]); }//How to unpack template

Re: Understanding alias template parameters

2022-04-22 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 22 April 2022 at 08:04:16 UTC, JG wrote: On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? Good job, works great! Potential is high: ```d void main() { alias type = real; auto

Re: Understanding alias template parameters

2022-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 4/22/22 01:04, JG wrote: > In response to the change to "alias", which has several upsides > including faster code. I would note it also has some downsides including > every lambda produces a new type so that (at the moment) the following > assert > holds: I got confused a little bit there.

Re: Understanding alias template parameters

2022-04-22 Thread JG via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); }

Re: Understanding alias template parameters

2022-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 21, 2022 at 09:02:47PM +, JG via Digitalmars-d-learn wrote: > Hi, > > Could someone possibly help me to understand why the commented line > doesn't compile? > > > ```d > import std; > > struct MapResult(R,F) > { > R r; > const F f; > auto empty() { return r.empty; }

Re: Understanding alias template parameters

2022-04-21 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:38:14 UTC, Ali Çehreli wrote: ```d auto myMap(alias f, R)(R r) { pragma(msg, typeof(f)); return MapResult!(R, f)(r); } ``` It looks delicious when the convenience function works magic with Voldemort: ```d import std.range, std.stdio; auto myMap(alias

Re: Understanding alias template parameters

2022-04-21 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); }

Re: Understanding alias template parameters

2022-04-21 Thread Ali Çehreli via Digitalmars-d-learn
t represents the types of function templates. One way of changing the code is to use the following but it does not really fit because of course you may want types other than 'int': (int x) => 2 * x // Now the type is known The more logical thing to do is to stay with alias temp

Understanding alias template parameters

2022-04-21 Thread JG via Digitalmars-d-learn
Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } void popFront() { r.popFront; } auto save() { return

Re: template parameters :: fix

2021-09-03 Thread Charles Hixson via Digitalmars-d-learn
change:             {    rl.remove(i); to:            {    rl  =  rl.remove(i); -- Javascript is what you use to allow third party programs you don't know anything about and doing you know not what to run on your computer.

Re: template parameters

2021-09-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 02, 2021 at 02:28:23PM -0700, Charles Hixson via Digitalmars-d-learn wrote: [...] > -- > Javascript is what you use to allow third part programs you don't know > anything about and doing you know not what to run on your computer. ROFL! I'm st^Wborrowing this for my quotes file. ;-)

Re: template parameters

2021-09-02 Thread Charles Hixson via Digitalmars-d-learn
T /**    An Associative Array with some Randomization and Linear features.  * Note:  This is done in a simplified and not too generalized fashion so that I don't need to  *         figure out template parameters at the moment.  It should be redone later, when my mastery  *         is better.  Th

Re: template parameters

2021-08-29 Thread Ali Çehreli via Digitalmars-d-learn
On 8/29/21 3:31 PM, Charles Hixson wrote: > Thanks. I going to have to study: > > enum supportsCall = isIntegral!(typeof(T.init.%s())); > > > for awhile to make any sense of that, but it looks like just what I was > looking for. Trying to explain with comments: // This is an eponymous template

Re: template parameters

2021-08-29 Thread Charles Hixson via Digitalmars-d-learn
Thanks.  I going to have to study: enum supportsCall = isIntegral!(typeof(T.init.%s())); for awhile to make any sense of that, but it looks like just what I was looking for. On 8/29/21 2:41 PM, Ali Çehreli via Digitalmars-d-learn wrote: On 8/29/21 11:32 AM, Charles H. wrote: I've set up

Re: template parameters

2021-08-29 Thread Ali Çehreli via Digitalmars-d-learn
On 8/29/21 11:32 AM, Charles H. wrote: I've set up a class template (so far untested) thus:     class    AARL (T, ndx = "ndx")     if (isIntegral(T.init.ndx) )     If I'm correct, this should work for ndx an integer variable of T, but I'd really like T to be able to be anything

template parameters

2021-08-29 Thread Charles Hixson via Digitalmars-d-learn
I've set up a class template (so far untested) thus: class    AARL (T, ndx = "ndx")         if (isIntegral(T.init.ndx) ) If I'm correct, this should work for ndx an integer variable of T, but I'd really like T to be able to be anything which can be stored both in an array and in an associative

template parameters

2021-08-29 Thread Charles H. via Digitalmars-d-learn
I've set up a class template (so far untested) thus: classAARL (T, ndx = "ndx") if (isIntegral(T.init.ndx) ) If I'm correct, this should work for ndx an integer variable of T, but I'd really like T to be able to be anything which can be stored both in an array and in

Re: Is there a "nice" way to access the names of template parameters outside?

2021-07-27 Thread Paul Backus via Digitalmars-d-learn
" way from the outside the get the names of the template values? As far as I'm aware there is no way to introspect on template parameters at all. Let's say i instantiate the template does that change anything? Can I get the "placeholder" names in any way then? I don't think inst

Re: Is there a "nice" way to access the names of template parameters outside?

2021-07-27 Thread Lukas Borin via Digitalmars-d-learn
ate values? As far as I'm aware there is no way to introspect on template parameters at all. Let's say i instantiate the template does that change anything? Can I get the "placeholder" names in any way then?

Re: Is there a "nice" way to access the names of template parameters outside?

2021-07-27 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 27 July 2021 at 08:15:12 UTC, Lukas Borin wrote: Consider the following template ```D auto foo(T, int W, int H)(T p1, T p2) { } ``` Is there a "nice" way from the outside the get the names of the template values? As far as I'm aware there is no way to introspect o

Is there a "nice" way to access the names of template parameters outside?

2021-07-27 Thread Lukas Borin via Digitalmars-d-learn
Consider the following template ```D auto foo(T, int W, int H)(T p1, T p2) { } ``` Is there a "nice" way from the outside the get the names of the template values? E.g: ```D pragma(msg, TemplateParameterNames!(foo)); // AliasSeq!("T", "W", "H") or ["T", "W", "H"] ``` I know you can find

Re: If statements and unused template parameters in Phobos documentation

2020-12-20 Thread Rekel via Digitalmars-d-learn
On Sunday, 20 December 2020 at 13:58:00 UTC, Max Haughton wrote: The if is a template constraint. Ah sorry! I must have missed that part of the dlang tour. (https://tour.dlang.org/tour/en/gems/template-meta-programming) Thanks a lot!

Re: If statements and unused template parameters in Phobos documentation

2020-12-20 Thread Max Haughton via Digitalmars-d-learn
On Sunday, 20 December 2020 at 13:51:08 UTC, Rekel wrote: I found a lot of the Phobos documentation to contain template arguments and if statements that made no sense to me, for example: ``` uint readf(alias format, A...) ( auto ref A args ) if (isSomeString!(typeof(format))); uint

If statements and unused template parameters in Phobos documentation

2020-12-20 Thread Rekel via Digitalmars-d-learn
I found a lot of the Phobos documentation to contain template arguments and if statements that made no sense to me, for example: ``` uint readf(alias format, A...) ( auto ref A args ) if (isSomeString!(typeof(format))); uint readf(A...) ( scope const(char)[] format, auto ref A args ); ```

Re: Why are default template parameters not permitted on class templates?

2020-11-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 29 November 2020 at 21:52:10 UTC, JN wrote: ValueHolder v2; // error Make it `ValueHolder!()` and it works. Default template params are only considered *after* it is clear a template needs to be instantiated. `ValueHolder` by itself is just the name of the template which is

Why are default template parameters not permitted on class templates?

2020-11-29 Thread JN via Digitalmars-d-learn
class ValueHolder(T = int) { T t; } void main() { ValueHolder!int v1; ValueHolder v2; // error } onlineapp.d(9): Error: template class onlineapp.ValueHolder(T = int) is used as a type without instantiation; to instantiate it use ValueHolder!(arguments)

Re: synthesising instantiated template parameters and arguments

2020-10-29 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 05:51:14 UTC, Nicholas Wilson wrote: but for a templated C this is tricker as I can't use a template sequence parameter (...) unless C uses it in the same position (I'm trying to generate a mangle from it so it needs to be exact). Given class

Re: synthesising instantiated template parameters and arguments

2020-10-28 Thread Adam D. Ruppe via Digitalmars-d-learn
reflection } alias ScopeClass = Anon!(int, 0, float); } So I'm not sure you can do what you want to do - D doesn't have any way to reflect on template parameters (though you CAN extract arguments I don't think it really helps here since you can't tell if the arguments were from `int, float

synthesising instantiated template parameters and arguments

2020-10-27 Thread Nicholas Wilson via Digitalmars-d-learn
Given template ScopeClass(C) { //... } where C is a, possibly templated, class I want the eponymous member of ScopeClass!(C) to have the same templatedness (both parameters and arguments)as C. For a non-template C this is a simple as: template ScopeClass(C) { class ScopeClass {

Re: Count template parameters of method

2020-10-12 Thread Andrey via Digitalmars-d-learn
And what about: void test() {} and void text(alias qqq)() {} ?

Re: Count template parameters of method

2020-10-11 Thread Basile B. via Digitalmars-d-learn
On Sunday, 11 October 2020 at 06:53:59 UTC, Andrey wrote: Hello, How to count a number of parameters in uninitialized template method? For example: struct Test { void abc(int a, bool status, string text)() {} { The method "Test.abc" has three template paramenters. I know that

Count template parameters of method

2020-10-11 Thread Andrey via Digitalmars-d-learn
Hello, How to count a number of parameters in uninitialized template method? For example: struct Test { void abc(int a, bool status, string text)() {} { The method "Test.abc" has three template paramenters. I know that "TemplateArgsOf" exists but it is used only for INITIALIZED

Function Templates with Only Template Parameters and UFCS

2020-05-10 Thread Seven Seas via Digitalmars-d-learn
Given the code: ``` auto foo(alias A, string str)() { // do stuff } struct Bar { // members } Bar bar; bar.foo!"hello"; // This is an error. Would have to do foo!(bar, "hello") ``` Assuming that I haven't misunderstood or borked something, having UFCS for function templates whose

Re: Variadic template parameters, refactor a long chain of static if's to 'functions'.

2019-06-28 Thread realhet via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 13:22:26 UTC, Adam D. Ruppe wrote: On Tuesday, 11 June 2019 at 09:26:56 UTC, realhet wrote: static bool processId(bool captureIntId, alias r, alias a)(){ mixin("alias ta = typeof("~a.stringof~");"); As I have been saying a lot, mixin and stringof should

Re: Variadic template parameters, refactor a long chain of static if's to 'functions'.

2019-06-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 09:26:56 UTC, realhet wrote: static bool processId(bool captureIntId, alias r, alias a)(){ mixin("alias ta = typeof("~a.stringof~");"); As I have been saying a lot, mixin and stringof should almost never be used together. You could write this a lot easier:

Variadic template parameters, refactor a long chain of static if's to 'functions'.

2019-06-11 Thread realhet via Digitalmars-d-learn
Hi again, I'm trying to do variadic parameter processing, and I have the following function that works fine: static bool same(T1, T2)(){ pragma(msg, "same? "~T1.stringof~" "~T2.stringof); return is(immutable(T1)==immutable(T2)); } Btn btn(T...)(string params, T args){ enum

Re: Getting template parameters by its name

2019-01-11 Thread Yui Hosaka via Digitalmars-d-learn
On Friday, 11 January 2019 at 06:13:11 UTC, Paul Backus wrote: On Friday, 11 January 2019 at 04:59:50 UTC, Yui Hosaka wrote: I want to do something like this: template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } You can get the

Re: Getting template parameters by its name

2019-01-10 Thread Paul Backus via Digitalmars-d-learn
On Friday, 11 January 2019 at 04:59:50 UTC, Yui Hosaka wrote: I want to do something like this: template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } You can get the arguments of a template instance as an AliasSeq using

Getting template parameters by its name

2019-01-10 Thread Yui Hosaka via Digitalmars-d-learn
I want to do something like this: template S(T) { } void main() { pragma(msg, S!(int).T); // Error: no property `T` for type `void` } Using alias, it is possible to get T by another name: template S(T) { alias t = T; } void main() { pragma(msg, S!(int).t); } But

Re: Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 11:26:40 UTC, Vijay Nayar wrote: On Wednesday, 25 April 2018 at 10:25:11 UTC, Simen Kjærås wrote: In the general case, the issue is unsolvable, since the relationship between template parameters and alias results may be arbitrarily complex. A simple degenerate

Re: Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread ag0aep6g via Digitalmars-d-learn
On 04/25/2018 12:25 PM, Simen Kjærås wrote: It's a known issue, and could be solved in some cases by partial template expansion, which is currently not part of the language. I believe it's in bugzilla somewhere, but a cursory search yielded no results.

Re: Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread Vijay Nayar via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 10:25:11 UTC, Simen Kjærås wrote: In the general case, the issue is unsolvable, since the relationship between template parameters and alias results may be arbitrarily complex. A simple degenerate case is this: Ok, wow, you weren't kidding. That becomes really

Re: Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread Simen Kjærås via Digitalmars-d-learn
no results. In the general case, the issue is unsolvable, since the relationship between template parameters and alias results may be arbitrarily complex. A simple degenerate case is this: alias Foo(T) = string; T fun(T)(Foo!T a) { return T.init; } unittest { // What's val's type? auto

Re: Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread Vijay Nayar via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 07:39:28 UTC, Vijay Nayar wrote: addAllWithAlias(v1); // Error! One more note, this following line works correctly. addAllWithAlias!double(v1); // OK.

Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread Vijay Nayar via Digitalmars-d-learn
encountered a bug or missing feature? Example below: ``` /** * Demonstrate an unexpected compiler error when using implicit template parameters * combined with aliases to partially instantiate templates. */ struct Vector(ElemT, size_t SizeV) { private: ElemT[SizeV] _data; public: @property

Re: Append variadic template parameters

2017-02-05 Thread Mark Fisher via Digitalmars-d-learn
On Sunday, 5 February 2017 at 21:51:14 UTC, Meta wrote: On Sunday, 5 February 2017 at 20:36:57 UTC, Mark Fisher wrote: I want to write a template: static auto ref BindArg(alias Func,alias arg,args...)() { return Func(arg,args); } where Func is called with 'arg' followed by the 'args'

Re: Append variadic template parameters

2017-02-05 Thread Meta via Digitalmars-d-learn
On Sunday, 5 February 2017 at 20:36:57 UTC, Mark Fisher wrote: I want to write a template: static auto ref BindArg(alias Func,alias arg,args...)() { return Func(arg,args); } where Func is called with 'arg' followed by the 'args' parameters. eg: string f(string a,int b,int c);

Re: Append variadic template parameters

2017-02-05 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 5 February 2017 at 20:36:57 UTC, Mark Fisher wrote: static auto ref BindArg(alias Func,alias arg,args...)() { return Func(arg,args); } [...] BindArg(f,"1",2,3); You forgot an exclamation mark there: BindArg!(f,"1",2,3);

Append variadic template parameters

2017-02-05 Thread Mark Fisher via Digitalmars-d-learn
I want to write a template: static auto ref BindArg(alias Func,alias arg,args...)() { return Func(arg,args); } where Func is called with 'arg' followed by the 'args' parameters. eg: string f(string a,int b,int c); BindArg(f,"1",2,3); The compiler throws an error: Error: function f

Re: Changing template parameters

2017-01-16 Thread Dlearner via Digitalmars-d-learn
On Monday, 16 January 2017 at 16:08:07 UTC, Rene Zwanenburg wrote: On Monday, 16 January 2017 at 15:56:16 UTC, Jack Stouffer wrote: Same way you use any template parameters, auto i = uniform!("(]")(0, 1000); Also, if the template parameter consists of a single token you

Re: Changing template parameters

2017-01-16 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 16 January 2017 at 15:56:16 UTC, Jack Stouffer wrote: Same way you use any template parameters, auto i = uniform!("(]")(0, 1000); Also, if the template parameter consists of a single token you can omit the parens: auto i = uniform!"(]"(0, 1000);

Re: Changing template parameters

2017-01-16 Thread Jack Stouffer via Digitalmars-d-learn
e template parameters? Same way you use any template parameters, auto i = uniform!("(]")(0, 1000);

Changing template parameters

2017-01-16 Thread Dlearner via Digitalmars-d-learn
Hey, quick question! I'm messing around with std.random and noticed that you can change the boundaries parameter to be either open or closed intervals on either side. By default it is "[)". How do I change these template parameters?

Re: Template parameters that don't affect template type

2016-08-12 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 20:43:13 UTC, Meta wrote: On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] It can be done, but you have to be explicit and should think very carefully if this is really a good design. struct X(int defaultSize = 100) { int size;

Re: Template parameters that don't affect template type

2016-08-11 Thread Meta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void

Re: Template parameters that don't affect template type

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
re, but the compiler considers them to be different types. Each instantiation of a template defines a DIFFERENT namespace. The only time the namespaces are identical are when the template parameters are identical. The reason templates are so useful is because I don't HAVE to write both S1 and S2.

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:42:51 UTC, Steven Schveighoffer wrote: On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
Also, what if we use a class instead of a struct? in this case they are both references to the same thing. I see a problem with reflection though, as one could get the template parameter value and it would wrong on conversion. D takes the easy way out of just preventing complex and

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 19:28:47 UTC, Lodovico Giaretta wrote: On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] If, in your case, it is possible to use one type as the other, then specify it. I mean, implement a templated opAssign that allows you to assign

Re: Template parameters that don't affect template type

2016-08-11 Thread Lodovico Giaretta via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: [...] If, in your case, it is possible to use one type as the other, then specify it. I mean, implement a templated opAssign that allows you to assign values of one instantiation to values of another. While doing so,

Re: Template parameters that don't affect template type

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/11/16 2:42 PM, Steven Schveighoffer wrote: On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size;

Re: Template parameters that don't affect template type

2016-08-11 Thread Ali Çehreli via Digitalmars-d-learn
On 08/11/2016 11:11 AM, Engine Machine wrote: > I have the need, in some cases, to pass static information to a template > class but don't want it to affect its type. > > import std.algorithm, core.stdc.stdlib; > struct X(int defaultSize = 100) > { >int Size; >int* p; >void foo(int

Re: Template parameters that don't affect template type

2016-08-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/11/16 2:11 PM, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(int size) { Size =

Re: Template parameters that don't affect template type

2016-08-11 Thread sldkf via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: Is there any way to get D to understand I want do not want a template parameter to be part of the type comparison? No. Use a standard run-time parameter. Your problem can be solved by defining a constructor.

Re: Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
On Thursday, 11 August 2016 at 18:11:30 UTC, Engine Machine wrote: I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void

Template parameters that don't affect template type

2016-08-11 Thread Engine Machine via Digitalmars-d-learn
I have the need, in some cases, to pass static information to a template class but don't want it to affect its type. import std.algorithm, core.stdc.stdlib; struct X(int defaultSize = 100) { int Size; int* p; void foo(int size) { Size = max(size, defaultSize); p =

Re: Passing anonymous templated functions as template parameters

2016-06-15 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 23:52:56 UTC, Basile B. wrote: On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote: Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template

Re: Passing anonymous templated functions as template parameters

2016-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/16 7:52 PM, Basile B. wrote: On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote: Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto

Re: Passing anonymous templated functions as template parameters

2016-06-15 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 22:27:38 UTC, pineapple wrote: Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){

Passing anonymous templated functions as template parameters

2016-06-15 Thread pineapple via Digitalmars-d-learn
Here's a simple code example to illustrate what I expected to work and didn't - is this a mistake in my syntax or a limitation of the language? template SomeTemplate(alias func){ auto templatefunc(T)(int x){ return func!T(x); } } // Valid auto

Re: Access template parameters?

2016-02-16 Thread Gavin Maye via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 19:00:19 UTC, Ali Çehreli wrote: std.traits.TemplateArgsOf: http://dlang.org/phobos/std_traits.html#TemplateArgsOf import std.traits; class Foo(type1,type2) {} class Bar(FooType) { // pragma(msg, TemplateArgsOf!FooType); alias ReturnType =

Re: Access template parameters?

2016-02-16 Thread Ali Çehreli via Digitalmars-d-learn
On 02/16/2016 10:34 AM, Gavin Maye wrote: Say you have class Foo(type1,type2) { } And a concrete Foo is passed as a parameter to another template, is there a way to get type1 and type2 from Foo so you can use them in the new template... For example.. class Bar(FooType) {

Access template parameters?

2016-02-16 Thread Gavin Maye via Digitalmars-d-learn
Say you have class Foo(type1,type2) { } And a concrete Foo is passed as a parameter to another template, is there a way to get type1 and type2 from Foo so you can use them in the new template... For example.. class Bar(FooType) { FooType.type1 DoSomething() { ... } } or Even

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issues.dlang.org/show_bug.cgi?id=15640 I would say it is not a bug

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:47:43 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 14:12:54 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it

Re: Variadic template parameters T... bounding

2016-02-02 Thread Voitech via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: [...] Two possible solutions... If you don't need to know the number of arguments at compile time, you can use normal variadic arguments: [...] Thank you I'll try

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:55:42 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 14:47:43 UTC, Marc Schütz wrote: if you mix ints and floats, the common type is deduced correctly: this is a bug for me :). I do not like this. I am ok with (u)byte to int conversion and similar,

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:12:54 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed:

Variadic template parameters T... bounding

2016-02-02 Thread Voitech via Digitalmars-d-learn
Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers import std.stdio; import std.meta:

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issues.dlang.org/show_bug.cgi?id=15640

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Jay Norwood via Digitalmars-d-learn
On Monday, 11 January 2016 at 00:50:37 UTC, Ilya Yaroshenko wrote: I will add such function. But it is not safe to do so (Slice can have strides not equal to 1). So it is like a hack ([0, 0, 0])[0 .. ret.elementsCount]). Have you made comparison between my and yours parallel versions?

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Jay Norwood via Digitalmars-d-learn
On Sunday, 10 January 2016 at 22:23:18 UTC, Ilya Yaroshenko wrote: Could you please provide full code and error (git gists)? -- Ilya ok, thanks. I'm building with DMD32 D Compiler v2.069.2 on Win32. The dub.json is included. https://gist.github.com/jnorwood/affd05b69795c20989a3

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Sunday, 10 January 2016 at 23:24:24 UTC, Jay Norwood wrote: On Sunday, 10 January 2016 at 22:23:18 UTC, Ilya Yaroshenko wrote: Could you please provide full code and error (git gists)? -- Ilya ok, thanks. I'm building with DMD32 D Compiler v2.069.2 on Win32. The dub.json is included.

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Jay Norwood via Digitalmars-d-learn
On Sunday, 10 January 2016 at 23:31:47 UTC, Ilya Yaroshenko wrote: Just use normal arrays for buffer (median accepts array on second argument for optimisation reasons). ok, I think I see. I created a slice(numTasks, bigd) over an allocated double[] dbuf, but slb[task] will be returning some

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Monday, 11 January 2016 at 00:39:04 UTC, Jay Norwood wrote: On Sunday, 10 January 2016 at 23:31:47 UTC, Ilya Yaroshenko wrote: Just use normal arrays for buffer (median accepts array on second argument for optimisation reasons). ok, I think I see. I created a slice(numTasks, bigd) over an

ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Jay Norwood via Digitalmars-d-learn
I cut this median template from Jack Stouffer's article and was attempting to use it in a parallel function. As shown, it builds and execute correctly, but it failed to compile if I attempting to use medians[i] = median(vec,slb[task]); in place of the medians[i] = median(vec,dbuf[j .. k]);

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Sunday, 10 January 2016 at 22:00:20 UTC, Jay Norwood wrote: I cut this median template from Jack Stouffer's article and was attempting to use it in a parallel function. As shown, it builds and execute correctly, but it failed to compile if I attempting to use medians[i] =

Re: ndslice, using a slice in place of T[] in template parameters

2016-01-10 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Sunday, 10 January 2016 at 23:24:24 UTC, Jay Norwood wrote: On Sunday, 10 January 2016 at 22:23:18 UTC, Ilya Yaroshenko wrote: Could you please provide full code and error (git gists)? -- Ilya ok, thanks. I'm building with DMD32 D Compiler v2.069.2 on Win32. The dub.json is included.

Re: Template Parameters in Struct Member Functions

2015-08-22 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 22 August 2015 at 16:49:26 UTC, DarthCthulhu wrote: I'm having difficulty understanding how templates operate as function parameters. Say I have this: struct ArrayTest { void arrayTest(T) (T arrayT) { writeln(arrayT); } } unittest { ArrayTest

Re: Template Parameters in Struct Member Functions

2015-08-22 Thread Mike Parker via Digitalmars-d-learn
); test.arrayTest!(float, 1)(farray); Sorry, that should be: test.arrayTest!(float[], 1)(farray); In your template declaration, you have declared two template parameters, T and passing, and one function parameter, arrayT. It is equivalent to: template arrayTest(T, int passing) { void arrayTest(T

Template Parameters in Struct Member Functions

2015-08-22 Thread DarthCthulhu via Digitalmars-d-learn
to match): void arrayTest(T, int passing) (T arrayT) { ... } I get 'cannot deduce function from argument types' errors. Specifically stating the type of the function doesn't seem to help: test.arrayTest(float [])(farray, 1); There must be a way to mix template and non-template parameters, right

Re: Is there a way to get the types of all template parameters?

2015-06-04 Thread Meta via Digitalmars-d-learn
On Thursday, 4 June 2015 at 13:38:20 UTC, Atila Neves wrote: For regular runtime parameters, there's ParameterTypeTuple. How would I write an equivalent template for template parameters? i.e. void fun(Foo foo, Bar bar)() {} alias types = CtParameterTypeTuple!fun; //TypeTuple!(Foo

Re: Structs as template parameters: weird error message

2015-04-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 2 April 2015 at 23:12:25 UTC, biozic wrote: The code below doesn't compile. Why this error message? --- struct Item { int i; } struct Params { Item* item; this(int i) { item = new Item(i); // line 9 } } struct Foo(Params params) {} enum foo =

Structs as template parameters: weird error message

2015-04-02 Thread biozic via Digitalmars-d-learn
The code below doesn't compile. Why this error message? --- struct Item { int i; } struct Params { Item* item; this(int i) { item = new Item(i); // line 9 } } struct Foo(Params params) {} enum foo = Foo!(Params(1)); --- test.d(9): Error: Item(1) is not an lvalue

expand variadic template parameters

2015-03-10 Thread André
Hi, in this minified example I try to expand the variadic parmaters of foo to bar: import std.typecons; void foo(T ...)(T args) { bar(args.expand); } void bar(int i, string s){} void main() { foo(1, a); } I got the syntax error: no property 'expand' for type '(int, string)' I

Re: expand variadic template parameters

2015-03-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 19:11:22 UTC, André wrote: Is there a simple way to get it working? The simplest: just write `bar(args);` - the variadic arguments will automatically expand.

Re: expand variadic template parameters

2015-03-10 Thread ketmar via Digitalmars-d-learn
On Tue, 10 Mar 2015 19:11:21 +, André wrote: Hi, in this minified example I try to expand the variadic parmaters of foo to bar: import std.typecons; void foo(T ...)(T args) { bar(args.expand); } void bar(int i, string s){} void main() { foo(1, a); } I

  1   2   >