Re: __asm LDC2: Attribute 'elementtype' type does not match parameter!

2024-06-25 Thread realhet via Digitalmars-d-learn
Update: I downloaded the latest LDC. (I waited with this version catch up long ago.) The above __asm inlining works fine on version LDC2 1.38.

__asm LDC2: Attribute 'elementtype' type does not match parameter!

2024-06-25 Thread realhet via Digitalmars-d-learn
Hi, I'm switching from LDC2 1.28 to 1.35, and trying to solve some problems on the way. Target: 64bit Windows. The problematic code: ``` const tmp = __asm!size_t( "pcmpestri $5,$3,$1" // 01 2 3 45 , "={RCX},x,{RAX},*p,{RDX},i,~{flags}", charSetVec

Re: Call an external program from CTFE

2024-06-24 Thread realhet via Digitalmars-d-learn
On Sunday, 23 June 2024 at 16:42:43 UTC, Richard (Rikki) Andrew Cattermole wrote: See above why the string imports was designed that way. I totally forgot the name "string imports". Now I remember, thanks. That's one data direction of the 2.

Re: Call an external program from CTFE

2024-06-24 Thread realhet via Digitalmars-d-learn
On Sunday, 23 June 2024 at 16:46:05 UTC, monkyyy wrote: On Sunday, 23 June 2024 at 16:33:54 UTC, realhet wrote: realistically you should just write a build script with two stages fun thought experiment time, if you found a programmable "FUSE"(file system api) database of some sort, mixed `-J`

Call an external program from CTFE

2024-06-23 Thread realhet via Digitalmars-d-learn
Hi, Is there a way to call an external program from CTFE? Use case: Inside a module I want to put some GLSL code. I also want to generate that GLSL code using CTFE. And when it's done, it would be nice if I was able to save that GLSL code into a temp file and call the glsl compiler on it. The

Re: aligned struct field weirdness

2024-06-18 Thread realhet via Digitalmars-d-learn
On Tuesday, 18 June 2024 at 02:26:00 UTC, Steven Schveighoffer wrote: All the code you posted here looks fine to me. It compiles and runs fine on run.dlang.io (even with the `version(none)` changed to `version(all)`, or using `scoped!B`). Thank You for checking. Also to add to the weirdness,

aligned struct field weirdness

2024-06-17 Thread realhet via Digitalmars-d-learn
Hello, I'm having a weird case of access violation. I tried to narrow the problem and put up a reproducible testCase on compilerexploer, but it requires my framework too which overrides std.stdio.writeln() in order to produce colorful text, and logging, etc. The error is an access violation

Re: Circular enum member references in UDAs

2024-02-15 Thread realhet via Digitalmars-d-learn
On Thursday, 15 February 2024 at 20:10:15 UTC, Paul Backus wrote: On Thursday, 15 February 2024 at 18:12:42 UTC, realhet wrote: There was an attempt to fix it, but it looks like the PR author wasn't able to get it working correctly in all cases. That means I will solve this by putting the UDAs

Re: Is there a way to tell LDC2 to only check the syntax of the source file?

2023-12-06 Thread realhet via Digitalmars-d-learn
On Wednesday, 6 December 2023 at 11:53:09 UTC, realhet wrote: Hello, I've found another trick: - prepend "version(none):" in front of the source. - ignore the optional "Error: declaration expected, not `module`" message - Take seriously all the other errors, those are only syntax errors, se

Is there a way to tell LDC2 to only check the syntax of the source file?

2023-12-06 Thread realhet via Digitalmars-d-learn
Hello, I can turn off linking with -c I can turn off compiling with-o- How can I turn it off before the semantic passes? I'm experimenting with a nasty trink: I prepend "__undefinied__ _;" into the tested code. And if I get an error: Error: undefined identifier `__undefinied__` I know

Re: Getting __COLUMN__ of source code location.

2023-07-29 Thread realhet via Digitalmars-d-learn
On Thursday, 27 July 2023 at 16:17:28 UTC, IchorDev wrote: I'm not aware of any way to do that exact thing. Measuring what column a line is on would be quite subjective. When I compile(LDC2) a something with an error and using the --vcolumns argument I get this: onlineapp.d(14,5): Error: found

Getting __COLUMN__ of source code location.

2023-07-23 Thread realhet via Digitalmars-d-learn
Hi, I can access the special tokens: __MODULE__, __LINE__, but how can I access the column. Is there a way to "hack" it out from LDC2? All the error messages contain column information, also I've found __traits(getLocation, symbol) also reporting the column. But how to get this information

Simple way to get Source Line Table of a compiled module.

2023-07-23 Thread realhet via Digitalmars-d-learn
Hi, I'm using LDC2 64bit on Windows. If I ask it to generate a .map file, I can locate the function. But how can I access the Line-code information? Do I need to generate a huge .pdb file with lots of other information (and also I have to understand it and extract the lines), or is there a li

Re: Complicated @property access only works when I write an extra parenthesis "()"

2023-05-27 Thread realhet via Digitalmars-d-learn
It seems like I managed to solve it. All the chain of properties now capturing a generic value type T. And finally the most inner associative array will handle the implicit cast. Maybe that extra implicit () got confused when the types are same, but the aliases to those types are different. o.O

Re: Complicated @property access only works when I write an extra parenthesis "()"

2023-05-26 Thread realhet via Digitalmars-d-learn
On Friday, 26 May 2023 at 21:11:45 UTC, Adam D Ruppe wrote: On Friday, 26 May 2023 at 21:00:20 UTC, realhet wrote: Only the extra () let it compile successfuly. No way to fix it. If the function takes an extra argument you can kinda trick it but for zero arg function pointer return from a pr

Re: Complicated @property access only works when I write an extra parenthesis "()"

2023-05-26 Thread realhet via Digitalmars-d-learn
On Friday, 26 May 2023 at 21:00:20 UTC, realhet wrote: Update: ``` auto x = karcSamples[a.key].lod0; print(x._size); auto y = karcSamples[a.key].lod0(); print(y._size); with(karcSamples[a.key].lod0) print(_size); with(karcSamples[a.key].lod0()) print(_size); ``` When I put it into a tem

Complicated @property access only works when I write an extra parenthesis "()"

2023-05-26 Thread realhet via Digitalmars-d-learn
Hello, I tried to narrow the problem and make a small example, but I've failed. I try to describe the syndrome, maybe someone knows about it. (I heard that @properties are not 100% functional, maybe it's because of that, I dunno...) With pragma msg, I verify the time of things: karcSamples

Re: string to char[4] FourCC conversion

2023-05-26 Thread realhet via Digitalmars-d-learn
On Friday, 26 May 2023 at 13:18:15 UTC, Steven Schveighoffer wrote: This worked for me: ```d char[4] fourC(string s) { if(s.length >= 4) return s[0 .. 4]; char[4] res = 0; res[0 .. s.length] = s; return res; } ``` Sometimes I forget that the return does an implicit cast

string to char[4] FourCC conversion

2023-05-26 Thread realhet via Digitalmars-d-learn
Hello, Is there a way to do it nicer/better/faster/simpler? ``` char[4] fourC(string s) { uint res;//Zero initialized, not 0xff initialized. autocnt = min(s.length, 4), p = cast(char[4]*)(&res); (*p)[0..cnt] = s[0..cnt]; return *p; } ``` I tri

Re: core.simd ubyte16 initialization weirdness.

2023-05-08 Thread realhet via Digitalmars-d-learn
On Monday, 8 May 2023 at 11:43:33 UTC, Richard (Rikki) Andrew Cattermole wrote: Don't forget to type bad2 which gives the same result as the good one. Otherwise it only has 7 elements in it. Thank You, now that's good too. So here are the weird stuff: Pure arrays produce errors: enum ubyte16

Re: core.simd ubyte16 initialization weirdness.

2023-05-08 Thread realhet via Digitalmars-d-learn
On Monday, 8 May 2023 at 08:05:13 UTC, Richard (Rikki) Andrew Cattermole wrote: Yes, there is a pragma msg bug, but there is also a functionality 'bug'. I collected some more info: ``` import std, core.simd, ldc.llvmasm; T pshufb(T, U)(T a, in U b) { return __asm!ubyte16("pshufb $2, $1", "

core.simd ubyte16 initialization weirdness.

2023-05-07 Thread realhet via Digitalmars-d-learn
Hello, ``` import std, core.simd; void main() { enum ubyte16 good1 = mixin([1, 2, 3, 4]), bad = [1, 2, 3, 4]; static immutable ubyte16 good2 = mixin([1, 2, 3, 4]), crash = [1, 2, 3, 4]; pragma(msg, good1); pragma(msg, bad); pragma(msg, good2)

Re: Terminating the process of a running LDC2 compiler.

2023-03-03 Thread realhet via Digitalmars-d-learn
On Friday, 3 March 2023 at 14:33:08 UTC, Imperatorn wrote: We don't know what you mean by your definition of safe unfortunately For example killing ldc2.exe while it writes some cached temp files. And when the next time it tries to load those corrupted files, it will crash, or generate wrong

Terminating the process of a running LDC2 compiler.

2023-03-01 Thread realhet via Digitalmars-d-learn
Hello, Is it safe to kill an ongoing LDC2 process on Windows? My situation is this: - I launch 8 LDC2 compilation command lines on 8 DLang source files. - One of them has a compilation error and quits. - At this point I wait the completion of the other threads, but it would be faster to kill

Re: Transform static immutable string array to tuple.

2023-02-19 Thread realhet via Digitalmars-d-learn
Awesome, Thank both of you! ``` enum a = ["A", "B"]; writeln(a); writeln(aliasSeqOf!a); writeln([aliasSeqOf!a]); ```

Transform static immutable string array to tuple.

2023-02-19 Thread realhet via Digitalmars-d-learn
Hello, Is there a better way to transform a string array to a tuple or to an AliasSeq? ``` mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`) ``` I'd like to use this as variable length arguments passed to the startsWith() std function (as multiple needles).

Re: Structure initializer VS lambda function

2023-02-19 Thread realhet via Digitalmars-d-learn
Hi again and thanks for the suggestions. I ended up checking every {} block with the following program: It works on a string where all the nested blocks are reduced to a single symbol. For example: '{', '"', '[' And all the comments and whitespaces are reduced to ' ' space. ``` enum CurlyBlock

Structure initializer VS lambda function

2022-12-12 Thread realhet via Digitalmars-d-learn
Hi, I'm writing a DLang parser and got confused of this. What is a good way to distinguish lambda functions and structure initialization blocks. Both of them are {} blocks. I'm thinking of something like this: 1. checking inside (on the first hierarchy level inside {}) , => must be a st

Re: How is it possible that countUntil() generates a jump-table when the hayStack is a compile time array?

2022-10-01 Thread realhet via Digitalmars-d-learn
On Saturday, 1 October 2022 at 13:49:12 UTC, H. S. Teoh wrote: On Sat, Oct 01, 2022 at 01:20:08PM +, realhet via Digitalmars-d-learn wrote: It is very good to know. Thank You for the confirmation. Indeed it is really clever. I wrote a parser only to parse the structural elements of

How is it possible that countUntil() generates a jump-table when the hayStack is a compile time array?

2022-10-01 Thread realhet via Digitalmars-d-learn
Hello, I just wanted to optimize a byte -> index lookup, by using a 256 element table instead of using [1, 2, 3].countUntil(x) and I was amazed what I've found. My solution lookup[x] was not faster at all, because LDC2 amazingly optimized the linear search to a jump table. Anyone please can

Re: Is it possible to return mutable and const range from a single method?

2022-08-22 Thread realhet via Digitalmars-d-learn
On Monday, 22 August 2022 at 19:35:11 UTC, Steven Schveighoffer wrote: It is possible to write the same function for both const and mutable overloads by using the `this` template parameter: I guess before the "inout", "this This" was the only way to do this. I must remember this, it's really u

Is it possible to return mutable and const range from a single method?

2022-08-22 Thread realhet via Digitalmars-d-learn
Hello, I managed to make a universal getParent() function which can preserve constness. I also had success with inout functions that work with this inout getParent method. Is it possible to do something like this but for the allParents input range producer method? In the const range implementa

Re: std.algorithm.cmp is conflicting with itself.

2022-08-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 August 2022 at 02:13:48 UTC, bachmeier wrote: Informative error message I'm making something like an IDE. The text search function in it is able to search across all user modules. I thought about filtering the search results by context. The following contexts are planned already

Re: std.algorithm.cmp is conflicting with itself.

2022-08-11 Thread realhet via Digitalmars-d-learn
On Thursday, 11 August 2022 at 19:33:31 UTC, bachmeier wrote: std.string does a public import of std.algorithm.cmp. That was it! Thanks! Conclusion: This is how to overload cmp() ```d //this is the only place from where all other modules can see these std modules public import std.string, s

Re: std.algorithm.cmp is conflicting with itself.

2022-08-11 Thread realhet via Digitalmars-d-learn
On Thursday, 11 August 2022 at 18:10:31 UTC, Paul Backus wrote: ... If you remove `std.algorithm` from `testcmpmodule2`'s `public import` line, the code compiles successfully. Yes, but in the 40 module project I'm unable to make it work. I doublechecked that the only public import of std.algori

std.algorithm.cmp is conflicting with itself.

2022-08-11 Thread realhet via Digitalmars-d-learn
Hello, I try to make an overload group of cmp() functions in my utility module but everything works well except when I import some 3rd party module that imports std.algorithm. Then I get an error: C:\D\testCmpOverload.d(11,8): Error: function `std.algorithm.comparison.cmp!(string, string).cmp`

Using LDC2 with --march=amdgcn

2022-07-24 Thread realhet via Digitalmars-d-learn
Hello, I noticed that the LDC2 compiler has an architecture target called "AMD GCN". Is there an example code which is in D and generates a working binary of a hello world kernel. I tried it, and just failed at the very beginning: How can I specify __kernel and __global in D?

Re: Unable to use map() and array() inside a class-field's initializer.

2022-07-14 Thread realhet via Digitalmars-d-learn
On Thursday, 14 July 2022 at 14:41:53 UTC, Paul Backus wrote: Explicit type annotation: vvv Thank You! I will remember that in case of weird errors I can try to help the compiler with type inference.

Unable to use map() and array() inside a class-field's initializer.

2022-07-14 Thread realhet via Digitalmars-d-learn
Hello, Somehow it can't reach map and array inside a class field initializer. If I put that small expression inside a function, it works. If I encapsulate the initializer expression into a lambda and evaluate it right away, it also works. Only the nice form fails. Why is that? ```d import

Re: static assert("nothing")

2022-05-31 Thread realhet via Digitalmars-d-learn
On Tuesday, 31 May 2022 at 09:35:30 UTC, Andrea Fontana wrote: On Tuesday, 31 May 2022 at 08:51:45 UTC, realhet wrote: Check if that string is init. assert("", "cool"); assert("ehh", "cool"); assert(string.init, "Not cool"); I feel some "JavaScript equality operator" vibes in this :D Anyways,

static assert("nothing")

2022-05-31 Thread realhet via Digitalmars-d-learn
Hi, In my framework I just found a dozen of compile time error handling like: ...else static assert("Invalid type"); This compiles without error. And it was useless for detecting errors because I forgot the first "false" or "0" parameter. I think it is because of the weird case of "every s

Re: Creating a custom iota()

2022-05-12 Thread realhet via Digitalmars-d-learn
On Thursday, 12 May 2022 at 20:12:19 UTC, Ali Çehreli wrote: And I've been thinking 'iota' may not be as suitable as I thought at first. I like the following even more: auto r0 = st .by(Duration(2)) .take(5); So I wrote this by() for my DateTime and then: import

Re: Creating a custom iota()

2022-05-12 Thread realhet via Digitalmars-d-learn
On Thursday, 12 May 2022 at 17:06:39 UTC, Ali Çehreli wrote: I don't care whether it is good practice or not. :) The following is what you meant anyway and seems to work. I restricted the parameter types to the ones I wanted to use. And for the standard iota behavior I used a public import.

Re: Creating a custom iota()

2022-05-12 Thread realhet via Digitalmars-d-learn
On Thursday, 12 May 2022 at 16:57:35 UTC, H. S. Teoh wrote: Does your DateTime type support the `++` operator? It can't because I only want to use the quantities.si.Time type to do arithmetic with my DateTime. In my previous DateTime, it was a lot of problem that I was doing math on it's raw

Creating a custom iota()

2022-05-12 Thread realhet via Digitalmars-d-learn
Hello, I have my own DateTime struct. It has opCmp() and opBinary(), I can do arithmetic with this custom DateTime and the amazing time units of the **quantities** package. Now I'm about mo make iterations in a DateTime range: const st = DateTime(UTC, "22.1.1 8:30").utcDayStart,

Re: How to use an existing D package in Visual D?

2022-04-05 Thread realhet via Digitalmars-d-learn
On Tuesday, 5 April 2022 at 09:57:29 UTC, Mike Parker wrote: On Tuesday, 5 April 2022 at 09:26:54 UTC, realhet wrote: You should compile the existing package as a library, then add the library file to the linker settings in VisualD. Thank You for the fast help! Currently I have my own build s

How to use an existing D package in Visual D?

2022-04-05 Thread realhet via Digitalmars-d-learn
Hello, I have all my D packages in the c:\D\libs\ directory. I added this path to the PropertyPages/Compiler/Additional Import Paths field. In the project source file I imported a module from my package using "import het.utils;" Also used a function from it. The syntax highlighter worked go

Re: Is it legal to remove a key from associative array while iterating over aa.keys if a foreach loop?

2021-08-29 Thread realhet via Digitalmars-d-learn
On Sunday, 29 August 2021 at 09:02:52 UTC, Mike Parker wrote: On Sunday, 29 August 2021 at 08:55:44 UTC, realhet wrote: Is it safe, or do I have to take a snapsot of the keys range like this? -> You shouldn't remove anything when iterating over `.keys` or `.values`. Use `.byKey` and `.byV

Is it legal to remove a key from associative array while iterating over aa.keys if a foreach loop?

2021-08-29 Thread realhet via Digitalmars-d-learn
Hi, //remap the result blobs foreach(k; res.blobs.keys){ int p = map(k); if(p!=k){ res.blobs[p].weight += res.blobs[k].weight; res.blobs.remove(k); } } It boils down to: foreach(k; aa.keys) aa.remove(k); Is it safe, or do I have to take a snapsot of the keys ra

Re: array inside a class + alias this + filter -> clears the array.

2021-07-07 Thread realhet via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 17:10:01 UTC, Paul Backus wrote: On Wednesday, 7 July 2021 at 16:20:29 UTC, realhet wrote: int[] opIndex() { return array; } Thx, I didn't know about this type of opSlice override. It works nicely. Now I have these choices: - write [] everywhere to access

array inside a class + alias this + filter -> clears the array.

2021-07-07 Thread realhet via Digitalmars-d-learn
Hi, I wanted to make a container class that exposes its elements using a simple "alias this", but getting weird errors: I test with the std.algorithm.filter template function. 1. when I use "alias this" on a function that returns a slice, making the internal array unreachable, filter just ca

Re: Is there a nicer way to get the first element or typeof(element).init from a range?

2021-05-30 Thread realhet via Digitalmars-d-learn
On Sunday, 30 May 2021 at 12:16:19 UTC, realhet wrote: presets.keys.sort.take(1).get(0); <- Oups: after fixing an error and making it compile the solution is even uglier: presets.keys.sort.take(1).array.get(0);

Is there a nicer way to get the first element or typeof(element).init from a range?

2021-05-30 Thread realhet via Digitalmars-d-learn
Hello, This is my current solution but there must be a better way to do it in D T get(T)(T[] arr, size_t idx, T def = T.init){ return idx

Re: Voldemort type "this" pointer

2021-04-22 Thread realhet via Digitalmars-d-learn
On Wednesday, 21 April 2021 at 15:53:59 UTC, Ali Çehreli wrote: On 4/21/21 8:37 AM, realhet wrote: On Wednesday, 21 April 2021 at 10:47:08 UTC, Mike Parker wrote: On Wednesday, 21 April 2021 at 10:00:51 UTC, realhet wrote: It has access to the context of its enclosing scope (via an added hidd

Re: Voldemort type "this" pointer

2021-04-21 Thread realhet via Digitalmars-d-learn
On Wednesday, 21 April 2021 at 10:47:08 UTC, Mike Parker wrote: On Wednesday, 21 April 2021 at 10:00:51 UTC, realhet wrote: It has access to the context of its enclosing scope (via an added hidden field). Thanks! So it is unsafe to return a non-static nested struct from a function. But it i

Voldemort type "this" pointer

2021-04-21 Thread realhet via Digitalmars-d-learn
Hi, I noticed that there is a hidden "this" pointer in a struct that I declare inside a body of a function. Also noticed when I use the "static" keyword, the "this" pointer disappears. My question is about what is the "this" pointer for. Is it for storing the stack frame of the function in o

Re: lockstep works with .each, but fails with .map

2021-03-05 Thread realhet via Digitalmars-d-learn
On Friday, 5 March 2021 at 19:26:38 UTC, Jacob Carlborg wrote: On 2021-03-05 19:49, realhet wrote: Why it works with each (or foreach), but not with map? o.O `lockstep` is specifically designed to work with `foreach`. I think `each` has a special case to work with `lockstep`. If you want to

lockstep works with .each, but fails with .map

2021-03-05 Thread realhet via Digitalmars-d-learn
Hi What am I doing wrong here? import std.stdio, std.range, std.algorithm, std.uni, std.utf, std.conv, std.typecons, std.array; auto SE(A, B)(in A a, in B b){ return (a-b)^^2; } void main(){ auto a = [1, 2, 3], b = [1, 1, 1]; lockstep(a, b, StoppingPolicy.requireSameLength).each!(

Re: How to capture a BitFlags type in a function parameter?

2021-01-31 Thread realhet via Digitalmars-d-learn
On Sunday, 31 January 2021 at 14:16:15 UTC, Paul Backus wrote: On Sunday, 31 January 2021 at 14:04:00 UTC, realhet wrote: Hi, static void stdUI(E, Flag!"unsafe" u)(ref BitFlags!(E, u) flags) {} Thank You! Somehow I forgot I could pass amd match ANY TYPE in the template parameters. I'll

How to capture a BitFlags type in a function parameter?

2021-01-31 Thread realhet via Digitalmars-d-learn
Hi, I wan't to process every specialization of the BitFlags struct in a function: So far the best I can come up is this: static void stdUI(F)(ref F flags) if(F.stringof.startsWith("BitFlags!(")){} But it's obviously lame. If I try this way: static void stdUI(E, U)(ref BitFlags!(E, U) f

Re: Is there a standard function that combines take() and popFrontExactly()

2020-12-14 Thread realhet via Digitalmars-d-learn
On Monday, 14 December 2020 at 14:16:41 UTC, Dukc wrote: On Friday, 11 December 2020 at 19:07:23 UTC, realhet wrote: I've just made this unicode wordreplacer function working, but It seems not too nice and functional-ish. Are there ways to make it more simple? To answer the title, yes there

Is there a standard function that combines take() and popFrontExactly()

2020-12-11 Thread realhet via Digitalmars-d-learn
Hi, I've just made this unicode wordreplacer function working, but It seems not too nice and functional-ish. Are there ways to make it more simple? import std.stdio, std.range, std.algorithm, std.uni, std.utf, std.conv; bool isWordChar(dchar ch){ return isAlphaNum(ch) || ch=='_'; } st

Re: Handling referencing class parent instances in a GC friendly way.

2020-11-30 Thread realhet via Digitalmars-d-learn
On Monday, 30 November 2020 at 14:36:08 UTC, FeepingCreature wrote: On Monday, 30 November 2020 at 14:33:22 UTC, realhet wrote: ... Though you may want to do `items = null;` too. I just forgot 1 of three things, thx for pointing it out. And I also forget to notify the parent to remove the refer

Handling referencing class parent instances in a GC friendly way.

2020-11-30 Thread realhet via Digitalmars-d-learn
Hi, class A{ A parent; A[] items; void myDestroy(){ items.each!(i => i.myDestroy); parent = null; // after this point I think the GC will release it automatically, and it will call ~this() too. Am I right? } } I have a hierarchy of class instances forward and backward link

Re: C++ or D?

2020-11-09 Thread realhet via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: Hi all, my question would be about using D or not using D. Here are some things you will NOT get in D: youtube -> Dconf 2014 Day 2 Keynote: The Last Thing D Needs -- Scott Meyers For example, you will not get neurosis from it, or bad

Compile-time function call with transformed parameters

2020-10-14 Thread realhet via Digitalmars-d-learn
Hi, Is there a way to make this in a nicer way without the string mixin? private auto generateVector(CT, alias fun, T...)(in T args){ static if(anyVector!T){ Vector!(CT, CommonVectorLength!T) res; static foreach(i; 0..res.length) res[i] = mixin("fun(", T.length.iota.map!(j => "args[

Re: Getting Field Names of a specific UDA in compile time.

2020-10-03 Thread realhet via Digitalmars-d-learn
On Saturday, 3 October 2020 at 14:00:30 UTC, Adam D. Ruppe wrote: On Saturday, 3 October 2020 at 13:10:31 UTC, realhet wrote: I only managed to get the string[] by making a static foreach, but I don't know how to put that in an enum xxx = ...; statement. There's always other ways but general

Getting Field Names of a specific UDA in compile time.

2020-10-03 Thread realhet via Digitalmars-d-learn
Hi, class Printer{ @("NODES") int gem1, gem2, gem3, gem4, gem5, head1, head2, head3, head4; import std.traits, std.meta; alias Nodes = getSymbolsByUDA!(typeof(this), "NODES"); enum NodeNames = ["gem1", "gem2", ]; } Is there a way to make an enum like the above with compile time p

Re: Struct initializer in UDA

2020-09-27 Thread realhet via Digitalmars-d-learn
On Sunday, 27 September 2020 at 11:59:49 UTC, Anonymouse wrote: On Sunday, 27 September 2020 at 10:17:39 UTC, realhet wrote: On Saturday, 26 September 2020 at 17:13:17 UTC, Anonymouse wrote: On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote: That looks the closes to the python nam

Re: Struct initializer in UDA

2020-09-27 Thread realhet via Digitalmars-d-learn
On Saturday, 26 September 2020 at 17:13:17 UTC, Anonymouse wrote: On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote: The closest I can get is @(S.init.c(9).f(42)) with use of opDispatch, which is easier to read but still ugly. All I can get is that the - an identifier of a member i

Struct initializer in UDA

2020-09-26 Thread realhet via Digitalmars-d-learn
Hi, struct S{int a, b, c=9, d, e, f;} Is there a way or a trick to declare an UDA by using a nice struct initializer? It would be nice to be able to use the form: @S{f:42} int a; //or something similar to this. instead of this longer and error-prone way: @S(0, 0, 0, 9, 0, 42) int a;

Re: Is there a way to return an lvalue and also an rvalue from the same member function?

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 17:08:49 UTC, realhet wrote: On Sunday, 20 September 2020 at 16:18:19 UTC, Steven Schveighoffer wrote: On 9/20/20 11:52 AM, realhet wrote: On Sunday, 20 September 2020 at 14:54:09 UTC, Steven Schveighoffer wrote: On 9/20/20 9:30 AM, realhet wrote: Yeah, I think

Re: Is there a way to return an lvalue and also an rvalue from the same member function?

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 16:18:19 UTC, Steven Schveighoffer wrote: On 9/20/20 11:52 AM, realhet wrote: On Sunday, 20 September 2020 at 14:54:09 UTC, Steven Schveighoffer wrote: On 9/20/20 9:30 AM, realhet wrote: Yeah, I think this might work. -Steve That would be a 3rd category out i

Re: Is there a way to return an lvalue and also an rvalue from the same member function?

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 15:52:49 UTC, realhet wrote: On Sunday, 20 September 2020 at 14:54:09 UTC, Steven Schveighoffer wrote: On 9/20/20 9:30 AM, realhet wrote: I managed to do the constant swizzles and it seems so elegant: auto opDispatch(string def)() const if(validRvalueSwizzl

Re: Is there a way to return an lvalue and also an rvalue from the same member function?

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 14:54:09 UTC, Steven Schveighoffer wrote: On 9/20/20 9:30 AM, realhet wrote: ref inout(int) x() inout { return array[0]; } This doesn't work when I type: v.x++; I want to make a similar type like the GLSL vectors. Where the following thing is valid: vec4 a, b;

Re: Is there a way to return an lvalue and also an rvalue from the same member function?

2020-09-20 Thread realhet via Digitalmars-d-learn
On Sunday, 20 September 2020 at 13:30:36 UTC, realhet wrote: Hi, More specifically: struct S{ int[2] array; ref swizzle(string code)(){ static if(code=="x") return array[0]; else static if(code=="y") return array[1]; else static assert("Unhandled"); }

Is there a way to return an lvalue and also an rvalue from the same member function?

2020-09-20 Thread realhet via Digitalmars-d-learn
Hi, struct S{ int[2] array; ref x() { return array[0]; } auto x() const { return array[0]; } } If there a way to write the function 'x' into one function, not 2 overloads. I tried auto/const/ref mindlessly :D, also remembered 'inout', but obviously those weren't solve the probl

Re: What kind of mangling has the LDC2 -X JsonFile "deco" field?

2020-09-17 Thread realhet via Digitalmars-d-learn
On Thursday, 17 September 2020 at 04:01:11 UTC, Adam D. Ruppe wrote: On Thursday, 17 September 2020 at 03:06:45 UTC, realhet wrote: Anyone can help me telling how to decode these please? Just prepend _D4name Thank you very much!

What kind of mangling has the LDC2 -X JsonFile "deco" field?

2020-09-16 Thread realhet via Digitalmars-d-learn
Hello, I'm trying to get information from the JsonFile produced by LDC2, but having no clue how to decode this: For example: header: KeywordCat kwCatOf(int k) "deco" : "FAyaZE3het8keywords10KeywordCat", The "deco" field contains the full name of the return type het.keywords.KeywordCat, but

Re: Catching OS Exceptions in Windows using LDC

2020-07-07 Thread realhet via Digitalmars-d-learn
On Saturday, 4 July 2020 at 14:44:06 UTC, Kagamin wrote: try https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter Thank You, this was the winner for me. Not just I can catch the OS Exceptions, I can check and alter the CPU state and de

Catching OS Exceptions in Windows using LDC

2020-07-04 Thread realhet via Digitalmars-d-learn
Hi, I'd like to catch the OS Exceptions including: - access violation - int 3 - invalid opcode etc. The default behavior is that when these events happen, the program immediately exits with some negative exit code. It was not a problem on other systems like: MSVC or Delphi, but on LDC these

Re: Weird behavior with UDAs

2020-06-13 Thread realhet via Digitalmars-d-learn
On Saturday, 13 June 2020 at 12:55:36 UTC, realhet wrote: Hello, I have a problem I can't even understand with the code For the first I realized that an UDA can be a type too, and come up with this: template getUDA(alias a, U){ enum u = q{ getUDAs!(a, U)[$-1] }; static if(hasUDA!(a, U)

Weird behavior with UDAs

2020-06-13 Thread realhet via Digitalmars-d-learn
Hello, I have a problem I can't even understand with the code below: https://run.dlang.io/is/7yXAEA import std.stdio, std.range, std.algorithm, std.traits, std.meta; struct UNIFORM{ string name; } struct A{ int i1; @UNIFORM() int i2; @UNIFORM("fuzz") int i3; @UNIFORM int i4; }

Re: Making alias of a struct field needs "this".

2020-06-03 Thread realhet via Digitalmars-d-learn
On Wednesday, 3 June 2020 at 10:11:59 UTC, realhet wrote: On Tuesday, 2 June 2020 at 20:38:40 UTC, Steven Schveighoffer wrote: On 6/2/20 10:51 AM, realhet wrote: On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: mixin("int[",

Re: Making alias of a struct field needs "this".

2020-06-03 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 20:38:40 UTC, Steven Schveighoffer wrote: On 6/2/20 10:51 AM, realhet wrote: On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: A month ago I discovered that mixinDeclarations can be used for types to

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:37:25 UTC, Stanislav Blinov wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: Try UDAs instead of a map: struct A { struct G { @("hauteur") int height; } Good idea, thx! I already using UDA's for range and measurement units. struc

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: mixin("@property auto ", k, "() const { return ", v, "; }"); Wow, string mixin can process comma separated list, I gotta remember this, thanks!

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: On Tuesday, 2 June 2020 at 09:10:03 UTC, Ali Çehreli wrote: On 6/2/20 1:56 AM, realhet wrote: Oh and I can put that function generator mixin thing into a template as well, that way it is reusable and much nicer. There are a lot of poss

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:10:03 UTC, Ali Çehreli wrote: On 6/2/20 1:56 AM, realhet wrote: > struct A{ >struct B{ int c; } >B b; > >auto f(){ > alias d = b.c; The spec explicitly says it's not legal: "Aliases cannot be used for expressions" (Item 10): https://dlang.org/

Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
Hello, I have a 2 level nested struct structure with nice descriptive field names. And I thought it will be easy to alias those identifierLists with a few letter names and do some calculations on them. But I'm having an error. struct A{ struct B{ int c; } B b; auto f(){ alias d = b

Re: Getting FieldNameTuple including all base-classes.

2020-05-20 Thread realhet via Digitalmars-d-learn
On Wednesday, 20 May 2020 at 09:03:51 UTC, realhet wrote: On Wednesday, 20 May 2020 at 01:18:24 UTC, Paul Backus wrote: On Tuesday, 19 May 2020 at 23:15:45 UTC, realhet wrote: With this mod it also works with structs: template AllClasses(T){ static if(is(T == class)) alias AllClas

Re: Getting FieldNameTuple including all base-classes.

2020-05-20 Thread realhet via Digitalmars-d-learn
On Wednesday, 20 May 2020 at 01:18:24 UTC, Paul Backus wrote: On Tuesday, 19 May 2020 at 23:15:45 UTC, realhet wrote: I think what you want is `std.meta.staticMap`. Something like this: alias FieldNameTuple2(T) = staticMap!(FieldNameTuple, BaseClassesTuple!T); class A { int a, a1; } class B

Getting FieldNameTuple including all base-classes.

2020-05-19 Thread realhet via Digitalmars-d-learn
Hi, I was able to reach all the fields in a subclass using foreach and BaseClassesTuple, but is there a way to do this using functional programming primitives, but in compile time for tuples? private template FieldNameTuple2(T) { enum FieldNameTuple2 = BaseClassesTuple!T.map!(S => FieldNam

Re: Handle FormatSpec!char in the virtual toString() method of a class.

2020-05-19 Thread realhet via Digitalmars-d-learn
On Thursday, 14 May 2020 at 19:01:25 UTC, H. S. Teoh wrote: On Wed, May 13, 2020 at 12:26:21PM +, realhet via Digitalmars-d-learn wrote: Thank You, very helpful!

Handle FormatSpec!char in the virtual toString() method of a class.

2020-05-13 Thread realhet via Digitalmars-d-learn
Hello, Is there a way to the following thing in a class instead of a struct? -- static struct Point { int x, y; void toString(W)(ref W writer, scope const ref FormatSpec!char f) if (isOutputRange!(W, char)) { // std.range.primitive

Is there an exception for access violation on LDC/win64?

2020-04-13 Thread realhet via Digitalmars-d-learn
Hi, import std.stdio, std.exception; void main(){ class C{ void foo(){ writeln(123); } } C c; try{ writeln(1); c.foo;// access violation here writeln(2); }catch(Throwable t){ writeln("exception"); } writeln(3); } When I run this code (using LDC2 64bit

Re: Using the functions "map" and "any" on tuples in compile time.

2020-04-12 Thread realhet via Digitalmars-d-learn
On Sunday, 12 April 2020 at 12:42:40 UTC, Harry Gillanders wrote: On Sunday, 12 April 2020 at 11:17:39 UTC, realhet wrote: I only remembered the __traits(identifier...), but completely forgot about the getMember. And I never heard of anySatisfy. My JSON serializer is beautiful now. Thank You

Using the functions "map" and "any" on tuples in compile time.

2020-04-12 Thread realhet via Digitalmars-d-learn
Hello, anyone can help me make this better? The functionality I want to achieve is: While serializing the fields of a struct, I want it to check the @STORED UDA on every field. If there is no fields are marked with @STORED, that means every field must be serialized. Otherwise only the marked o

Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-31 Thread realhet via Digitalmars-d-learn
On Tuesday, 24 March 2020 at 15:22:19 UTC, Steven Schveighoffer wrote: On 3/24/20 10:28 AM, realhet wrote: On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer If this were Linux, I'd start using nm to search the object files for the symbol that is missing (like search for symbols de

Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-31 Thread realhet via Digitalmars-d-learn
On Thursday, 26 March 2020 at 14:52:36 UTC, Ferhat Kurtulmuş wrote: On Sunday, 22 March 2020 at 18:43:50 UTC, realhet wrote: Hello, I'm try to use the latest LDC2 version: 1.20.0 Previously I used 1.6.0 [...] Try to run the compiler in visual studio command line terminal. I set up the envi

  1   2   >