Re: automate tuple creation

2022-01-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 19, 2022 at 09:59:15PM +, forkit via Digitalmars-d-learn wrote: > so I have this code below, that creates an array of tuples. > > but instead of hardcoding 5 tuples (or hardcoding any amount of > tuples), what I really want to do is automate the creation of > how-ever-many tuples

Re: shared defaultlib with dmd

2022-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 18, 2022 at 10:04:15PM +, forkit via Digitalmars-d-learn wrote: > so I use this compile command (on Windows, using ldc) > > -link-defaultlib-shared=true > > Then (in simple example) the size of my compiled .exe: > > From 806KB down to 18KB > > Oh. That's so much nicer on my SSD

Re: number ranges

2022-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 18, 2022 at 04:02:42PM +, Tejas via Digitalmars-d-learn wrote: [...] > Newer languages nowadays use `start.. it's something we should follow? I've never seen that before. Which languages use that? T -- "If you're arguing, you're losing." -- Mike Thomas

Re: ldc2 failed with exit code -1073741819.

2022-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 18, 2022 at 05:41:34PM +, Anonymouse via Digitalmars-d-learn wrote: > On Tuesday, 18 January 2022 at 17:37:27 UTC, H. S. Teoh wrote: > > > Bypassing dub and calling the raw ldc command gives no output. > > > What else can I do? > > > > What does `echo $?` print immediately after

Re: ldc2 failed with exit code -1073741819.

2022-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 18, 2022 at 05:20:04PM +, Anonymouse via Digitalmars-d-learn wrote: > On Tuesday, 18 January 2022 at 16:43:52 UTC, H. S. Teoh wrote: > > What's the dustmite command you used? In such cases, it's useful to > > check for this specific error message in your dustmite command, so > >

Re: ldc2 failed with exit code -1073741819.

2022-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 18, 2022 at 04:25:45PM +, Anonymouse via Digitalmars-d-learn wrote: > I did a big sweep through my project and changed all `writefln`s and > `format`s and the such to take their format patterns as compile-time > parameters, and now ldc can no longer build it on Windows. It works

Re: number ranges

2022-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 17, 2022 at 10:35:30PM +, forkit via Digitalmars-d-learn wrote: > On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote: > > > > If I ever needed to foreach over 1-based indices, I'd write it this > > way in order to avoid all confusion: > > > > foreach (i; 1 .. 5 + 1)

Re: number ranges

2022-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 17, 2022 at 10:22:19PM +, forkit via Digitalmars-d-learn wrote: [...] > I think it's fair to say, that I'm familiar with 0-based indexing ;-) > > my concern was with the 1..5 itself. > > In terms of what makes sense, it actually makes more sense not to use > it, at all ;-) If I

Re: number ranges

2022-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 17, 2022 at 09:37:31PM +, forkit via Digitalmars-d-learn wrote: > On Monday, 17 January 2022 at 11:58:18 UTC, Paul Backus wrote: > > > > This kind of half-open interval, which includes the lower bound but > > excludes the upper bound, is used in programming because it lets you > >

Re: Throw stack trace from program kill

2022-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 16, 2022 at 01:42:21PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/16/22 1:33 PM, Paul Backus wrote: [...] > > ```d > > extern(C) void handleCtrlC(int) > > { > > import core.stdc.stdlib: exit; > > import std.stdio: writeln; > > > > try throw new

Re: Dynamic array ot not

2022-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 16, 2022 at 08:21:29AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/16/22 07:32, Salih Dincer wrote: > > On Sunday, 16 January 2022 at 11:43:40 UTC, Ali Çehreli wrote: > >> > >> void main() { > >> enum count = 7; > >> > >> // Allocate some memory > >> void* rawData =

Re: How to convert a chunks result to a two-dimensional array

2022-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 15, 2022 at 01:49:14AM +, forkit via Digitalmars-d-learn wrote: [...] > int[][] arrayOfarrays = iota(1, 16).chunks(5).to2Darray; // how to > convert this into [][] [...] auto arrayOfArrays = iota(1, 16).chunks(5).map!(r => r.array).array; T -- Winners never quit,

Re: Static indexing

2022-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 12, 2022 at 11:04:59AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/12/22 3:59 AM, JG wrote: [...] > >     struct Point > >     { > >   double x; > >   double y; > >   alias expand = typeof(this).tupleof; > >   alias expand this; > >     }

Re: @safe question

2022-01-11 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 12, 2022 at 12:24:14AM +, forkit via Digitalmars-d-learn wrote: > On Tuesday, 11 January 2022 at 21:50:00 UTC, Paul Backus wrote: > > .. > > If you know a particular bit of code is memory safe, but the compiler > > can't prove it, you can mark that code as @trusted. For example: >

Re: print ubyte[] as (ascii) string

2022-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 07, 2022 at 07:54:28PM +, eugene via Digitalmars-d-learn wrote: [...] > * Does .until() make a copy of original string? And GC then will take > care of it? No, it's one of the lazy range functions that lazily evaluates the string and does not allocate. > * So many ways to do

Re: mixin does not work as expected

2022-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 05, 2022 at 11:29:08PM +, Era Scarecrow via Digitalmars-d-learn wrote: [...] > That said, rolling your own mixins should really be the last resort. > You're dumping a lot into a single line of code you can't trace, > follow, debug, or look at. Mixins are kinda like the nuclear

Re: mixin does not work as expected

2022-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 05, 2022 at 08:40:15AM +, rempas via Digitalmars-d-learn wrote: [...] > void test(bool signed)(int num, int base) { > static if (signed) { > mixin(type_check!("static if", "i8", "true", "5", "4", "10", "5")); > mixin(type_check!("else static if", "i16", "true", "7", "6",

Re: what is going on here?

2022-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 05, 2022 at 08:00:45AM +, forkit via Digitalmars-d-learn wrote: [...] > Well, in my case, it was nice to see that the oom reaper thread is > working correctly ;-) I'm well-acquainted with the OOM reaper; it and dmd are good friends, and love to throw parties esp. when CTFE and

Re: what is going on here?

2022-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 04, 2022 at 03:34:41PM -0800, H. S. Teoh wrote: [...] > Of course, afterwards the optimizer would merge them into something > saner, but while the compiler is unfolding all those assignments, its > memory usage would obviously skyrocket. Or the compiler would run out of memory before

Re: what is going on here?

2022-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 04, 2022 at 10:53:50PM +, forkit via Digitalmars-d-learn wrote: [...] > // > > module test; > void main(){ static char[2147483646] arr; } > > // I bet you it's the same problem I found a couple of years ago, where the compiler translates the above code to something

Re: Is there a File-like object for unit tests?

2022-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 04, 2022 at 05:01:41PM +, Amit via Digitalmars-d-learn wrote: > Hi! > > I wrote a text parser that takes a File argument and parses that > file's contents. Now I would like to write a unit-test for that > parser. I need a File (or a general IO interface) that reads from an >

Re: function(pointer) as template argument, explicit template instantiation

2021-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 31, 2021 at 11:52:21AM +, kdevel via Digitalmars-d-learn wrote: [...] > That is what I want to do. The function template lyr shall be > (explicitly) instantiated in order to put the resulting function > pointer into an AA. The call signature of lyr!(foo) and foo must be > the same.

Re: How to print unicode characters (no library)?

2021-12-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 27, 2021 at 04:40:19PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Monday, 27 December 2021 at 15:26:16 UTC, H. S. Teoh wrote: > > A lot of modern Linux applications don't even work properly under > > anything non-UTF-8 > > yeah, you're supposed to check the locale but

Re: How to print unicode characters (no library)?

2021-12-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 27, 2021 at 02:30:55PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Monday, 27 December 2021 at 11:21:54 UTC, rempas wrote: > > So should I just use UTF-8 only for Linux? > > Most unix things do utf-8 more often than not, but technically you are > supposed to check the

Re: How to print unicode characters (no library)?

2021-12-26 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 26, 2021 at 11:45:25PM +, max haughton via Digitalmars-d-learn wrote: [...] > I think that mental model is pretty good actually. Maybe a more > specific idea exists, but this virtual machine concept does actually > explain to the new programmer to expect dragons - or at least that

Re: How to pass a class by (const) reference to C++

2021-12-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 15, 2021 at 10:01:19PM +, Jan via Digitalmars-d-learn wrote: > On Wednesday, 15 December 2021 at 21:30:47 UTC, Tim wrote: [...] > ```cpp > extern export __gshared static int var; > ``` [...] > Joking aside, I understood the docs such that `__gshared` actually > *is* `static` in D,

Re: A debug class has started

2021-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 13, 2021 at 10:43:14PM +, forkit via Digitalmars-d-learn wrote: > On Monday, 13 December 2021 at 21:13:25 UTC, H. S. Teoh wrote: > > > > What you should be doing is: > > > > return to!string(str[0 .. len]); > > > > Or just: > > > > return str[0 .. len].idup; [...] >

Re: A debug class has started

2021-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 13, 2021 at 08:58:42PM +, forkit via Digitalmars-d-learn wrote: [...] > immutable(char)[] replaceChar(char* str, ulong len, char ch1, char ch2) > { > for (ulong i = 0; i < len; i++) > { > if (str[i] == ch1) > { > writefln("Found %c at str[%d]",

Re: A debug class has started

2021-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 13, 2021 at 08:47:12PM +, forkit via Digitalmars-d-learn wrote: > On Monday, 13 December 2021 at 20:28:26 UTC, H. S. Teoh wrote: > > On Mon, Dec 13, 2021 at 08:04:24PM +, forkit via Digitalmars-d-learn > > wrote: [...] > > > (this produces an unpredictable result??) > > > char*

Re: A debug class has started

2021-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 13, 2021 at 08:04:24PM +, forkit via Digitalmars-d-learn wrote: > On Monday, 13 December 2021 at 12:06:53 UTC, WebFreak001 wrote: > > > > You should really use `.dup` if you want to mutate your string. (You > > would need to duplicate anyway if you don't want an unsafe cast) > >

Re: Struct fields and properties as alias members

2021-12-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 08, 2021 at 05:21:49PM +, Ben Jones via Digitalmars-d-learn wrote: [...] > I considered just having a `ref int` parameter, but I didn't think > that would work if I was actually calling a property function, rather > than just modifying a struct member. [...] Why not pass the

Re: Struct fields and properties as alias members

2021-12-08 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 08, 2021 at 05:19:32PM +, Ben Jones via Digitalmars-d-learn wrote: > I'm trying to use a property member of a struct as a template alias > parameter and I don't really understand how to fix the error message > I'm seeing (I also tried the simpler case of a plain struct member, >

Re: sleeping vs sched_yield

2021-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 02, 2021 at 11:29:17PM +, Chris Katko via Digitalmars-d-learn wrote: [...] > It seems I can (thanks to the amazing work of D community) simply do: > > ```d > extern(C) int sched_yield(void); // #include > ``` > > however, how does the linker know I need and not some local >

Re: from bytes to string

2021-11-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 27, 2021 at 03:24:43PM +, Coder via Digitalmars-d-learn wrote: [...] > Question, why a function can not be nothrow if I catch in the body? > > void foo() nothrow { > import std.utf : validate, UTFException; > try { > validate("a"); > } >

Re: Any additions for write-to-file short program

2021-11-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 19, 2021 at 10:21:52PM +, pascal111 via Digitalmars-d-learn wrote: [...] > When I compiled the code after adding yours, I found this error message: > > "untitled20.d:24:8: error: no property 'copy' for type 'ByChunk' >24 |.copy(outputFile.lockingBinaryWriter); // copy

Re: How to read a single character in D language?

2021-11-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 19, 2021 at 10:21:42PM +, Adam Ruppe via Digitalmars-d-learn wrote: [...] > The OS functions for getch alone though are actually pretty simple: > > 1) change the terminal to "raw" mode. the default is to buffer lines, > which means your application doesn't get anything until a

Re: Any additions for write-to-file short program

2021-11-18 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 18, 2021 at 10:20:48PM +, pascal111 via Digitalmars-d-learn wrote: > In next program that rewrites original written texts into new files, I > see that it may need some additions or we can accept it like this > because it's just a simple program that achieve its task and doesn't >

Re: Incomplete words read from file

2021-11-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 18, 2021 at 12:39:12AM +, jfondren via Digitalmars-d-learn wrote: [...] > If what you're wanting to do is to *reshape* text so that it prints > with proper word-breaks across lines according to the current size of > the terminal, then you've got to do this work yourself. [...]

Re: Are templated functions always re-constructed?

2021-11-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 17, 2021 at 11:12:22AM +, rempas via Digitalmars-d-learn wrote: > On Tuesday, 16 November 2021 at 21:30:08 UTC, H. S. Teoh wrote: > > > > Short answer: a template called with the same CT arguments will only > > be instantiated once, and reused thereafter. > > > > Long answer: the

Re: French and Greek strings

2021-11-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 17, 2021 at 12:58:43AM +, pascal111 via Digitalmars-d-learn wrote: > How can I use types to make string and char variables that hold French > and Greek characters? For strings, just use `string`. :-) D strings are Unicode by default, no further effort is needed to use it.

Re: Are templated functions always re-constructed?

2021-11-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 16, 2021 at 09:14:50PM +, rempas via Digitalmars-d-learn wrote: > Let's say that I have the following function: > > ``` > void add(T)(T val, T val2) { return val + val2; } // Classic example, lol > ``` > > Now let's say that I call the function passing an `int` parameter. The >

Re: Make sure lifetime of helper structs is less than owning struct

2021-11-15 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 15, 2021 at 03:56:57PM +, WebFreak001 via Digitalmars-d-learn wrote: > I have an API with some struct like a file reader. I want to add > byChunks-like functionality to it, so I'm trying to implement it with > a helper struct that implements opApply. I have disabled copying the >

Re: Completing C code with D style

2021-11-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 11, 2021 at 01:09:26AM +, forkit via Digitalmars-d-learn wrote: > On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote: > > On Wed, Nov 10, 2021 at 11:39:40PM +, forkit via Digitalmars-d-learn > > wrote: [...] > > > I still remember compiling code on my 286x86 ...

Re: Completing C code with D style

2021-11-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 10, 2021 at 11:39:40PM +, forkit via Digitalmars-d-learn wrote: [...] > I still remember compiling code on my 286x86 ... talk about low > memory..whoaaah. That's nothing! ;-) When I was a kid, I programmed a computer that had only 48K of RAM (that's 48 *kilo*bytes, not

Re: Completing C code with D style

2021-11-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 10, 2021 at 03:13:08PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 11/10/21 3:05 PM, H. S. Teoh wrote: > > > I cannot compile even simple programs on a low-memory system because > > the compiler runs out of memory > > Did the -lowmem switch help in some cases? On my

Re: Completing C code with D style

2021-11-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 10, 2021 at 10:17:48PM +, russhy via Digitalmars-d-learn wrote: > On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote: > > btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I > > really don't give a damn about allocations .. not one little bit ;-) > > It's

Re: How do you declare manifest constants?

2021-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 04, 2021 at 01:17:02PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 11/4/21 10:36 AM, H. S. Teoh wrote: > > > import __stdin : myversion; > > Where can we learn more of that magic? :) [...] I kinda cheated, because I was the one who implemented dmd's stdin feature, so

Re: How do you declare manifest constants?

2021-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 04, 2021 at 05:24:44PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > On Thursday, 4 November 2021 at 17:09:31 UTC, Steven Schveighoffer wrote: > > D doesn't have any equivalent for this. > > Is it possible to add this feature having `-C VERSION="1.2.3"` (`-D` > is already

Re: curses/ncurses liberary in D

2021-11-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 03, 2021 at 01:33:28AM +, dangbinghoo via Digitalmars-d-learn wrote: > On Wednesday, 3 November 2021 at 00:50:31 UTC, pascal111 wrote: > > How can I include "ncurses" liberary in D? I'm using Ubuntu and GDC! > > Search ncurses in Dub registray shows that there's 3 ncurses D >

Re: Does associative array change the location of values?

2021-10-31 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Oct 31, 2021 at 09:54:23AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 10/31/21 9:49 AM, H. S. Teoh wrote: > > > The current spec explicitly states that masking pointers this way is UB. > > Ok. :) What about unions? > > union U { > ulong u; > void* p; > } > > Can the GC

Re: Does associative array change the location of values?

2021-10-31 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 30, 2021 at 07:56:35PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 10/30/21 3:47 PM, Elronnd wrote: > > > If the GC were moving, it would also have to move the pointers you > > took to AA elements. > > I doubt D's GC can ever change pointer values because the values may >

Re: Does associative array change the location of values?

2021-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 29, 2021 at 05:58:24PM +, Paul Backus via Digitalmars-d-learn wrote: > On Friday, 29 October 2021 at 17:40:38 UTC, Andrey Zherikov wrote: > > I want to have a pointer to a value in an associative array. Does AA > > guarantee that the value will remain at the same address all the >

Re: What is D's "__debugbreak()" equivalent?

2021-10-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 27, 2021 at 04:54:49PM +, Simon via Digitalmars-d-learn wrote: > Microsofts C++ compiler provides the __debugbreak function, which on > x86 emits interrupt 3, which will cause the debugger to halt. What is > the equivalent in D? I tried using raise(SIGINT) from > core.stdc.signal,

Re: Unexpected path of execution

2021-10-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 19, 2021 at 09:20:39AM -0700, Charles Hixson via Digitalmars-d-learn wrote: > given this code fragment: > >             if    (i < (line.length - 3) ) >             {    writeln ("in c4: i = ", i, ", line.length = ", > line.length); >                   add2 (c4, line [i..i+4]); > I

Re: Create array from range

2021-10-09 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 09, 2021 at 11:58:14PM +, Greg Strong via Digitalmars-d-learn wrote: > This should be a simple question, but I'm having difficult finding an > answer. How do I filter some elements of an array into a new array? > The filter! function returns a range, but I can't seems to assign

Re: Managing malloced memory

2021-10-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 06, 2021 at 06:06:38PM +, anon via Digitalmars-d-learn wrote: > I interface to a C library that gives me a malloced object. How can I manage > that pointer so that it gets freed automatically. > What I've thought of so far: [...] > * struct wrapped in automem/ refcounted: The

Re: Sort bug / strangeness

2021-10-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 01, 2021 at 06:30:48PM +, Danny Arends via Digitalmars-d-learn wrote: [...] > Is there a sort() algorithm that avoids swapping the items themselves > and e.g. just returns the indexes so I can reorder the original array > myself ?

Re: Program crash: GC destroys an object unexpectedly

2021-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 21, 2021 at 08:36:49PM +, eugene via Digitalmars-d-learn wrote: > On Tuesday, 21 September 2021 at 20:17:15 UTC, eugene wrote: > > > Now, change operation order in the main like this: > > Actually, all proposed 'fixes' > > - use stopper somehow in the end

Re: Program crash: GC destroys an object unexpectedly

2021-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 21, 2021 at 08:17:15PM +, eugene via Digitalmars-d-learn wrote: [...] > ```d > void main(string[] args) { > > auto Main = new Main(); > Main.run(); > > auto stopper = new Stopper(); > stopper.run(); > ``` [...] > ```d > void main(string[] args) { > > auto

Re: Program crash: GC destroys an object unexpectedly

2021-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 21, 2021 at 07:42:48PM +, jfondren via Digitalmars-d-learn wrote: > On Monday, 13 September 2021 at 17:18:30 UTC, eugene wrote: > > I do not understand at all why GC considers those sg0 and sg1 as > > unreferenced. > > And why old gdc (without -Os) and old ldc do not. > >

Re: Which operators cannot be overloaded and why not?

2021-09-14 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 13, 2021 at 06:19:20PM +, NonNull via Digitalmars-d-learn wrote: > On Monday, 13 September 2021 at 16:12:34 UTC, H. S. Teoh wrote: > > On Mon, Sep 13, 2021 at 02:12:36PM +, NonNull via > > Digitalmars-d-learn wrote: > > > Which operators cannot be overloaded and why not? > > >

Re: Which operators cannot be overloaded and why not?

2021-09-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 13, 2021 at 02:12:36PM +, NonNull via Digitalmars-d-learn wrote: > Which operators cannot be overloaded and why not? Others have already given the list, so I won't repeat that. As to the "why": In general, D tries to avoid the wild wild west, every operator for himself situation

Re: Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Sep 12, 2021 at 01:08:17AM +, Alex Bryan via Digitalmars-d-learn wrote: > I am having trouble discovering what the proper (or at least a proper) > way is to write a function that can take either a static or dynamic > array as a parameter. My current implementation consists of 2 >

Re: Phobos Unittest

2021-09-03 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 03, 2021 at 11:39:44PM +, Per Nordlöw via Digitalmars-d-learn wrote: > When is a phobos unittest supposed to be qualified with version > `(StdUnittest)`? Ideally, always? I don't see that their current use > is consistenly following a rule. If so, is the purpose of its presence >

Re: template parameters

2021-09-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 02, 2021 at 02:28:23PM -0700, Charles Hixson via Digitalmars-d-learn wrote: [...] > -- > Javascript is what you use to allow third part programs you don't know > anything about and doing you know not what to run on your computer. ROFL! I'm st^Wborrowing this for my quotes file. ;-)

Re: Run-time setting of immutable variable?

2021-09-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 02, 2021 at 05:17:15PM +, DLearner via Digitalmars-d-learn wrote: [...] > The following clean-compiled and produced the expected result: > ``` > ubyte[10] Arr; > > immutable void* ArrPtr; > shared static this() { > ArrPtr = cast(immutable void*)([0]);

Re: Run-time setting of immutable variable?

2021-09-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 02, 2021 at 04:01:19PM +, DLearner via Digitalmars-d-learn wrote: > Suppose there is a variable that is set once per run, and is > (supposed) never to be altered again. However, the value to which it > is set is not known at compile time. This is the classic use case of

Re: Question on Immutability

2021-08-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 30, 2021 at 11:27:07PM +, Merlin Diavova via Digitalmars-d-learn wrote: > Hi All, > > I'm trying to understand immutability in D and it seems a bit odd. > I'm coming from dynamic languages so please forgive my ignorance and > dynamic language-isms. > > I want to have a base

Re: Interpolate dates

2021-08-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 30, 2021 at 12:06:46AM +, Booster via Digitalmars-d-learn wrote: > I have some dates and date-times. I need to interpolate the date-times > from the dates. Try looking at std.datetime perhaps? T -- The diminished 7th chord is the most flexible and fear-instilling chord. Use it

Re: Mixin/static if issue

2021-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 25, 2021 at 10:16:39PM +, DLearner via Digitalmars-d-learn wrote: > Please see below: > ``` > void main() { >import std.stdio; > >uint TestVar = 5; > >string mxnWrite_Size_t(string VarName) { ^^ Obviously, VarName is a string.

Re: foreach() behavior on ranges

2021-08-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 25, 2021 at 04:46:54PM +, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > On Wednesday, 25 August 2021 at 10:59:44 UTC, Steven Schveighoffer wrote: > > structs still provide a mechanism (postblit/copy ctor) to properly > > save a forward range when copying, even if the

Re: foreach() behavior on ranges

2021-08-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 24, 2021 at 08:36:18AM +, frame via Digitalmars-d-learn wrote: > Consider a simple input range that can be iterated with empty(), > front() and popFront(). That is comfortable to use with foreach() but > what if the foreach loop will be cancelled? If a range isn't depleted > yet

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 17, 2021 at 07:53:52PM +, james.p.leblanc via Digitalmars-d-learn wrote: > On Tuesday, 17 August 2021 at 19:44:29 UTC, H. S. Teoh wrote: > > You could use a helper template and an AliasSeq for this: > > > > template isAmong(T, S...) { > > static if (S.length == 0)

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 17, 2021 at 07:22:54PM +, james.p.leblanc via Digitalmars-d-learn wrote: [...] > auto moo(T : (int || float || mySpecialStruct )(T myMoo) {•••} > > When re-using any such sets, it would be nice to define the set as > follows: > > S = (int || float || mySpecialStruct) > > and

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 17, 2021 at 06:11:56PM +, james.p.leblanc via Digitalmars-d-learn wrote: > Evening All, > > Eponymous templates allow a nice calling syntax. For example, "foo" > here can be called without needing the exclamation mark (!) at calling > sites. We see that foo is restricting a,

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 13, 2021 at 04:35:54PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 8/13/21 4:23 PM, Marcone wrote: > > > string x = "Hello World!"; > > writeln(x[x.indexOf("e")..x.indexOf("r")]); > > I don't see the usefulness and there are the following problems with > it: > > - Not an

Re: Anyway to achieve the following

2021-08-13 Thread H. S. Teoh via Digitalmars-d-learn
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 location? References are essentially pointers under the

Re: nested templates using Complex! with slices, ... confused, I am!

2021-08-09 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 09, 2021 at 06:35:56PM +, james.p.leblanc via Digitalmars-d-learn wrote: [...] > > **T[] foo_temp(Complex!T[])(T x, T y){ > > auto r = [x, x]; > > auto i = [y, y]; > > auto z = [ Complex!T(x, y), Complex!T(x,y) ]; > > return z; > > }** Your syntax is wrong; the

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 06, 2021 at 06:02:01PM +, james.p.leblanc via Digitalmars-d-learn wrote: [...] > However, do NOT feel stupid ... the motivation behind why > I cannot use a standard int[your_max_length] (in other words, > use a static array), is because I need to do a specified > memory alignment

Re: best/proper way to declare constants ?

2021-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 04:53:38PM +, someone via Digitalmars-d-learn wrote: [...] > I already assumed that loading the data from file is a goner. > > So this leaves me with two choices: > > - keep the code as it is incurring higher-than expected > compilation-time: this is solely used in a

Re: best/proper way to declare constants ?

2021-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 03:09:13PM +, someone via Digitalmars-d-learn wrote: > On Thursday, 5 August 2021 at 10:28:00 UTC, Steven Schveighoffer wrote: > > > H.S. Teoh, I know you know better than this ;) None of this is > > necessary, you just need `rtValue` for both runtime and CTFE (and > >

Re: best/proper way to declare constants ?

2021-08-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 01:39:42AM +, someone via Digitalmars-d-learn wrote: [...] > What happens in the following case ? > > public immutable enum gudtLocations = [ >r"BUE"d : structureLocation(r"arg"d, r"Buenos Aires"d, r"ART"d), >r"GRU"d : structureLocation(r"bra"d, r"São Paulo"d,

Re: best/proper way to declare constants ?

2021-08-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 12:47:06AM +, someone via Digitalmars-d-learn wrote: > What are the pros/cons of the following approaches ? 1) If the constant is a POD (int, float, etc.), use: enum myValue = ...; 2) If the constant is a string or some other array: static immutable

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 02, 2021 at 04:42:14PM +, Rekel via Digitalmars-d-learn wrote: [...] > Also slightly off topic, but when would one use an alias instead of a > function/delegate? I haven't used aliases before. When you want a compile-time binding that could potentially elide the indirect function

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Aug 02, 2021 at 02:31:45PM +, Rekel via Digitalmars-d-learn wrote: > I recently found one can return function calls to void functions, > though I don't remember any documentation mentioning this even though > it doesn't seem trivial. This is intentional, in order to make it easier to

Re: translate C struct char array into D

2021-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 30, 2021 at 03:41:32PM +, Tejas via Digitalmars-d-learn wrote: > On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote: [...] > > ```d > > struct test1 { > > // member variables... > > > > char* data() { > > return cast(char*) ( + 1); > > } > > } > > ``` >

Re: Build time

2021-07-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 23, 2021 at 06:53:06PM +, JG via Digitalmars-d-learn wrote: [...] > 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

Re: Not allowed to globally overload operators?

2021-07-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 7/19/21 11:20 PM, Tejas wrote: > > > trying to create the spaceship operator of C++ > > Just to make sure, D's opCmp returns an int. That new C++ operator was > added to provide the same semantics. [...]

Re: Yet another parallel foreach + continue question

2021-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 20, 2021 at 02:39:58AM +, seany via Digitalmars-d-learn wrote: > On Tuesday, 20 July 2021 at 02:31:14 UTC, H. S. Teoh wrote: > > On Tue, Jul 20, 2021 at 01:07:22AM +, seany via Digitalmars-d-learn > > wrote: > > > On Tuesday, 20 July 2021 at 00:37:56 UTC, H. S. Teoh wrote: > >

Re: Yet another parallel foreach + continue question

2021-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 20, 2021 at 01:07:22AM +, seany via Digitalmars-d-learn wrote: > On Tuesday, 20 July 2021 at 00:37:56 UTC, H. S. Teoh wrote: > > On Tue, Jul 20, 2021 at 12:07:10AM +, seany via Digitalmars-d-learn > > wrote: > > > [...] > > [...] > > > > I didn't test this, but I'm pretty sure

Re: Yet another parallel foreach + continue question

2021-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 20, 2021 at 12:07:10AM +, seany via Digitalmars-d-learn wrote: > Consider : > > for (int i = 0; i < max_value_of_i; i++) { > foreach ( j, dummyVar; myTaskPool.parallel(array_to_get_j_from, > my_workunitSize) { > > if ( boolean_function(i,j) ) continue; >

Re: Creating immutable arrays in @safe code

2021-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 16, 2021 at 10:23:31PM +, Dennis via Digitalmars-d-learn wrote: > On Friday, 16 July 2021 at 20:45:11 UTC, H. S. Teoh wrote: > > Have you tried `pure`? > > The code in question is all `@safe pure nothrow`. Hmm, OK. Not sure why .array isn't being inferred as unique... but yeah,

Re: Creating immutable arrays in @safe code

2021-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 16, 2021 at 08:19:32PM +, Dennis via Digitalmars-d-learn wrote: [...] > ```D > immutable(int)[] positive(int[] input) @safe > { > return input.filter!(x => x > 0).array; > } > ``` [...] > I could make another primitive (`iarraySort`), but I wonder if there > are more convenient

Re: Module import failing after $ dub add mypackage

2021-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 16, 2021 at 04:54:18PM +, Scotpip via Digitalmars-d-learn wrote: [...] > I simply need a fast binary serialisation lib to read and write a > large list of structs to local disk - it's not for inter-app > communication. The struct is simple and only contains primitive D data >

Re: Please help me understand this function signature: std.stdio.File.byLine

2021-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 15, 2021 at 08:24:57PM +, Scotpip via Digitalmars-d-learn wrote: [...] > For starters, it's now clear to me that a strong understanding of > Templates is essential to make much headway - that's why I got stuck > here. They are dealt with towards the back of the books, but you >

Re: Please help me understand this function signature: std.stdio.File.byLine

2021-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 15, 2021 at 06:08:45PM +, Scotpip via Digitalmars-d-learn wrote: [...] > ``` > auto byLine(Terminator, Char) ( > KeepTerminator keepTerminator = No.keepTerminator, > Terminator terminator = '\x0a' > ) > if (isScalarType!Terminator); > > auto byLine(Terminator, Char) ( >

Re: How to create friends of a class at compile time?

2021-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 15, 2021 at 05:21:45PM +, Tejas via Digitalmars-d-learn wrote: > I can do it like this in C++: > ``` > template > class def > { > friend typename abc; > } > ``` > > I am just hopelessly confused on how to achieve the same in D. D does not have `friend` declarations.

Re: Trivial simple OpenGl working example

2021-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 09, 2021 at 05:11:06AM +, Виталий Фадеев via Digitalmars-d-learn wrote: [...] > I using CPU Pentium B970 It is old CPU, but even it contains a > graphics accelerator. > Mesa DRI Intel(R) HD Graphics 2000 (SNB GT1), has 4 conveers on GPU. > Smartphones also contains GPU. > Because

Re: Error: function `...` without `this` cannot be `const`

2021-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 30, 2021 at 07:40:40PM +, someone via Digitalmars-d-learn wrote: [...] > @property int data() { return m_data; } // read property [...] > string something() @property { return this.whatever; } [...] > Now I am not sure which is the correct way. [...] Both are correct. :-)

Re: Error: function `...` without `this` cannot be `const`

2021-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 30, 2021 at 05:47:05PM +, someone via Digitalmars-d-learn wrote: [...] > ```d > public string getAmountSI( >in float lnumAmount >) const { [...] > } > ``` > > I used to put all attributes BEFORE the function name which now I > understand is completely wrong since they

<    1   2   3   4   5   6   7   8   9   10   >