Re: DMD [-O flag] vs. [memory allocation in a synchronized class]

2017-06-09 Thread realhet via Digitalmars-d-learn
On Thursday, 8 June 2017 at 17:39:41 UTC, Ivan Kazmenko wrote: Reported: https://issues.dlang.org/show_bug.cgi?id=17481 Thank You!

Out of memory error (even when using destroy())

2017-05-26 Thread realhet via Digitalmars-d-learn
Hi, I'm kinda new to the D language and I love it already. :D So far I haven't got any serious problems but this one seems like beyond me. import std.stdio; void main(){ foreach(i; 0..2000){ writeln(i); auto st = new ubyte[500_000_000]; destroy(st); //<-this

Re: Out of memory error (even when using destroy())

2017-05-26 Thread realhet via Digitalmars-d-learn
Thanks for the answer! But hey, the GC knows that is should not search for any pointers in those large blocks. And the buffer is full of 0-s at the start, so there can't be any 'false pointers' in it. And I think the GC will not search in it either. The only reference to the buffer is 'st'

Re: Out of memory error (even when using destroy())

2017-05-26 Thread realhet via Digitalmars-d-learn
Jordan Wilson wrote: This I think achieves the spirit of your code, but without the memory exception: ubyte[] st; foreach(i; 0..2000){ writeln(i); st.length=500_000_000; // auto = new ubyte[500_000_000]; st.length=0; // destory(st) st.assumeSafeAppend; //

Re: DMD [-O flag] vs. [memory allocation in a synchronized class]

2017-06-08 Thread realhet via Digitalmars-d-learn
On Thursday, 8 June 2017 at 10:48:41 UTC, ketmar wrote: worksforme with -O, and with -O -inline. I forgot to mention, that I'm generating win32 output. DMD32 D Compiler v2.074.0

DMD [-O flag] vs. [memory allocation in a synchronized class]

2017-06-08 Thread realhet via Digitalmars-d-learn
Hi, This code works well with the unoptimized compilation with DMD. import std.array; synchronized class Obj{ private int[] arr; void trigger(){ arr.length += 1; } } void main(){ auto k = new shared Obj; k.trigger; } And when I use the -O option, it shows the following error in the

Re: DMD [-O flag] vs. [memory allocation in a synchronized class]

2017-06-08 Thread realhet via Digitalmars-d-learn
I've managed to narrow the problem even more: //win32 dmd -O class Obj{ synchronized void trigger(){ new ubyte[1]; } } void main(){ auto k = new shared Obj; k.trigger; } This time I got a more sophisticated error message: object.Error@(0): Access Violation 0x7272456D

Re: Using stdin/out in a windows application bugs only when compiled to 64bit.

2018-06-08 Thread realhet via Digitalmars-d-learn
On Friday, 8 June 2018 at 02:44:13 UTC, Mike Parker wrote: ...you can get it with this: dmd -m64 -L/SUBSYSTEM:console -L/ENTRY:WinMainCRTStartup foo.d Thank You! It works with LDC -m64 as well. And now that I repaired my VCRedist2015 the bat file test (my second code example) is working too.

Re: Using stdin/out in a windows application bugs only when compiled to 64bit.

2018-06-08 Thread realhet via Digitalmars-d-learn
On Friday, 8 June 2018 at 03:08:21 UTC, Mike Franklin wrote: I recall similar issues with a project I was working on, but I don't remember all the details now. Anyway, I ended up with this in the end. Using main() instead of WinMain() did the trick too. Also it's simpler, so I choose this

Using stdin/out in a windows application bugs only when compiled to 64bit.

2018-06-07 Thread realhet via Digitalmars-d-learn
Hi, The following narrow test program works fine when compiled with DMD to 32bit target: import std.stdio, core.sys.windows.windows, core.runtime; extern(Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { Runtime.initialize;

Re: Using stdin/out in a windows application bugs only when compiled to 64bit.

2018-06-07 Thread realhet via Digitalmars-d-learn
On Thursday, 7 June 2018 at 19:42:05 UTC, Steven Schveighoffer wrote: Are you just compiling the 32-bit dmd version with default flags? Yes, no flags at all and it defaults to a 32bit target. I can use the console and able to make windows, and able to setup an opengl window too. The console

Re: Using stdin/out in a windows application bugs only when compiled to 64bit.

2018-06-07 Thread realhet via Digitalmars-d-learn
On Thursday, 7 June 2018 at 23:25:45 UTC, Steven Schveighoffer wrote: ... The WinMain exported function works alone well and on 32bit it also does the console. On 64 I also tried AllocConsole, but fail. I get the Console handle with GetConsoleHandle, it sends back a nonzero value. But as I

Re: DMD Windows 64bit target - how to setup the environment?

2017-12-29 Thread realhet via Digitalmars-d-learn
Thank You for fast help! I just reply late because I wanted to try out many things. With Benjamin's list it was indeed easy to set up the environment. I also installed LDC and it worked without problems too. Made some tests about sse vectorization and it turned out that I'm in love with LDC

DMD Windows 64bit target - how to setup the environment?

2017-12-25 Thread realhet via Digitalmars-d-learn
Hello, I'm very well satisfied with the DMD 32bit compiler and the OptLink linker on Windows. I even made an incremental builder to it, and I can see the running program in 1 second. Lately I sadly noticed, that the OptLink works only for 32bit target, and I need to go to 64bit if I want to

Re: DMD Windows 64bit target - how to setup the environment?

2017-12-25 Thread realhet via Digitalmars-d-learn
Now I have my first DMD 64bit windows console app running. (And I'm already afraid of the upcoming windowed application haha) After further fiddling I installed the >>>Visual Cpp tools 2015<<< package that contains a linker with x64 stuff in it (along with several GB of bloatware). contents

append uninitialized elements to array

2018-07-30 Thread realhet via Digitalmars-d-learn
Hello, I've already found out how to create an array with uninitialized elements, but what I'm looking for is a way to append 16 uninitialized ushorts to it and after I will it directly from 2 SSE registers. The approximate array length is known at the start so I could be able to do this

Re: append uninitialized elements to array

2018-07-31 Thread realhet via Digitalmars-d-learn
Thank You!

Re: strip() and formattedRead()

2018-03-21 Thread realhet via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 18:50:18 UTC, Adam D. Ruppe wrote: On Wednesday, 21 March 2018 at 18:44:12 UTC, realhet wrote: Compiling this I get an error: "formattedRead: cannot deduce arguments from (string, string, float, float, float)" What compiler version are you using? The newest

strip() and formattedRead()

2018-03-21 Thread realhet via Digitalmars-d-learn
Hi, I just got this problem and since an hour can't find answer to it. float x,y,z; if(formattedRead("vertex -5.1 2.4 3.666".strip, "vertex %f %f %f", x, y, z)){ writefln("v(%f, %f, %f)", x, y, z); } Compiling this I get an error: "formattedRead: cannot deduce arguments from

Problem with opBinary

2018-11-14 Thread realhet via Digitalmars-d-learn
Hi, Just a little weird thing I noticed and don't know why it is: I have a FilePath struct and I wanted to make it work with the "~" operator and an additional string. So I've created a global funct: FilePath opBinary(string op:"~")(FilePath p1, string p2){ return FilePath(p1, p2);

Re: Problem with opBinary

2018-11-14 Thread realhet via Digitalmars-d-learn
Thanks, this make it clear. (This also explains the existence of opBinaryRight)

Re: LDC2 win64 calling convention

2018-11-29 Thread realhet via Digitalmars-d-learn
On Wednesday, 28 November 2018 at 21:58:16 UTC, kinke wrote: You're not using naked asm; this entails a prologue (spilling the params to stack etc.). Additionally, LDC doesn't really like accessing params and locals in DMD-style inline asm, see

LDC2 win64 calling convention

2018-11-28 Thread realhet via Digitalmars-d-learn
Hi, Is there a documentation about the win64 calling convention used with LDC2 compiler? So far I try to use the Microsoft x64 calling convention, but I'm not sure if that's the one I have to. But it's not too accurate becaues I think it uses the stack only.

Re: LDC2 win64 calling convention

2018-11-28 Thread realhet via Digitalmars-d-learn
Thank You for the explanation! But my tests has different results: void* SSE_sobelRow(ubyte* src, ubyte* dst, size_t srcStride){ asm{ push RDI; mov RAX, 0; mov RDX, 0; mov RCX, 0; //clear 'parameter' registers mov RAX, src; mov RDI, dst; //gen movups XMM0,[RAX]; movaps

Multitasking question: Making a picture viewer, loading lots of images in the background

2019-04-02 Thread realhet via Digitalmars-d-learn
Hi, I'm writing a picture browser program and I'd like to ask for a bit of assistance. My app is basically a Win32 window with an OpenGL surface. Currently I'm able to display a lot of pictures in it. The decompression of the bitmaps take place at the beginning of the program. I want to

Re: Multitasking question: Making a picture viewer, loading lots of images in the background

2019-04-03 Thread realhet via Digitalmars-d-learn
On Wednesday, 3 April 2019 at 04:09:45 UTC, DanielG wrote: My understanding is that there's no benefit to creating more than the number of hyperthreads your CPU Yes. I'm just searching for a higher abstraction to manage this easily in D. I've already did it years ago on Delphi. (-> Manage N

check if _argument[0] is a descendant of a specific class.

2019-06-08 Thread realhet via Digitalmars-d-learn
Hi, I'm googling since an hour but this is too much for me: class A{} class B:A{} void foo(...){ if(_arguments[0]==typeid(A)){ //obviously not works for B } if(_arguments[0] is_a_descendant_of A){ //how to make it work for both A and B? } }

Variadic template parameters, refactor a long chain of static if's to 'functions'.

2019-06-11 Thread realhet via Digitalmars-d-learn
Hi again, I'm trying to do variadic parameter processing, and I have the following function that works fine: static bool same(T1, T2)(){ pragma(msg, "same? "~T1.stringof~" "~T2.stringof); return is(immutable(T1)==immutable(T2)); } Btn btn(T...)(string params, T args){ enum

Re: check if _argument[0] is a descendant of a specific class.

2019-06-08 Thread realhet via Digitalmars-d-learn
On Saturday, 8 June 2019 at 21:25:41 UTC, Adam D. Ruppe wrote: On Saturday, 8 June 2019 at 21:24:53 UTC, Adam D. Ruppe wrote: _arguments is a compile time construct, it is a run time thing. err i meant is *NOT* a compile time construct Thank You for the fast help! At first I was happy to

Re: Variadic template parameters, refactor a long chain of static if's to 'functions'.

2019-06-28 Thread realhet via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 13:22:26 UTC, Adam D. Ruppe wrote: On Tuesday, 11 June 2019 at 09:26:56 UTC, realhet wrote: static bool processId(bool captureIntId, alias r, alias a)(){ mixin("alias ta = typeof("~a.stringof~");"); As I have been saying a lot, mixin and stringof should

Re: Can I remove an element from a global associative array from within a class destructor?

2019-08-03 Thread realhet via Digitalmars-d-learn
On Saturday, 3 August 2019 at 05:33:05 UTC, Jonathan M Davis wrote: On Friday, August 2, 2019 5:13:10 PM MDT realhet via Digitalmars-d-learn wrote: Hi, ... Thank you! Now I have 2 solutions in mind: 1. If I only want to track the count and totalBytes for a specific kind of reference, I

Can I remove an element from a global associative array from within a class destructor?

2019-08-02 Thread realhet via Digitalmars-d-learn
Hi, I tried to make some resource statistict for my OpenGL Buffer objects: //here are the things that hold the statistics. private __gshared{ size_t[int] textureSizeMap, bufferSizeMap; } struct GLCounters{ int programs, shaders, textures, buffers; size_t textureSize, bufferSize; }

How to create a custom max() function without the ambiguity error.

2019-12-06 Thread realhet via Digitalmars-d-learn
Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...} //static function struct V3f{ V3f max(in V2f b){...} //member function } module gl3n; vec3 max(in vec3 a, in vec3 a) //another

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread realhet via Digitalmars-d-learn
On Friday, 6 December 2019 at 13:04:57 UTC, Ferhat Kurtulmuş wrote: On Friday, 6 December 2019 at 12:34:17 UTC, realhet wrote: Hi, I'm trying to use a popular function name "max", and extend it for my special types: For example: module utils; MyType max(in MyType a, in MyType a){...}

Re: How to create a custom max() function without the ambiguity error.

2019-12-06 Thread realhet via Digitalmars-d-learn
On Friday, 6 December 2019 at 14:55:18 UTC, Ferhat Kurtulmuş wrote: On Friday, 6 December 2019 at 13:25:24 UTC, realhet wrote: On Friday, 6 December 2019 at 13:04:57 UTC, Ferhat Kurtulmuş wrote: [...] Thx for answering! [...] In d you can also use scoped imports:

Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn
Hi, I have an input range. I use the map! on it to transform using a function. Finally I use filter! on the transformed data. When I do a foreach on this, i noticed, that the transform function is called twice for each element. If I remove the filter! it does only one transform function call

Re: Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:30:22 UTC, realhet wrote: ... Unfortunately function purity is not the answer. I put a very long calculation into the transform function which is called from "map!". And the "filter!" is making the "map!" call my function 2 times: First for the "filter!" to

Re: Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:49:24 UTC, Paul Backus wrote: It's actually a much simpler reason: filter calls .front twice for each element in its input (once to check if the value satisfies the predicate, and then again to return the value if it does), and the range returned by map

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: classinfo.m_init can be an option, but maybe there's a nicer way to do this? eh the initializer i think is the best. you can sometimes shortcut it pragma(msg, (new

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: Using what I've learned: class A{ int i=42; void init(){ // reInitialize class fields alias T = typeof(this); mixin([FieldNameTuple!T].map!(n => n~"=(new

Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
Hello, class A{ int i = 42; } Is there a way to get that 42? (Input is the class A and the name of the field 'i') A.i.init returns 0, so it doesn't care about the class. classinfo.m_init can be an option, but maybe there's a nicer way to do this? Thx!

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Hello, class A{ int i = 42; } Is there a way to get that 42? (Input is the class A and the name of the field 'i') A.i.init returns 0, so it doesn't care about the class.

Re: Getting the initial value of a class field in compile time.

2020-02-09 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 01:19:55 UTC, Paul Backus wrote: On Sunday, 9 February 2020 at 00:57:05 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe enum initValue = (new

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 00:57:05 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote: On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote: mixin([FieldNameTuple!T].map!(n => n~"=(new T)."~n~";").join); After checking it in the asm debugger, it

Re: Getting the initial value of a class field in compile time.

2020-02-09 Thread realhet via Digitalmars-d-learn
On Sunday, 9 February 2020 at 02:25:56 UTC, Steven Schveighoffer wrote: On 2/8/20 7:39 PM, realhet wrote: On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Yea, I exactly ran into that "init" problem, I will avoid that, thx!

Information about the 'magic' field in object.Object class

2020-01-16 Thread realhet via Digitalmars-d-learn
Hello, I'm try to figure out the contents od the base class instance in D, LDC Windows 64bit. I'm sure that there is a 8 byte VMT pointer. But unable to fund information about the remaining 8 byte. I guess it must be a unique 8byte (void* ?) identifier that is useful for Monitor. In a video

Re: Information about the 'magic' field in object.Object class

2020-01-16 Thread realhet via Digitalmars-d-learn
On Thursday, 16 January 2020 at 14:32:24 UTC, Adam D. Ruppe wrote: On Thursday, 16 January 2020 at 14:30:04 UTC, realhet wrote: Is there a documentation about that 'magic' field? I'm pretty sure the only fields in there are pointer to vtable and pointer to monitor object... I have a really

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

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

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: 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

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

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)) { //

linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-22 Thread realhet via Digitalmars-d-learn
Hello, I'm try to use the latest LDC2 version: 1.20.0 Previously I used 1.6.0 After fixing all the compiler errors and warnings, I managed to compile all the d source files to obj files, and I got 4 linking errors. I think all of them caused by the first 2: 1: msvcrt.lib(initializers.obj) :

Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-23 Thread realhet via Digitalmars-d-learn
On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer wrote: Make sure you don't have any stale objects left over in your project from the older build. Build everything clean from scratch. -Steve Thx, I double checked this. Then I attempted to link from the commandline and it

Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 Thread realhet via Digitalmars-d-learn
On Sunday, 22 March 2020 at 20:20:17 UTC, Steven Schveighoffer wrote: Make sure you don't have any stale objects left over in your project from the older build. Build everything clean from scratch. -Steve After narrowing the problem, I fixed all warnings, and deprecations, and I have only

Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 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 I managed to compile it with normal compilation. The -allInst flag may be the problem. I also had success by manual

Re: linking obj files compiled with LDC2 1.20.0 on Win64

2020-03-24 Thread realhet via Digitalmars-d-learn
On Tuesday, 24 March 2020 at 16:35:56 UTC, realhet wrote: 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 Now I have 2 of this: megatexturing.obj : error LNK2019:

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 =>

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!

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 =>

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

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!

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

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

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

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 =

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

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

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 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.

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

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):

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,

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

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

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"); }

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

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

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,

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

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

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

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[",

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: 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,

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

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

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=='_'; }

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

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)

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.

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

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

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

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

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,

  1   2   >