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

Re: Tuple poilerplate code

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

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

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

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?

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

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:

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

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?

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"?

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

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

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

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

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

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

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?

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

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

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

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)

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

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

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

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

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:

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

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

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

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:

Re: Profiling

2021-08-24 Thread JG via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 09:42:29 UTC, JG wrote: 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

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

Re: Profiling

2021-08-24 Thread JG via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 09:45:31 UTC, JG wrote: On Tuesday, 24 August 2021 at 09:42:29 UTC, JG wrote: On Tuesday, 24 August 2021 at 09:36:06 UTC, JG wrote: [...] In case anyone is interested it seems that it was forked to here: https://github.com/joakim-brannstrom/profdump Perhaps

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

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/

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

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)(); writeln(a); //displays 1234 s.x += 1; writeln(a); //displays 1235 a += 1;

Re: Dustmite and linking error

2021-09-03 Thread JG via Digitalmars-d-learn
On Thursday, 2 September 2021 at 17:56:54 UTC, Vladimir Panteleev wrote: On Thursday, 2 September 2021 at 11:20:18 UTC, Vladimir Panteleev wrote: One way to get a very rough estimate is to take the square of the current reduction (.reduced directory), and divide it by the square of the

Re: Dustmite and linking error

2021-09-03 Thread JG via Digitalmars-d-learn
On Thursday, 2 September 2021 at 11:19:55 UTC, jfondren wrote: On Thursday, 2 September 2021 at 11:04:12 UTC, JG wrote: Hi, We hit a linking error (after upgrading to dub 1.26.0). I thought I would try to use dustmite to create a reduced error test case. One week later it is still running

Dustmite and linking error

2021-09-02 Thread JG via Digitalmars-d-learn
Hi, We hit a linking error (after upgrading to dub 1.26.0). I thought I would try to use dustmite to create a reduced error test case. One week later it is still running (depth 22). I don't suppose there is anyway of determining when it will finish?

Re: Dustmite and linking error

2021-09-04 Thread JG via Digitalmars-d-learn
On Saturday, 4 September 2021 at 07:40:07 UTC, Vladimir Panteleev wrote: On Saturday, 4 September 2021 at 07:38:34 UTC, Andre Pany wrote: The Dustmite condition you are using seems very generic, therefore this error message can be triggered by various code constellations. This might be the

Re: Dustmite and linking error

2021-09-04 Thread JG via Digitalmars-d-learn
On Saturday, 4 September 2021 at 08:05:16 UTC, JG wrote: On Saturday, 4 September 2021 at 07:40:07 UTC, Vladimir Panteleev wrote: On Saturday, 4 September 2021 at 07:38:34 UTC, Andre Pany wrote: The Dustmite condition you are using seems very generic, therefore this error message can be

Re: Dustmite and linking error

2021-09-04 Thread JG via Digitalmars-d-learn
On Friday, 3 September 2021 at 19:56:30 UTC, JG wrote: On Thursday, 2 September 2021 at 17:56:54 UTC, Vladimir Panteleev wrote: On Thursday, 2 September 2021 at 11:20:18 UTC, Vladimir Panteleev wrote: One way to get a very rough estimate is to take the square of the current reduction (.reduced

Re: Dustmite and linking error

2021-09-04 Thread JG via Digitalmars-d-learn
On Saturday, 4 September 2021 at 06:18:52 UTC, JG wrote: On Friday, 3 September 2021 at 19:56:30 UTC, JG wrote: [...] I tried again. What am I doing wrong? cp source ~/tmp/source cd ~/tmp/source dub build --config prog1 2>&1 | grep "collect2: error: ld returned 1 exit status" echo $?

Re: Dustmite and linking error

2021-09-04 Thread JG via Digitalmars-d-learn
On Saturday, 4 September 2021 at 08:54:31 UTC, Mike Parker wrote: On Saturday, 4 September 2021 at 08:19:53 UTC, JG wrote: [...] You should be able to do that now with "sourceFiles" and "sourcePaths". Just avoid the default "source" or "src" directories and specify the paths and/or files

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

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

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

Re: Printing a quoted string

2022-01-02 Thread JG via Digitalmars-d-learn
On Sunday, 2 January 2022 at 17:27:53 UTC, Amit wrote: Hi! I would like to print a string in the same format that I would write it in the code (with quotes and with special characters escaped). Similar to [Go's %q format](https://pkg.go.dev/fmt#hdr-Printing). Is there a safe, built-in way

SumType

2021-10-28 Thread JG via Digitalmars-d-learn
I am heavily using SumType (which I like very much). The problem I am having is that is seems to be causing slow compile times (as can be observed by profiling during the compile). The problem seems to be with match (which is extremely convenient to use). I looked at the code and it does the

Re: SumType

2021-10-28 Thread JG via Digitalmars-d-learn
On Thursday, 28 October 2021 at 13:30:53 UTC, Paul Backus wrote: On Thursday, 28 October 2021 at 09:02:52 UTC, JG wrote: I am heavily using SumType (which I like very much). The problem I am having is that is seems to be causing slow compile times (as can be observed by profiling during the

Re: what's the most efficient way to implement std.container.binaryheap.back()?

2021-10-25 Thread JG via Digitalmars-d-learn
On Monday, 25 October 2021 at 04:49:12 UTC, mw wrote: Hi, https://dlang.org/phobos/std_container_binaryheap.html The binary heap induces structure over the underlying store such that accessing the largest element (by using the front property) is a Ο(1) operation. I'm wondering what's the

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

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

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

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

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

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 =

Static indexing

2022-01-12 Thread JG via Digitalmars-d-learn
Hi, I want to make a type which has two fields x and y but can also be indexed with [0] and [1] checked at compile time. Is the following reasonable / correct? struct Point { double x; double y; alias expand = typeof(this).tupleof; alias expand this; }

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

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: How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread JG via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 12:27:16 UTC, Dennis wrote: On Tuesday, 25 January 2022 at 12:11:01 UTC, JG wrote: Any ideas how one can achieve what is written in the subject line? ```D void f(T...)(auto ref T args, string file = __FILE__, int line = __LINE__) { writeln(file, ":", line,

How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread JG via Digitalmars-d-learn
Any ideas how one can achieve what is written in the subject line? f below does achieve this but I one would expect that it produces significant template bloat. g achieves the aim but isn't very elegant. import std; void f(string file=__FILE__,size_t line=__LINE__,R...)(R r) {

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

Re: container vs standard array

2023-09-19 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 =

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

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.

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

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"

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

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: Question on shapes

2022-05-18 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

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

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;

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

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

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

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.

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.

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

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

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

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    

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

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

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

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

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

  1   2   >