Re: Typed variadic template syntax?

2014-01-31 Thread Timon Gehr
On 01/31/2014 03:32 AM, Idan Arye wrote: mixin({ foreach(...) { ... } }()) Except it doesn't work inside classes and structs - it complains that function literals cannot be class members. You have to define a named function and pollute the namespace. This is the corresponding issue:

Re: Typed variadic template syntax?

2014-01-30 Thread Idan Arye
On Wednesday, 29 January 2014 at 22:16:57 UTC, Peter Alexander wrote: On Wednesday, 29 January 2014 at 21:18:06 UTC, Etienne wrote: void exec(string command)(){ foreach(str ; choice.splitter(.)){ writeln(str); } } I'd like to take the opportunity to say how

Re: Typed variadic template syntax?

2014-01-30 Thread Ilya Yaroshenko
On Thursday, 30 January 2014 at 11:19:33 UTC, Idan Arye wrote: On Wednesday, 29 January 2014 at 22:16:57 UTC, Peter Alexander wrote: On Wednesday, 29 January 2014 at 21:18:06 UTC, Etienne wrote: void exec(string command)(){ foreach(str ; choice.splitter(.)){

Re: Typed variadic template syntax?

2014-01-30 Thread Dicebot
On Wednesday, 29 January 2014 at 22:16:57 UTC, Peter Alexander wrote: You can use TypeTuple for static foreach. ... This is why I think using term declaration foreach is less confusing. It is pretty much the same but shifts attention away from essentional use case.

Re: Typed variadic template syntax?

2014-01-30 Thread Timon Gehr
On 01/30/2014 03:08 PM, Ilya Yaroshenko wrote: 2) `foreach` creates it's own scope. This won't work: foreach(i; TypeTuple!(1,2,3)){ mixin(int num~i.stringof~;); } num1=1; num2=2; num3=3; writeln(num1,num2,num3); ... 2) no. This should work for compile time

Re: Typed variadic template syntax?

2014-01-30 Thread Ilya Yaroshenko
On Thursday, 30 January 2014 at 15:28:34 UTC, Timon Gehr wrote: On 01/30/2014 03:08 PM, Ilya Yaroshenko wrote: 2) `foreach` creates it's own scope. This won't work: foreach(i; TypeTuple!(1,2,3)){ mixin(int num~i.stringof~;); } num1=1; num2=2; num3=3;

Re: Typed variadic template syntax?

2014-01-30 Thread Etienne
On 2014-01-30 10:28 AM, Timon Gehr wrote: import std.typetuple, std.stdio; void main(){ foreach(i; TypeTuple!(1,2,3)){ mixin(int num~i.stringof~;); } num1=1; num2=2; num3=3; writeln(num1,num2,num3); } This written as a static foreach or declarative

Re: Typed variadic template syntax?

2014-01-30 Thread Ilya Yaroshenko
On Thursday, 30 January 2014 at 17:13:21 UTC, Ilya Yaroshenko wrote: On Thursday, 30 January 2014 at 15:28:34 UTC, Timon Gehr wrote: On 01/30/2014 03:08 PM, Ilya Yaroshenko wrote: 2) `foreach` creates it's own scope. This won't work: foreach(i; TypeTuple!(1,2,3)){ mixin(int

Re: Typed variadic template syntax?

2014-01-30 Thread Ilya Yaroshenko
On Thursday, 30 January 2014 at 17:12:51 UTC, Etienne wrote: On 2014-01-30 10:28 AM, Timon Gehr wrote: import std.typetuple, std.stdio; void main(){ foreach(i; TypeTuple!(1,2,3)){ mixin(int num~i.stringof~;); } num1=1; num2=2; num3=3; writeln(num1,num2,num3); }

Re: Typed variadic template syntax?

2014-01-30 Thread Idan Arye
On Thursday, 30 January 2014 at 14:08:27 UTC, Ilya Yaroshenko wrote: 1) You can use mixin(format(Prolog%(Begin%sEnd%)Epilog, CompileTimeRange)); See std.format for ranges and std.string.format. That works for simple cases. Complex cases require that you write a function and calling it with

Re: Typed variadic template syntax?

2014-01-30 Thread Dicebot
Andrei has stated at least once that he agrees about usefulness / necessity of declaration foreach. It is mostly matter of someone doing implementation, same as for many other hot discussed stuff.

Re: Typed variadic template syntax?

2014-01-30 Thread deadalnix
On Thursday, 30 January 2014 at 11:19:33 UTC, Idan Arye wrote: Two problems: 1) You can't use `foreach` outside functions. That means that you write: struct Foo{ foreach(i;TypeTuple!(1,2,3)){ mixin(int num~i.stringof~;); } } mixin({ foreach(...) { ... }

Re: Typed variadic template syntax?

2014-01-30 Thread Andrei Alexandrescu
On 1/30/14 12:33 PM, Dicebot wrote: Andrei has stated at least once that he agrees about usefulness / necessity of declaration foreach. It is mostly matter of someone doing implementation, same as for many other hot discussed stuff. Yah, we should have an easier means of iteratively injecting

Re: Typed variadic template syntax?

2014-01-30 Thread Idan Arye
On Thursday, 30 January 2014 at 23:06:36 UTC, deadalnix wrote: On Thursday, 30 January 2014 at 11:19:33 UTC, Idan Arye wrote: Two problems: 1) You can't use `foreach` outside functions. That means that you write: struct Foo{ foreach(i;TypeTuple!(1,2,3)){ mixin(int

Re: Typed variadic template syntax?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 09:50:13 UTC, Timon Gehr wrote: import std.range, std.algorithm; int value(int xs[]...) { return reduce!((a,b)=10*a+b)(0,xs.retro); } Sadly, you can't build a struct (with N int fields) or an enum this way.

Re: Typed variadic template syntax?

2014-01-29 Thread Timon Gehr
On 01/29/2014 08:01 AM, Andrei Alexandrescu wrote: int value(int xs[]...) { int result = 0; foreach (i; xs) { result += 10 * result + i; } return result; } unittest { static assert(value(1, 2) == 21); } ... import std.range, std.algorithm; int value(int xs[]...) {

Re: Typed variadic template syntax?

2014-01-29 Thread Andrei Alexandrescu
On 1/29/14 1:53 AM, Stanislav Blinov wrote: On Wednesday, 29 January 2014 at 09:50:13 UTC, Timon Gehr wrote: import std.range, std.algorithm; int value(int xs[]...) { return reduce!((a,b)=10*a+b)(0,xs.retro); } Sadly, you can't build a struct (with N int fields) or an enum this way.

Re: Typed variadic template syntax?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 16:39:31 UTC, Andrei Alexandrescu wrote: On 1/29/14 1:53 AM, Stanislav Blinov wrote: Sadly, you can't build a struct (with N int fields) or an enum this way. mixin m|

Re: Typed variadic template syntax?

2014-01-29 Thread Etienne
On Wednesday, 29 January 2014 at 09:53:15 UTC, Stanislav Blinov wrote: On Wednesday, 29 January 2014 at 09:50:13 UTC, Timon Gehr wrote: import std.range, std.algorithm; int value(int xs[]...) { return reduce!((a,b)=10*a+b)(0,xs.retro); } Sadly, you can't build a struct (with N int fields)

Re: Typed variadic template syntax?

2014-01-29 Thread Etienne
void exec(string command)(){ foreach(str ; choice.splitter(.)){ writeln(str); } } I'd like to take the opportunity to say how much I'd love to be able to do a static foreach rather than use recursion.

Re: Typed variadic template syntax?

2014-01-29 Thread Peter Alexander
On Wednesday, 29 January 2014 at 21:18:06 UTC, Etienne wrote: void exec(string command)(){ foreach(str ; choice.splitter(.)){ writeln(str); } } I'd like to take the opportunity to say how much I'd love to be able to do a static foreach rather than use

Re: Typed variadic template syntax?

2014-01-29 Thread inout
On Wednesday, 29 January 2014 at 07:02:00 UTC, Andrei Alexandrescu wrote: On 1/28/14 4:14 PM, bearophile wrote: This is not an enhancement request, but it presents a potential enhancement. This is C++11 code: templateint... digits struct value; template struct value { static const int v

Re: Typed variadic template syntax?

2014-01-29 Thread anonymous
On Wednesday, 29 January 2014 at 22:25:45 UTC, inout wrote: int value(int xs[]...) { int result = 0; foreach (i; xs) { result += 10 * result + i; } return result; } unittest { static assert(value(1, 2) == 21); } Andrei This allocates memory no

Typed variadic template syntax?

2014-01-28 Thread bearophile
This is not an enhancement request, but it presents a potential enhancement. This is C++11 code: templateint... digits struct value; template struct value { static const int v = 0; }; templateint first, int... rest struct valuefirst, rest... { static int const v = 10 *

Re: Typed variadic template syntax?

2014-01-28 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 00:14:31 UTC, bearophile wrote: On the other hand I don't know how much common are template instantiations with values all of the same type (like all ints as in this case) in D code. Opinions welcome. Bye, bearophile Well, if you're going for a direct

Re: Typed variadic template syntax?

2014-01-28 Thread Andrei Alexandrescu
On 1/28/14 4:14 PM, bearophile wrote: This is not an enhancement request, but it presents a potential enhancement. This is C++11 code: templateint... digits struct value; template struct value { static const int v = 0; }; templateint first, int... rest struct valuefirst, rest... {

Re: Typed variadic template syntax?

2014-01-28 Thread Jakob Ovrum
On Wednesday, 29 January 2014 at 07:02:00 UTC, Andrei Alexandrescu wrote: int value(int xs[]...) { Ew! :)