need help to check symbol is static variable or not

2024-07-01 Thread Dakota via Digitalmars-d-learn
this code give error: ```d static if( !__traits(compiles, mixin("enum v = V;")) ) { enum v = V; } ``` ```sh Error: static variable `NotWorkVar` cannot be read at compile time ``` V is alias get from `typeof(__traits(getMember, M, symbol)`, M is `module` from importC. the importC so

Why does this mixin fail to compile?

2024-07-01 Thread ryuukk_ via Digitalmars-d-learn
This simple mixin fails to compile, anyone know why? ```D mixin implement; mixin template implement() { mixin("struct _gen(T) {"); mixin("}"); } void main(){} ``` ``` onlineapp.d-mixin-5(5): Error: `}` expected following members in `struct` declaration onlineapp.d-mixin-5(5):

Re: Why does this mixin fail to compile?

2024-07-01 Thread Dennis via Digitalmars-d-learn
On Monday, 1 July 2024 at 09:25:39 UTC, ryuukk_ wrote: This simple mixin fails to compile, anyone know why? ```D mixin implement; mixin template implement() { mixin("struct _gen(T) {"); mixin("}"); } A string mixin must form a complete declaration / statement / expression / type, so

Re: Why does this mixin fail to compile?

2024-07-01 Thread ryuukk_ via Digitalmars-d-learn
On Monday, 1 July 2024 at 09:29:50 UTC, Dennis wrote: On Monday, 1 July 2024 at 09:25:39 UTC, ryuukk_ wrote: This simple mixin fails to compile, anyone know why? ```D mixin implement; mixin template implement() { mixin("struct _gen(T) {"); mixin("}"); } A string mixin must form a com

Re: Why does this mixin fail to compile?

2024-07-01 Thread drug007 via Digitalmars-d-learn
On 01.07.2024 12:39, ryuukk_ wrote: On Monday, 1 July 2024 at 09:29:50 UTC, Dennis wrote: On Monday, 1 July 2024 at 09:25:39 UTC, ryuukk_ wrote: This simple mixin fails to compile, anyone know why? ```D mixin implement; mixin template implement() {     mixin("struct _gen(T) {");     mixin("}"

Re: Why does this mixin fail to compile?

2024-07-01 Thread ryuukk_ via Digitalmars-d-learn
On Monday, 1 July 2024 at 10:20:25 UTC, drug007 wrote: On 01.07.2024 12:39, ryuukk_ wrote: On Monday, 1 July 2024 at 09:29:50 UTC, Dennis wrote: On Monday, 1 July 2024 at 09:25:39 UTC, ryuukk_ wrote: This simple mixin fails to compile, anyone know why? ```D mixin implement; mixin template im

Re: need help to check symbol is static variable or not

2024-07-01 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 1 July 2024 at 07:32:30 UTC, Dakota wrote: this code give error: ```d static if( !__traits(compiles, mixin("enum v = V;")) ) { enum v = V; } ``` __traits(compiles, ...) can't check if a declaration is valid directly. You have to wrap it in a function literal expression: ```d

Re: Why does this mixin fail to compile?

2024-07-01 Thread drug007 via Digitalmars-d-learn
On 01.07.2024 13:31, ryuukk_ wrote: On Monday, 1 July 2024 at 10:20:25 UTC, drug007 wrote: No problem, make a full string then mixin it. Your "no problem" = lot of string concatenation therefore slower and memory hungry, i have no desire to do that Do you think that string concatenation is

Re: Why does this mixin fail to compile?

2024-07-01 Thread ryuukk_ via Digitalmars-d-learn
Ok, i'll just do it and benchmark at the end Another question: Why doesn't this work?: ```D mixin implement; mixin template implement() { char[4096] buffer = 0; int pos = 0; void append(string str) { buffer[pos .. pos + str.length] = str[]; pos += str.length;

Re: Why does this mixin fail to compile?

2024-07-01 Thread drug007 via Digitalmars-d-learn
On 01.07.2024 15:26, ryuukk_ wrote: Ok, i'll just do it and benchmark at the end Another question: Why doesn't this work?: I'm pretty sure your code does not work the way you think it does. String Mixins and Template Mixins are two different things. If you want to use String Mixins just m

Re: Why does this mixin fail to compile?

2024-07-01 Thread monkyyy via Digitalmars-d-learn
On Monday, 1 July 2024 at 13:00:55 UTC, ryuukk_ wrote: i don't want string concatenation This limitation is very intentional, add it to the pile like file io in ctfe of stuff that the core devs think "you shouldnt even want that" for "safety"

Re: Why does this mixin fail to compile?

2024-07-01 Thread Dennis via Digitalmars-d-learn
On Monday, 1 July 2024 at 13:00:55 UTC, ryuukk_ wrote: please stick to what i wrote, i don't want string concatenation, i provide a reduced example from my project, everything should be a single template block, no extra functions other than the append() one Mixin templates are a declaration s

Re: need help to check symbol is static variable or not

2024-07-01 Thread Dakota via Digitalmars-d-learn
On Monday, 1 July 2024 at 11:15:46 UTC, Nick Treleaven wrote: On Monday, 1 July 2024 at 07:32:30 UTC, Dakota wrote: this code give error: ```d static if( !__traits(compiles, mixin("enum v = V;")) ) { enum v = V; } ``` __traits(compiles, ...) can't check if a declaration is valid directl

odbc error Im008 sql server :(

2024-07-01 Thread alina via Digitalmars-d-learn
hello people I need help to connect to sqlserver this is my code and that is the error returned ``` import odbc.sql; import odbc.sqlext; import odbc.sqlucode; import odbc.sqltypes; import std.stdio; import std.string : fromStringz, toStringz; version(Windows) { string connectionString = "Dr