Re: Can std.variant be used with std.container.rbtree?

2022-04-02 Thread JG via Digitalmars-d-learn
On Friday, 1 April 2022 at 22:22:21 UTC, Vijay Nayar wrote: Consider the following program: ```d void main() { import std.stdio; import std.container.rbtree; import std.variant; [...] You need an order on the elements in a red black tree. Am I correct in thinking you want a conta

Variadic templates with default parameters.

2022-04-02 Thread JG via Digitalmars-d-learn
Consider the following code: ```d import std; auto logVariadic(T...)(T x,int line=__LINE__,string file=__FILE__) { writeln(file,":",line," ",x); } int variadicCnt; auto logVariadicWrapper(T...)(T x, int line=__LINE__, string file=__FILE__) { variadicCnt++; logVariadic(x,line,file); }

arsd.minigui

2022-04-03 Thread JG via Digitalmars-d-learn
Hi, I have an png image that I generate (via pdf via pdflatex) that I want to scale and display in a widget. Is this possible via something in arsd? I tried resizeImage but that doesn't seem to do what I expect. Any suggestions?

Re: arsd.minigui

2022-04-03 Thread JG via Digitalmars-d-learn
On Sunday, 3 April 2022 at 17:10:48 UTC, Adam Ruppe wrote: On Sunday, 3 April 2022 at 16:58:03 UTC, JG wrote: [...] Which resizeImage did you use, from the imageresize module? What pain you have with it? Some of its settings take some tweaking. [...] Thank you very much for your quick re

RefCounted

2022-04-13 Thread JG via Digitalmars-d-learn
Hi, I would have thought that RefCounted!(T, RefCountedAutoInitialize.no) is to be used in place T* when I want reference counting instead of the usual garbage collection (or manual allocation). Perhaps this is wrong? If I am correct what am I doing wrong here? (Sorry for two space squashed

Re: RefCounted

2022-04-13 Thread JG via Digitalmars-d-learn
On Wednesday, 13 April 2022 at 20:47:33 UTC, JG wrote: Hi, I would have thought that RefCounted!(T, RefCountedAutoInitialize.no) is to be used in place T* when I want reference counting instead of the usual garbage collection (or manual allocation). Perhaps this is wrong? [...] Perhaps I

Re: RefCounted

2022-04-15 Thread JG via Digitalmars-d-learn
On Wednesday, 13 April 2022 at 20:47:33 UTC, JG wrote: Hi, I would have thought that RefCounted!(T, RefCountedAutoInitialize.no) is to be used in place T* when I want reference counting instead of the usual garbage collection (or manual allocation). Perhaps this is wrong? [...] In case so

Re: Lambda Tuple with Map Reduce

2022-04-20 Thread JG via Digitalmars-d-learn
On Wednesday, 20 April 2022 at 08:04:42 UTC, Salih Dincer wrote: ```d alias type = real; alias func = type function(type a); [...] I think technically you should have save after range in that loop.

Understanding alias template parameters

2022-04-21 Thread JG via Digitalmars-d-learn
Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } void popFront() { r.popFront; } auto save() { return

Re: Understanding alias template parameters

2022-04-22 Thread JG via Digitalmars-d-learn
On Thursday, 21 April 2022 at 21:02:47 UTC, JG wrote: Hi, Could someone possibly help me to understand why the commented line doesn't compile? ```d import std; struct MapResult(R,F) { R r; const F f; auto empty() { return r.empty; } auto front() { return f(r.front); } vo

Re: Reference counting example

2022-04-26 Thread JG via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 06:55:34 UTC, Alain De Vos wrote: Can someone provide a simple/very simple reference counting or refcounted example i can understand. Thanks. I suggest to look at RefCounted [here](https://code.dlang.org/packages/automem) rather than in Phobos. There are simple ex

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-01 Thread JG via Digitalmars-d-learn
On Sunday, 1 May 2022 at 07:59:57 UTC, Elfstone wrote: On Sunday, 1 May 2022 at 06:42:26 UTC, Tejas wrote: On Sunday, 1 May 2022 at 03:57:12 UTC, Elfstone wrote: module test; struct MatrixImpl(S, size_t M, size_t N) { } [...] AFAICT, I'm afraid you'll have to stick to `dot2`

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-01 Thread JG via Digitalmars-d-learn
On Sunday, 1 May 2022 at 11:34:49 UTC, JG wrote: On Sunday, 1 May 2022 at 07:59:57 UTC, Elfstone wrote: On Sunday, 1 May 2022 at 06:42:26 UTC, Tejas wrote: [...] Thanks a lot! So this really is a D "feature". The current behaviour is so broken. It makes no sense, for a language user at least

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread JG via Digitalmars-d-learn
On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote: On Sunday, 1 May 2022 at 03:57:12 UTC, Elfstone wrote: [...] Template deduction for aliased function parameter is a very tricky argument and it's not so simple to handle in certain cases. Consider for example this code: ```d template

Re: Parameters declared as the alias of a template won't accept the arguments of the same type.

2022-05-02 Thread JG via Digitalmars-d-learn
On Monday, 2 May 2022 at 19:17:19 UTC, Stanislav Blinov wrote: On Monday, 2 May 2022 at 16:29:05 UTC, Loara wrote: Template deduction for aliased function parameter is a very tricky argument and it's not so simple to handle in certain cases. Consider for example this code: ```d template

String Literals

2022-05-03 Thread JG via Digitalmars-d-learn
Hi, The specification of string literals has either some errors or I don't understand what is meant by a Character. For instance we have: WysiwygString: r" WysiwygCharacters_opt " StringPostfix_opt WysiwygCharacters: WysiwygCharacter WysiwygCharacter WysiwygCharacters WysiwygCha

What am I doing wrong here?

2022-05-06 Thread JG via Digitalmars-d-learn
This isn't code to be used for anything (just understanding). ```d import std; struct Delegate(A,B) { B function(void* ptr, A a) f; void* data; B opCall(A a) { return f(data,a); } } auto toDelegate(A, B,S)(S s) { static B f(void* ptr, A a) { return (*(cast(S*)

Re: What am I doing wrong here?

2022-05-06 Thread JG via Digitalmars-d-learn
On Friday, 6 May 2022 at 18:35:40 UTC, Ali Çehreli wrote: On 5/6/22 11:04, JG wrote: > [...] This is a segmentation fault. Reduced: import std; [...] Hi, thanks. That was quite silly. (I was thinking the variable lives to the end of scope of main but not thinking about that I am passing b

Re: What am I doing wrong here?

2022-05-08 Thread JG via Digitalmars-d-learn
On Saturday, 7 May 2022 at 02:29:59 UTC, Salih Dincer wrote: On Friday, 6 May 2022 at 18:04:13 UTC, JG wrote: ```d //... struct Adder { int a; int opCall(int b) { return a+b; } } auto adder(int a) { auto ret = Adder.init; ret.a=a; return ret; } void main() { auto g = add

Re: Question on shapes

2022-05-17 Thread JG via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 00:10:55 UTC, Alain De Vos wrote: Let's say a shape is ,a circle with a radius ,or a square with a rectangular size. I want to pass shapes to functions, eg to draw them on the screen, draw(myshape) or myshape.draw(); But how do i implement best shapes ? You could al

Allocate a string via the GC

2022-05-23 Thread JG via Digitalmars-d-learn
Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ```

Re: Allocate a string via the GC

2022-05-23 Thread JG via Digitalmars-d-learn
On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Why do you want

Bug?

2022-05-26 Thread JG via Digitalmars-d-learn
Hi, I was reading the source of std.algorithm cache and saw some code that didn't make sense to me with a comment indexing the [bug report](https://issues.dlang.org/show_bug.cgi?id=15891). Could anyone help to understand if this code is really necessary (meaning I have some misconception) or

Re: static assert("nothing")

2022-05-31 Thread JG via Digitalmars-d-learn
On Tuesday, 31 May 2022 at 08:51:45 UTC, realhet wrote: 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" paramet

Generating unique identifiers at compile time

2022-06-09 Thread JG via Digitalmars-d-learn
Hi, As an experiment I have implemented the following kind of pattern matching (by parsing the part of the string before '='). ```d struct S { int x; int y; } struct T { int w; S s; } void main() { mixin(matchAssign(q{auto T(first,S(second,third)) = T(1,S(2,3));})); first.wr

Re: Generating unique identifiers at compile time

2022-06-12 Thread JG via Digitalmars-d-learn
On Friday, 10 June 2022 at 06:17:54 UTC, bauss wrote: On Thursday, 9 June 2022 at 23:50:10 UTC, user1234 wrote: There's [been attempts] to expose it, exactly so that users can generate unique names, but that did not found its path in the compiler. [been attempts]: https://github.com/dlang/d

Re: Generating unique identifiers at compile time

2022-06-12 Thread JG via Digitalmars-d-learn
On Sunday, 12 June 2022 at 18:45:27 UTC, Paul Backus wrote: On Thursday, 9 June 2022 at 21:20:27 UTC, JG wrote: [...] [...] [...] Here's a `gensym` implementation I came up with a while back: ```d enum gensym = q{"_gensym" ~ __traits(identifier, {})["__lambda".length .. $]}; // Works mul

Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
Hi, I reduced my code to the following. Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) = SumType!(ParseError,T); auto parseErrorOr(T)(T x)

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
On Monday, 13 June 2022 at 19:59:16 UTC, Steven Schveighoffer wrote: On 6/13/22 3:48 PM, JG wrote: Hi, I reduced my code to the following.  Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? ```d import std; struct P

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
On Monday, 13 June 2022 at 20:25:00 UTC, Steven Schveighoffer wrote: On 6/13/22 4:09 PM, JG wrote: Thanks. It seems to be something to do with the variadic template since this works: ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) = SumType!(ParseError,T); auto parse

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
On Monday, 13 June 2022 at 21:45:39 UTC, Paul Backus wrote: On Monday, 13 June 2022 at 19:48:06 UTC, JG wrote: Hi, I reduced my code to the following. Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? Reduced furthe

Bug?

2022-06-14 Thread JG via Digitalmars-d-learn
Hi, Is this a bug? ```d import std; template test(alias f) { auto test(I)(I i) { return f(i); } } void main() { alias t = test!(x=>x+1); 1.t.writeln; //<--Doesn't compile 1.test!(x=>x+1).writeln; t(1).writeln; } ```

Re: Bug?

2022-06-15 Thread JG via Digitalmars-d-learn
On Tuesday, 14 June 2022 at 19:49:39 UTC, Steven Schveighoffer wrote: On 6/14/22 3:35 PM, JG wrote: Hi, Is this a bug? ```d import std; template test(alias f) {     auto test(I)(I i) { return f(i); } } void main() {     alias t = test!(x=>x+1);     1.t.writeln; //<--Doesn't compile     1

Re: Bug in dmd?

2022-06-15 Thread JG via Digitalmars-d-learn
On Tuesday, 14 June 2022 at 23:56:58 UTC, Andrey Zherikov wrote: On Tuesday, 14 June 2022 at 21:44:48 UTC, Dukc wrote: No idea. The functions seems indeed to be exactly the same, so I assume this is a DMD bug. It cannot be a bug in `std.sumtype`, since that would trigger in both of the templat

Re: Whats the proper way to write a Range next function

2022-06-15 Thread JG via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 13:52:24 UTC, Christian Köstlin wrote: the naive version would look like ```d auto next(Range)(Range r) { r.popFront; return r.front; } ``` But looking at a mature library e.g. https://github.com/submada/btl/blob/9cc599fd8495215d346ccd62d6e9f1f7ac140937/so

Re: Whats the proper way to write a Range next function

2022-06-15 Thread JG via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 17:30:31 UTC, JG wrote: On Wednesday, 15 June 2022 at 13:52:24 UTC, Christian Köstlin wrote: the naive version would look like ```d auto next(Range)(Range r) { r.popFront; return r.front; } ``` But looking at a mature library e.g. https://github.com/subma

Re: Failure due to memcpy being called at compile time

2022-06-20 Thread JG via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 01:39:43 UTC, Paul Backus wrote: On Tuesday, 14 June 2022 at 05:35:46 UTC, JG wrote: On Monday, 13 June 2022 at 21:45:39 UTC, Paul Backus wrote: The call to `move` is coming from `SumType.opAssign`: https://github.com/dlang/phobos/blob/v2.100.0/std/sumtype.d#L681 I

Better way to achieve the following

2022-06-21 Thread JG via Digitalmars-d-learn
Suppose we are often writing something like ```d theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]=x; ``` One would like to something like ```d alias shortName = theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]; shortName = x; ``

Re: Better way to achieve the following

2022-06-21 Thread JG via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 17:15:02 UTC, Steven Schveighoffer wrote: On 6/21/22 1:09 PM, JG wrote: Thoughts? Use a pointer? Especially if you are using `.method` calls, this just works seamlessly. -Steve Thanks for the suggestion. My immediate reaction is that for `.method` calls I wou

Re: This code completely breaks the compiler:

2022-08-18 Thread JG via Digitalmars-d-learn
On Friday, 19 August 2022 at 03:13:03 UTC, Ruby The Roobster wrote: On Friday, 19 August 2022 at 03:10:38 UTC, Ruby The Roobster wrote: This snippet compiles. Even if `dsds` and `sadsad` are defined nowhere, this code compiles. [SNIP] The reason why this compiles is because of the varidic t

Re: typeof(func!0) != typeof(func!0())

2022-08-21 Thread JG via Digitalmars-d-learn
On Monday, 22 August 2022 at 04:39:18 UTC, Andrey Zherikov wrote: I have this simple code: ```d struct U { auto ref func(int i)() { return this; } } void main() { { alias type = typeof(U().func!0); pragma(msg, type); // pure nothrow @nogc ref @safe U() return

Casting rules

2022-08-26 Thread JG via Digitalmars-d-learn
Where can I find rules about casting. e.g. I assume casting away immutable is undefined behavior (or implementation defined behavior). What about casting to immutable (I would expect at most it only to be allowed if your type has no references e.g. ints okay but int[] not etc.) Casting const aw

Re: Casting rules

2022-08-27 Thread JG via Digitalmars-d-learn
On Friday, 26 August 2022 at 21:18:15 UTC, ag0aep6g wrote: On Friday, 26 August 2022 at 20:42:07 UTC, JG wrote: [...] Casting immutable/const away: https://dlang.org/spec/const3.html#removing_with_cast The cast itself allowed. Mutating the data is not. Casting to immutable: https://dlang.

Re: C function taking two function pointers that share calculation

2022-09-14 Thread JG via Digitalmars-d-learn
On Wednesday, 14 September 2022 at 17:23:47 UTC, jmh530 wrote: There is a C library I sometimes use that has a function that takes two function pointers. However, there are some calculations that are shared between the two functions that would get pointed to. I am hoping to only need to do thes

Re: Find in assoc array then iterate

2022-10-21 Thread JG via Digitalmars-d-learn
On Friday, 21 October 2022 at 22:03:53 UTC, Kevin Bailey wrote: I'm trying to do this equivalent C++: unordered_map map; for (auto i = map.find(something); i != map.end(); ++i) ...do something with i... in D, but obviously with an associative array. It seems that it's quite ea

Re: "Little Scheme" and PL Design (Code Critique?)

2022-11-22 Thread JG via Digitalmars-d-learn
On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu wrote: I just pushed a D implementation of "[Little Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)", which is a limited educational version of [Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language)),

Re: Why not allow elementwise operations on tuples?

2023-01-18 Thread JG via Digitalmars-d-learn
On Monday, 16 January 2023 at 08:30:15 UTC, Sergei Nosov wrote: On Friday, 13 January 2023 at 15:27:26 UTC, H. S. Teoh wrote: [...] Yeah, that's clear that such an implementation is rather straightforward. Although, I'm a bit confused with your implementation - 1. it doesn't seem to use tupl

Re: Is there a way to get the name of the current function?

2023-03-07 Thread JG via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:11:49 UTC, rempas wrote: For example, in the given code: ```d void my_function() { import std.stdio; writeln("The name of the function is: ", ); } ``` Is there something to put in the place of `` to get the name of the function? Yes, see here: https://d

Re: mutable pointers as associative array keys

2023-04-10 Thread JG via Digitalmars-d-learn
On Monday, 10 April 2023 at 18:14:56 UTC, John Colvin wrote: It seems that it isn't possible, am I missing something? alias Q = int[int*]; pragma(msg, Q); // int[const(int)*] Also, is this documented somewhere? It seems to be so (which is strange) and I can't image it is by design since you

Re: container vs standard array

2023-09-18 Thread JG via Digitalmars-d-learn
On Tuesday, 19 September 2023 at 00:34:01 UTC, vino wrote: Hi All, I am trying to understand as to why the below code is throwing error Code ``` import std.stdio: writeln; import std.container.array; void main () { //auto a = Array!string("Aname"); // throws error auto b = Array

Tuple poilerplate code

2020-08-31 Thread JG via Digitalmars-d-learn
Is there anyway to remove the boilerplate code of dealing with tuples: I find myself having to write things like this fairly often auto someRandomName = f(...); //where f returns a tuple with two parts auto firstPart = someRandomName[0]; auto secondPart = someRandomName[1]; Is to possible

Re: Tuple poilerplate code

2020-09-01 Thread JG via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 03:51:10 UTC, user1234 wrote: On Tuesday, 1 September 2020 at 02:08:54 UTC, JG wrote: Is there anyway to remove the boilerplate code of dealing with tuples: I find myself having to write things like this fairly often auto someRandomName = f(...); //where f ret

Re: Tuple poilerplate code

2020-09-01 Thread JG via Digitalmars-d-learn
Thank you all for the interesting suggestions.

Re: get element index when using each!(x)

2020-09-16 Thread JG via Digitalmars-d-learn
On Thursday, 17 September 2020 at 00:51:54 UTC, dangbinghoo wrote: hi, is there any way to get the index for an element when iteration using each!(x)? I know I can do this using foreach statement, but I prefer using the each template. --- string s = "hello"; foreach(i, c; s) { } -

Re: Tuple poilerplate code

2020-09-18 Thread JG via Digitalmars-d-learn
On Wednesday, 2 September 2020 at 03:52:55 UTC, JG wrote: Thank you all for the interesting suggestions. Still thinking about this from time to time. Other than the suggestions given, this is what I have been playing around with. - import std.stdio; import std.

vibe.d get body of HTTPServerResponse

2020-11-02 Thread JG via Digitalmars-d-learn
I am trying to get the body the response generated by: res.render!("index.dt"); where res is of type HTTPServerResponse Does anyone know how I might go about this?

Re: vibe.d get body of HTTPServerResponse

2020-11-02 Thread JG via Digitalmars-d-learn
On Monday, 2 November 2020 at 17:02:01 UTC, Steven Schveighoffer wrote: On 11/2/20 10:10 AM, JG wrote: I am trying to get the body the response generated by: res.render!("index.dt"); where res is of type HTTPServerResponse Does anyone know how I might go about this? That is a convenience w

Profiling

2021-02-08 Thread JG via Digitalmars-d-learn
I was trying to profile a d program. So I ran: dub build --build=profile. I then ran the program and it produced trace.log and trace.def. I then ran d-profile-viewer and got the following error: std.conv.ConvException@/home/jg/dlang/ldc-1.24.0/bin/../import/std/conv.d(2382): Unexpected '-' wh

Re: Profiling

2021-02-10 Thread JG via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 18:33:16 UTC, drug wrote: On Tuesday, 9 February 2021 at 07:45:13 UTC, JG wrote: I was trying to profile a d program. So I ran: dub build --build=profile. I then ran the program and it produced trace.log and trace.def. I then ran d-profile-viewer and got the foll

vibe.d selectively include attribute into tag using diet template

2021-02-27 Thread JG via Digitalmars-d-learn
Hi, I know that one can do the following: tag(attribute='#{dexpression}') But, is there a way to deal with attributes that don't get assigned values. That is, is there a way to produce or depending on a boolean variable? Of course one can do: - if (booleanVariable) tag(attribute) include

Re: vibe.d selectively include attribute into tag using diet template

2021-02-27 Thread JG via Digitalmars-d-learn
On Saturday, 27 February 2021 at 19:12:55 UTC, Steven Schveighoffer wrote: Yes, if you assign a boolean value to it directly, then if true, the attribute is included, if not, it's not. e.g.: tag(attribute=booleanVariable) Note the lack of quotes. Thank you very much for this. If you use

Re: vibe.d selectively include attribute into tag using diet template

2021-03-01 Thread JG via Digitalmars-d-learn
On Sunday, 28 February 2021 at 18:10:26 UTC, Steven Schveighoffer wrote: On 2/28/21 12:29 AM, JG wrote: On Saturday, 27 February 2021 at 19:12:55 UTC, Steven Schveighoffer wrote: If you use an expression without quotes in diet, it becomes an interpolation. Would you mind explaining in more d

Local library with dub

2021-04-20 Thread JG via Digitalmars-d-learn
Hi I want to put some code together in a local library that is then used by several other projects. I am running into a few problems. Firstly when I try and configure the code to be a library (dub init, add d files to source, and remove source/app.d - perhaps this wrong) dub test no longer se

Re: Local library with dub

2021-04-20 Thread JG via Digitalmars-d-learn
On Tuesday, 20 April 2021 at 18:11:18 UTC, Andre Pany wrote: On Tuesday, 20 April 2021 at 17:15:15 UTC, JG wrote: Hi I want to put some code together in a local library that is then used by several other projects. I am running into a few problems. Firstly when I try and configure the code to

Re: Local library with dub

2021-04-21 Thread JG via Digitalmars-d-learn
On Wednesday, 21 April 2021 at 00:39:41 UTC, Mike Parker wrote: On Tuesday, 20 April 2021 at 18:43:28 UTC, JG wrote: This still leaves open the question of how to include a version of such a library in another project via dub. Execute `dub add-local` followed by the path to the project's r

Re: Local library with dub

2021-04-21 Thread JG via Digitalmars-d-learn
On Wednesday, 21 April 2021 at 19:15:19 UTC, Jordan Wilson wrote: On Wednesday, 21 April 2021 at 15:07:25 UTC, JG wrote: On Wednesday, 21 April 2021 at 00:39:41 UTC, Mike Parker wrote: [...] Thanks. I suppose this means that if you want to able to use multiple versions you have to keep each

moveToGC

2021-05-10 Thread JG via Digitalmars-d-learn
The following compiles with dmd but not with ldc on run.dlang.io. Am I doing something wrong? import core.memory; void main() { struct S { int x; this(this) @disable; ~this() @safe pure nothrow @nogc {} } S* p;

Re: moveToGC

2021-05-12 Thread JG via Digitalmars-d-learn
On Monday, 10 May 2021 at 11:11:06 UTC, Mike Parker wrote: On Monday, 10 May 2021 at 10:56:35 UTC, JG wrote: The following compiles with dmd but not with ldc on run.dlang.io. Am I doing something wrong? Please provide the error message(s) when asking questions like this. In this case: ``` o

Understanding RefCounted

2021-05-12 Thread JG via Digitalmars-d-learn
Reading the documentation on RefCounted I get the impression that the following can lead to memory errors. Could someone explain exactly how that could happen? I suppose that problem would be the call something to do with front? ``` private struct RefCountedRangeReturnType(R) { import std

Re: Understanding RefCounted

2021-05-12 Thread JG via Digitalmars-d-learn
On Wednesday, 12 May 2021 at 13:38:10 UTC, Steven Schveighoffer wrote: On 5/12/21 3:28 AM, JG wrote: Reading the documentation on RefCounted I get the impression that the following can lead to memory errors. Could someone explain exactly how that could happen? I suppose that problem would be t

Re: How to use dub with our own package

2021-05-12 Thread JG via Digitalmars-d-learn
On Wednesday, 12 May 2021 at 13:37:26 UTC, Vinod K Chandran wrote: Hi all, I am creating a hobby project related with win api gui functions. i would like to work with dub. But How do I use dub in my project. 1. All my gui library modules are located in a folder named "winglib". 2. And that fo

Re: Issue with small floating point numbers

2021-05-12 Thread JG via Digitalmars-d-learn
On Thursday, 13 May 2021 at 03:48:49 UTC, Tim wrote: On Thursday, 13 May 2021 at 03:46:28 UTC, Alain De Vos wrote: Not is is not wrong it is wright. Because you use not pi but an approximation of pi the result is not zero but an approximation of zero. Oh, of course. Jesus that sucks big time.

Re: Understanding RefCounted

2021-05-12 Thread JG via Digitalmars-d-learn
On Thursday, 13 May 2021 at 00:53:50 UTC, Steven Schveighoffer wrote: On 5/12/21 1:16 PM, JG wrote: [...] Ah, ok. So reference counting provides a single thing you can point at and pass around without worrying about memory cleanup. But only as long as you refer to it strictly through a RefC

Shift operator, unexpected result

2021-06-09 Thread JG via Digitalmars-d-learn
I found the following behaviour, as part of a more complicated algorithm, unexpected. The program: import std; void main() { int n = 64; writeln(123uL>>n); } produces: 123 I would expect 0. What is the rationale for this behaviour or is it a bug?

Two interpretations

2021-06-11 Thread JG via Digitalmars-d-learn
Is it specified somewhere which way the following program will be interpreted? import std; struct A { int x=17; } int x(A a) { return 100*a.x; } void main() { A a; writeln(a.x); }

Vibe.d diet templates

2021-06-17 Thread JG via Digitalmars-d-learn
Suppose I have an array of attributes and values v is there any way to apply these attributes to a tag? So that something like tag(#{v[0]0]}=#{v[0][1]},...}) becomes where v[0][0]="attribute0" and v[0][1]="value0"?

Re: Vibe.d diet templates

2021-06-17 Thread JG via Digitalmars-d-learn
On Thursday, 17 June 2021 at 09:16:56 UTC, WebFreak001 wrote: On Thursday, 17 June 2021 at 08:23:54 UTC, JG wrote: Suppose I have an array of attributes and values v is there any way to apply these attributes to a tag? So that something like tag(#{v[0]0]}=#{v[0][1]},...}) becomes where v[

Re: Vibe.d diet templates

2021-06-17 Thread JG via Digitalmars-d-learn
On Thursday, 17 June 2021 at 18:54:41 UTC, WebFreak001 wrote: On Thursday, 17 June 2021 at 16:26:57 UTC, JG wrote: [...] Thanks, this works. I would have thought this would be a common enough use case to have support in diet. Anyone else wanted this? Opened an issue here: https://github.co

Sumtype warning

2021-07-11 Thread JG via Digitalmars-d-learn
I am getting the following message: Warning: struct SumType has method toHash, however it cannot be called with const(SumType!(A,B,C)) this Could someone point in the right direction to understand what I am doing that causes this?

Documentation

2021-07-15 Thread JG via Digitalmars-d-learn
What is the relationship between https://dlang.org/library/ and https://dlang.org/phobos/index.html

Build time

2021-07-23 Thread JG via Digitalmars-d-learn
Hi, The program I writing is around 3000 loc and recently I noticed a large slow down in compile time which after investigation seemed to be caused by my computer running out of memory. The compile was using more than 15GB memory. I tried using lowmem and that did solve the memory problem but

Re: Build time

2021-07-23 Thread JG via Digitalmars-d-learn
On Friday, 23 July 2021 at 18:57:46 UTC, Adam D Ruppe wrote: On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: The program I writing is around 3000 loc what's the code? I am not sure how relevant it is but it is a compiler that I have been writing, not something serious (yet - if ever).

Re: Build time

2021-07-24 Thread JG via Digitalmars-d-learn
On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: [...] You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: [...] Thanks for this suggestion. Unfortunately this makes the compile use too much memory for my system a

Re: Build time

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 08:26:39 UTC, JG wrote: On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: [...] You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: [...] Thanks for this suggestion. Unfortunately this

Re: Build time

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:12:15 UTC, JG wrote: On Saturday, 24 July 2021 at 08:26:39 UTC, JG wrote: On Friday, 23 July 2021 at 20:03:22 UTC, Dennis wrote: [...] Thanks for this suggestion. Unfortunately this makes the compile use too much memory for my system and so it gets killed bef

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 19:39:02 UTC, Alexey wrote: On Saturday, 24 July 2021 at 18:10:07 UTC, Alexey wrote: I've tried to use ```typeof(t) is cast(t)null```, but compiler exits with error and so this can't be used for checking this issue. The goal I with to achieve by this check - is to

Re: How to check if variable of some type can be of null value?

2021-07-24 Thread JG via Digitalmars-d-learn
On Saturday, 24 July 2021 at 20:10:37 UTC, JG wrote: On Saturday, 24 July 2021 at 19:39:02 UTC, Alexey wrote: [...] There are probably better ways. However, this seems to work: ```d import std; enum canBeSetToNull(T) = __traits(compiles,(T.init is null)); interface I1 { } class C1 : I1 { }

Re: Passing delegate indirectly to createLowLevelThread doesn't work

2021-07-26 Thread JG via Digitalmars-d-learn
On Monday, 26 July 2021 at 16:46:40 UTC, Tejas wrote: On Monday, 26 July 2021 at 15:42:44 UTC, Paul Backus wrote: On Monday, 26 July 2021 at 15:29:26 UTC, Tejas wrote: ```d import std; import core.thread.osthread; void delegate() f; void main() { void func(){} f = &func; createLowL

Tracy

2021-08-06 Thread JG via Digitalmars-d-learn
There was a message a while back (https://forum.dlang.org/post/fyakhpjbcpzqegfev...@forum.dlang.org) about adding support for tracy. When I asked a question about compile time performance I received the following instructions: https://forum.dlang.org/post/eevoyuwhbuycyzgxs...@forum.dlang.org I

Re: Tracy

2021-08-07 Thread JG via Digitalmars-d-learn
On Saturday, 7 August 2021 at 14:36:39 UTC, Dennis wrote: On Friday, 6 August 2021 at 12:30:16 UTC, JG wrote: I guess this means that tracy has been integrated? If this is so is it documented anywhere how to use it? Stefan Koch's WIP tracy integration in DMD is completely separate from Johan

Anyway to achieve the following

2021-08-13 Thread JG via Digitalmars-d-learn
Suppose one has a pointer p of type T*. Can on declare variable a of type T which is stored in the location pointed to by p? As an example if we have: struct S { int x = 1234; } void main() { S s; //unknown construction of a using &(s.x) writeln(a);

Re: Anyway to achieve the following

2021-08-13 Thread JG via Digitalmars-d-learn
On Friday, 13 August 2021 at 17:19:43 UTC, H. S. Teoh wrote: On Fri, Aug 13, 2021 at 05:11:50PM +, Rekel via Digitalmars-d-learn wrote: [...] For anyone more experienced with C, I'm not well known with references but are those semantically similar to the idea of using a type at a predefined

Re: Anyway to achieve the following

2021-08-15 Thread JG via Digitalmars-d-learn
On Saturday, 14 August 2021 at 20:50:47 UTC, Carl Sturtivant wrote: ``` struct S { int x = 1234; } void main() { import std.stdio; S s; //construction of a using &(s.x) auto a = Ref!(int)(&s.x); writeln(a); //displays 1234 s.x += 1; writeln(a); //displays 1235 a += 1;

Re: Anyway to achieve the following

2021-08-16 Thread JG via Digitalmars-d-learn
On Sunday, 15 August 2021 at 21:53:14 UTC, Carl Sturtivant wrote: On Sunday, 15 August 2021 at 07:10:17 UTC, JG wrote: [...] What you are asking for are reference variables. C++ has them: the example here illustrates the behavior you want. https://www.geeksforgeeks.org/references-in-c/ [...

Concurrency message passing

2021-08-17 Thread JG via Digitalmars-d-learn
Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this should have some standard solution in D? I looked at std.concurrency and thought that message passing coul

Re: Concurrency message passing

2021-08-17 Thread JG via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:24:14 UTC, Steven Schveighoffer wrote: On 8/17/21 7:05 AM, JG wrote: Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this shou

Vibe.d error

2021-08-18 Thread JG via Digitalmars-d-learn
Hi, We are intermittently getting the following error: Accept TLS connection: server OpenSSL error at ../ssl/record/rec_layer_s3.c:1543: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown (SSL alert number 46) HTTP connection handler has thrown: Accepting SSL tunnel: e

Re: Vibe.d error

2021-08-20 Thread JG via Digitalmars-d-learn
On Friday, 20 August 2021 at 10:50:12 UTC, WebFreak001 wrote: On Wednesday, 18 August 2021 at 19:51:00 UTC, JG wrote: [...] There might be incompatibilities with how openssl is used and the installed openssl version or config. If you are getting this from having https enabled on the server

Re: Profiling

2021-08-24 Thread JG via Digitalmars-d-learn
On Wednesday, 10 February 2021 at 23:42:31 UTC, mw wrote: On Wednesday, 10 February 2021 at 11:52:51 UTC, JG wrote: As a follow up question I would like to know what tool people use to profile d programs? I use this one: https://code.dlang.org/packages/profdump e.g. ``` dub build --build=

Re: Profiling

2021-08-24 Thread JG via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 09:36:06 UTC, JG wrote: On Wednesday, 10 February 2021 at 23:42:31 UTC, mw wrote: [...] I tried to do this, but I am not sure how to install profdump. What I did is cloned the repository using git. Tried to build it using dub but got an error as described here: [

  1   2   >