Re: Given two AliasSeq (A and B) and template T, how to make AliasSeq!(T!(A[0], B[0]) ... T!(A[n], B[n])) ?

2016-11-26 Thread Nicholas Wilson via Digitalmars-d-learn

On Sunday, 27 November 2016 at 06:01:13 UTC, Tofu Ninja wrote:

Basically the title says it all.

alias A = AliasSeq!(...);
alias B = AliasSeq!(...);
static assert(A.length == B.length);
template T(An, Bn){ ... }
alias C = AliasSeq!(T!(A[0], B[0]) ... T!(A[n], B[n])); // how 
to make this :/


How do I actually make the sequence C?


Whoops it would help if I read your question.

You want to use Iota in conjunction with staticMap.
alias pairs(int N, alias a, alias b) = AliasSeq(a[N],b[N]);
alias C = staticMap!(T,staticMap(pairs,Iota!N));


Re: Given two AliasSeq (A and B) and template T, how to make AliasSeq!(T!(A[0], B[0]) ... T!(A[n], B[n])) ?

2016-11-26 Thread Nicholas Wilson via Digitalmars-d-learn

On Sunday, 27 November 2016 at 06:01:13 UTC, Tofu Ninja wrote:

Basically the title says it all.

alias A = AliasSeq!(...);
alias B = AliasSeq!(...);
static assert(A.length == B.length);
template T(An, Bn){ ... }
alias C = AliasSeq!(T!(A[0], B[0]) ... T!(A[n], B[n])); // how 
to make this :/


How do I actually make the sequence C?


AliasSeq s auto expand. so

alias C = AliasSeq!(A,B);


How to get hash value of an object?

2016-11-26 Thread panmengh via Digitalmars-d-learn

How to get hash value of an object?

Use hashOf? or typeid(T).getHash(&o)?

I test with the following code:

System:
windows 10

dmd --version
DMD32 D Compiler v2.072.0 (official download version)

ldc2 --version
LDC - the LLVM D compiler (1.1.0git-62a2252) (the latest git 
master version)

  based on DMD v2.071.2 and LLVM 3.9.1git

import std.stdio;

void main()
{
string[string] a;
string[string] b0;

writeln(a.hashOf(), "\t\t",typeid(typeof(a)).getHash(&a), 
"\t\t\t",
b0.hashOf(), "\t\t",typeid(typeof(b0)).getHash(&b0), "  
", a,);


a["1"] = "1";
string[string] b1 = ["1":"1"];
writeln(a.hashOf(), "\t\t",typeid(typeof(a)).getHash(&a), 
"\t\t",
b1.hashOf(), "\t\t",typeid(typeof(b1)).getHash(&b1), "  
", a,);


a["9"] = "9";
string[string] b2 = ["1":"1", "9":"9"];
writeln(a.hashOf(), "\t\t",typeid(typeof(a)).getHash(&a), 
"\t\t\t",
b2.hashOf(), "\t\t",typeid(typeof(b2)).getHash(&b2), "  
", a,);


a["3"] = "3";
string[string] b3 = ["1":"1", "9":"9", "3":"3"];
writeln(a.hashOf(), "\t\t",typeid(typeof(a)).getHash(&a), 
"\t\t",
b3.hashOf(), "\t\t",typeid(typeof(b3)).getHash(&b3), "  
", a,);


a.remove("1");
a["1"] = "1";
string[string] b4 = ["1":"1", "9":"9", "3":"3"];
writeln(a.hashOf(), "\t\t",typeid(typeof(a)).getHash(&a), 
"\t\t",
b3.hashOf(), "\t\t",typeid(typeof(b4)).getHash(&b4), "  
", a,);

}

Output:
dub --compiler=dmd -a=x86_64
Running .\test2.exe
1669671676  0   1669671676  0   []
732702303   2197205690  683765274   3388425732  ["1":"1"]
732702303   0   912895782   0   ["1":"1", 
"9":"9"]
732702303   2197205690  4139255736  3388425732  ["3":"3", 
"1":"1", "9":"9"]
732702303   2197205690  4139255736  3388425732  ["3":"3", 
"1":"1", "9":"9"]


test2.exe (second run)
1669671676  0   1669671676  0   []
1608602074  122060002   2487796584  31054674["1":"1"]
1608602074  0   3256818953  0   ["1":"1", 
"9":"9"]
1608602074  122060002   667025292   31054674["3":"3", 
"1":"1", "9":"9"]
1608602074  122060002   667025292   31054674["3":"3", 
"1":"1", "9":"9"]


dub --compiler=ldc2 -a=x86_64
Running .\test2.exe
593689054   0   593689054   0   []
1747365348  1899073920  1747365348  1899073920  ["1":"1"]
3252326176  0   3252326176  0   ["1":"1", 
"9":"9"]
492636279   1899073920  492636279   1899073920  ["3":"3", 
"1":"1", "9":"9"]
492636279   1899073920  492636279   1899073920  ["3":"3", 
"1":"1", "9":"9"]


test2.exe (second run)
593689054   0   593689054   0   []
1747365348  2353409518  1747365348  2353409518  ["1":"1"]
3252326176  0   3252326176  0   ["1":"1", 
"9":"9"]
492636279   2353409518  492636279   2353409518  ["3":"3", 
"1":"1", "9":"9"]
492636279   2353409518  492636279   2353409518  ["3":"3", 
"1":"1", "9":"9"]


Does only hashOf with ldc2 return the right value?




Given two AliasSeq (A and B) and template T, how to make AliasSeq!(T!(A[0], B[0]) ... T!(A[n], B[n])) ?

2016-11-26 Thread Tofu Ninja via Digitalmars-d-learn

Basically the title says it all.

alias A = AliasSeq!(...);
alias B = AliasSeq!(...);
static assert(A.length == B.length);
template T(An, Bn){ ... }
alias C = AliasSeq!(T!(A[0], B[0]) ... T!(A[n], B[n])); // how to 
make this :/


How do I actually make the sequence C?


Is there some trait like getOverloads that works with mixin templates?

2016-11-26 Thread ArturG via Digitalmars-d-learn

a simple example:

mixin template v1()
{
void foo(){}
}

mixin template v2()
{
void foo(int){}
}

class Test
{
mixin v1;
mixin v2;
}

void main()
{
__traits(getOverloads, Test, "foo").length.writeln; // 0
}

i know you can use alias to manually make them visible for 
getOverloads.
but i could use a automated way, at least for unnamed template 
mixins

or to be able to merge all into the same named mixin scope.

is there a way to do this?


Re: non-constant expression ["foo":5, "bar":10, "baz":2000]

2016-11-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 26 November 2016 at 17:37:57 UTC, Paolo Invernizzi 
wrote:

This is stated in documentation [1]:


What's the link?

This is a known limitation, it has never worked. The docs should 
reflect that, though some day, it might start working.




non-constant expression ["foo":5, "bar":10, "baz":2000]

2016-11-26 Thread Paolo Invernizzi via Digitalmars-d-learn

This is stated in documentation [1]:

immutable long[string] aa = [
  "foo": 5,
  "bar": 10,
  "baz": 2000
];

unittest
{
assert(aa["foo"] == 5);
assert(aa["bar"] == 10);
assert(aa["baz"] == 2000);
}

But results to:

   Error: non-constant expression ["foo":5L, "bar":10L, 
"baz":2000L]


Known bug?
If yes, Is there the need to emend the documentation, till the 
bug is open?

---
/Paolo