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:
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
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(.)){
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.
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
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;
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
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
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);
}
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
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.
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(...) { ... }
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
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
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.
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[]...) {
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.
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|
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)
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.
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
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
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
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 *
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
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... {
On Wednesday, 29 January 2014 at 07:02:00 UTC, Andrei
Alexandrescu wrote:
int value(int xs[]...) {
Ew! :)
27 matches
Mail list logo