Re: struct sta­tic ini­tial­izer method apply to UDA

2018-12-06 Thread learnfirst1 via Digitalmars-d-learn
On Thursday, 6 December 2018 at 12:50:34 UTC, Radu wrote: On Thursday, 6 December 2018 at 11:09:47 UTC, Basile B. wrote: Which would be a real nice feature to have. this is what I need, I guess I has to wait.

struct sta­tic ini­tial­izer method apply to UDA

2018-12-06 Thread learnfirst1 via Digitalmars-d-learn
my question is how to easy use struct sta­tic ini­tial­izer method with UDA. Fake code: struct DbColumn { string name; boolunique ; boolsigned ; boolnullable ; } struct Order { uint id; @DbColumn({ .nullable= true}) // not

is function pointer least significant bit always zero ?

2018-10-27 Thread learnfirst1 via Digitalmars-d-learn
I plan to use function pointer least significant bit to store some information. If there is no GC on my system, I think it will help the memory is well aligned. The question is all the function least significant bit is zero ?

Re: betterC generate dynamic array throw Error: TypeInfo cannot be used with -betterC

2018-10-17 Thread learnfirst1 via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 16:50:36 UTC, Paul Backus wrote: You can't append to an array in betterC code, because making space for the new elements requires allocating memory, and that uses the GC. In theory, since you're only using the GC during CTFE, it shouldn't be a problem, but

Re: try find the fastest way to convert a group string into index?

2018-09-16 Thread learnfirst1 via Digitalmars-d-learn
On Sunday, 16 September 2018 at 11:51:24 UTC, learnfirst1 wrote: On Sunday, 16 September 2018 at 11:30:11 UTC, learnfirst1 wrote: On Sunday, 16 September 2018 at 10:14:24 UTC, Vladimir Panteleev wrote: I will test pcre solution vs mpfc for benchmark. the pcre is easy to deal with low/up

Re: try find the fastest way to convert a group string into index?

2018-09-16 Thread learnfirst1 via Digitalmars-d-learn
On Sunday, 16 September 2018 at 11:30:11 UTC, learnfirst1 wrote: On Sunday, 16 September 2018 at 10:14:24 UTC, Vladimir Panteleev wrote: It has to be case Case Insensitive, so before I run mpfh for each new request headers, I need to convert the keys into low or up case. this value can be

Re: try find the fastest way to convert a group string into index?

2018-09-16 Thread learnfirst1 via Digitalmars-d-learn
On Sunday, 16 September 2018 at 10:14:24 UTC, Vladimir Panteleev wrote: On Sunday, 16 September 2018 at 10:04:09 UTC, learnfirst1 wrote: how to make this more fast like with one loop and get the results. thanks for reply, minimal perfect hashing seems good for this task, I will do more test

try find the fastest way to convert a group string into index?

2018-09-16 Thread learnfirst1 via Digitalmars-d-learn
The use case is translate http header key into enum. this is the current code : https://run.dlang.io/is/lpw29w In this fake code I only list a few headers, it should be more. but less then 128 and only include the a few codes. how to make this more fast like with one loop and get the

is this a betterC bug ?

2018-08-14 Thread learnfirst1 via Digitalmars-d-learn
enum string[] a = ["a"]; extern(C) void main() { int i = 0; auto s = a[i]; } --- Error: TypeInfo cannot be used with -betterC

Re: why mixin template can not inclulde statement;

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 13:17:13 UTC, learnfirst1 wrote: this work, it report no error but give a link problem. (this could be a bug ?) mixin template test(A...){ __gshared int a = A[0]; pragma(inline, true) // remove this will work static extern(C) int test(){

Re: why mixin template can not inclulde statement;

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 13:10:57 UTC, Kagamin wrote: On Friday, 10 August 2018 at 13:01:21 UTC, learnfirst1 wrote: Looks like some problem with tuple, try __gshared a = A[0]; this work, it report no error but give a link problem. (this could be a bug ?)

Re: why mixin template can not inclulde statement;

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 13:05:24 UTC, Kagamin wrote: Mixim template can only introduce declarations, not statements, a workaround is a lambda called in place. mixin template test(A...){ __gshared a = A; int dummy = (){ a++; return 0; }(); } extern(C) void main(){

Re: why mixin template can not inclulde statement;

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 12:38:55 UTC, learnfirst1 wrote: mixin template test(A...){ mixin template test(A...){ __gshared a = A; } extern(C) void main(){ mixin test!123; } --- duplicate symbol __D4test4mainUZ8__mixin111__a_field_0i in: test.o ld: 1

why mixin template can not inclulde statement;

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
mixin template test(A...){ __gshared a = A; a++; } extern(C) void main(){ mixin test!123; } - I dont want to use string mixin to intro a lot un want symbol, try with mixin template find this not work. I know if mixin test on global it should not working,

Re: is this a bug ? mixin template static function missing!

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 12:05:52 UTC, Simen Kjærås wrote: On Friday, 10 August 2018 at 11:17:10 UTC, learnfirst1 wrote: If you try the same without the mixin template, you'll see that it doesn't work: struct Test { extern(C) pragma(crt_constructor) static void init(){ // work

Re: is this a bug ? mixin template static function missing!

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 10:24:55 UTC, Simen Kjærås wrote: On Friday, 10 August 2018 at 08:31:21 UTC, learnfirst1 wrote: Filed a bug: https://issues.dlang.org/show_bug.cgi?id=19153 template G(){ pragma(crt_constructor) static extern(C) void init(){} } void main(){ mixin G!(); //

Re: is this a bug ? mixin template static function missing!

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 10:24:55 UTC, Simen Kjærås wrote: On Friday, 10 August 2018 at 08:31:21 UTC, learnfirst1 wrote: The correct behavior would be for the compiler to show the latter error message for a mixin'd function as well. Filed a bug:

Re: templated lambda with {} cause GC

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
On Friday, 10 August 2018 at 10:38:53 UTC, Simen Kjærås wrote: What you should do instead is: T!((t){ printf("test 2 name = %s\n".ptr, t.name.ptr); }, "test"); (note the lack of the => arrow) -- Simen rikki cattermole , Paul Backus, Simen Kjærås: thanks for the

templated lambda with {} cause GC

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
import core.stdc.stdio; struct Test { string name ; } void T(alias pred, A...)(){ __gshared t = Test(A) ; pred(t); } extern(C) void main(){ T!(t => printf("test 1 name = %s\n".ptr, t.name.ptr), "test") ; // build OK T!(t => { printf("test

is this a bug ? mixin template static function missing!

2018-08-10 Thread learnfirst1 via Digitalmars-d-learn
#!/usr/bin/env rdmd import core.stdc.stdio; template G(size_t line = __LINE__, A...){ int i = 3; static extern(C) pragma(crt_constructor) void init2(){ printf("init: %d\n", line); } } pragma(crt_constructor) extern(C) void init1(){ printf("init

Re: variable _param_0 cannot be read at compile time

2018-08-09 Thread learnfirst1 via Digitalmars-d-learn
On Thursday, 9 August 2018 at 13:42:03 UTC, Kagamin wrote: struct M { int i; S*[100] s; } struct S { M* mp; bool x; } S* add(A...)() { alias m = A[0]; __gshared s = S(,A[1..$]); m.s[m.i++] = return } void main(){

Re: variable _param_0 cannot be read at compile time

2018-08-08 Thread learnfirst1 via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 13:13:42 UTC, Simen Kjærås wrote: On Wednesday, 8 August 2018 at 12:57:43 UTC, learnfirst1 wrote: Why this is a error ? ``` struct S { bool v; string x; } S* add(A...)(ref A a) { __gshared s = S(a); return } void main(){

Re: variable _param_0 cannot be read at compile time

2018-08-08 Thread learnfirst1 via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 12:57:43 UTC, learnfirst1 wrote: Why this is a error ? this code example can explain what I am try to do here: struct M { int i; S*[100] s; } struct S { M* mp; bool x; } S* add(A...)(ref A a) { __gshared s = S(a);

variable _param_0 cannot be read at compile time

2018-08-08 Thread learnfirst1 via Digitalmars-d-learn
Why this is a error ? ``` struct S { bool v; string x; } S* add(A...)(ref A a) { __gshared s = S(a); return } void main(){ auto p = add(true); } ``` test.d(9): Error: variable _param_0 cannot be read at compile time test.d(14): Error: template instance