Re: printf, writeln, writefln

2022-12-08 Thread Ali Çehreli via Digitalmars-d-learn
On 12/8/22 08:21, Salih Dincer wrote: > void stringCopy(Chars)(string source, > ref Chars target) >sample.stringCopy = cTxt; // disappeared ? char Nothing disappeared on my system. (?) Going off-topic, I find the expression above extremely confusing. I am used to

Re: gcc -E -dD; dstep; sqlite3

2022-12-08 Thread Ali Çehreli via Digitalmars-d-learn
On 12/8/22 06:28, johannes wrote: > enum __FLT128_MAX__ = 1.18973149535723176508575932662800702e+4932F128; That literal is not legal D. The "F128" characters at the end are extra. Besides, D does not have a 128-bit floating point type. Ali (Sorry for double e-mail.)

Re: printf, writeln, writefln

2022-12-07 Thread Ali Çehreli via Digitalmars-d-learn
On 12/6/22 15:07, johannes wrote: > 'write' prints out the address > of the first byte. This is odd to me because printf does the job > correctly. printf behaves as what you expect because %s means dereferencing the pointer values and printing the char contents until printf sees '\0'. > But

Re: Confused about something in the D book relating to precision

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 18:57, thebluepandabear wrote: > I am not understanding why Ali said there is a decimal mark if precision > is nonzero? > > How can a number have zero precision? That "precision" is referring to how many digits are printed after the decimal mark in the formatted output. > "the

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 15:25, Adam D Ruppe wrote: > which would trigger the write barrier. The thread isn't > allowed to complete this operation until the GC is done. According to my limited understanding of write barriers, the thread moving to 800 could continue because order of memory operations may

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 12:17, Adam D Ruppe wrote: On Sunday, 4 December 2022 at 17:53:00 UTC, Adam D Ruppe wrote: Interesting... you know, maybe D's GC should formally expose a mutex that you can synchronize on for when it is running. .. or compile in write barriers. then it doesn't matter if the

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 06:27, Sergey wrote: > if it will be possible to write > library in D and use it from > C/++/Python/R/JVM(JNI)/Erlang(NIF)/nameYourChoice smoothly it will be a > win. Years ago we tried to call D from Java. I realized that it was very tricky to introduce the calling thread to D's

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 05:58, vushu wrote: > I was worried if my library should be GC free May I humbly recommend you question where that thinking comes from? Ali P.S. I used to be certain that the idea of GC was wrong and the creators of runtimes with GC were simpletons. In contrast, people like me,

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/22 13:18, thebluepandabear wrote: > But I don't really understand this? What does it mean that it 'must be > represented by at least 2 bytes'? The integral value of Ğ in unicode is 286. https://unicodeplus.com/U+011E Since 'char' is 8 bits, it cannot store 286. At first, that

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/22 13:44, rikki cattermole wrote: > Yeah you're right, its code unit not code point. This proves yet again how badly chosen those names are. I must look it up every time before using one or the other. So they are both "code"? One is a "unit" and the other is a "point"? Sheesh! Ali

Re: Syntax Sugar for Initializing a Fixed float Array as void*?

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/30/22 16:48, Ali Çehreli wrote: Functions are syntax sugar. :) And I remembered std.array.staticArray. One its overloads should be useful: import std; void main() { auto v3 = staticArray!(0.1f.repeat(5)); auto v4 = staticArray!5(0.1f.repeat); writeln(v3); writeln(v4);

Re: Syntax Sugar for Initializing a Fixed float Array as void*?

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/30/22 16:39, jwatson-CO-edu wrote: Is there a way to write a single statement that creates a void pointer that points to an initialized float array?  See below: ```d float* arr = cast(float*) new float[4]; arr[0] = 0.1; arr[1] = 0.1; arr[2] = 0.1; arr[3] = 0.1; void* value = cast(void*)

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/22 15:25, DLearner wrote: > 'dynamic array' is > not a reasonable description for a construct that behaves like > VarArr2[3] becoming 40. I agree with you: It has always bothered me to call the following a dynamic array: int[] arr; 'arr' is not a dynamic array but the slice

Re: Is there a formula for overflow?

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/22 19:07, thebluepandabear wrote: > But the book doesn't talk about why the D compiler came up with these > results The compiler doesn't do anything special. It's all about the lack of bits to store the value. If the result needs 33 bits but the type has only 32 bits, the

Re: dirEntries removes entire branches of empty directories

2022-11-26 Thread Ali Çehreli via Digitalmars-d-learn
On 11/14/22 14:41, kdevel wrote: > the ftw version gets the whole information from readdir alone. Created an enhancement request: https://issues.dlang.org/show_bug.cgi?id=23512 Ali

Re: Assigning parameter on entry to a function and assigning back on exit

2022-11-25 Thread Ali Çehreli via Digitalmars-d-learn
On 11/25/22 05:06, Victor Porton wrote: >> A function argument that is both input and output, may be passed to >> the function either as reference or do two assignments: on entry of >> the function it is assigned to the parameter, on exit it is assigned >> back. The way I understand it with C,

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/22 14:37, [] () {} () wrote: > so, as I understand it, your're against the use of private, against the > use of class, and against the use of encapsulation. I never implied any of that. > .. good luck with your career as a software engineer (but please, for > all our sakes, don't work

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/22 23:01, [] () {} () wrote: > On that basis, I might be tempted to agree with you're point of view -> > never, ever, ever, ever, use classes in D. That's not my point of view. Ali

Re: Is defining get/set methods for every field overkill?

2022-11-20 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/22 00:31, [] () {} () wrote: > Quoted from that video (the one that you agree with): > > "I don't ever think that private .. private is like just .. shouldn't > even be used." > > "so I don't even use classes I just use struct so that everything is > always public .. and that in my

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/22 01:43, [] () {} () wrote: > do it your way for the next 10 years, and > I bet you will eventually come to a different point of view ;-) Hm... I am responding without reading the rest of the thread so I don't know whether you've mentioned the 10 years more but here it goes: I hope

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/22 01:05, [] () {} () wrote: > All this because some programmer wanted to save a few key strokes, or > did not anticipate change, or did not anticipate the need to ensure data > is valid before assigning it, or returning it. > > So no. It's not overkill. It's called software

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/22 20:13, [] () {} () wrote: > after 10 years of doing all that, you may well come to the conclusion > that public member variables are not such a great idea afterall ;-) It depends. Majority of my structs are pure data. When there is no invariant to protect, then there is no reason

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/22 19:35, [] () {} () wrote: > I like to see an example, of a 'class type' with 'public' member > variables, somehow magically converted into both getter and setter using > UFCS, without breaking client code. UFCS was mentioned before in the same context but I think what is meant was

Re: Is defining get/set methods for every field overkill?

2022-11-16 Thread Ali Çehreli via Digitalmars-d-learn
On 11/16/22 20:39, thebluepandabear wrote: > I am debating whether or not I should add getter methods to these > properties. If you are debating, then the answer is easy: you should not. :) Less code written means less bugs, more cohesion, easier refactoring, cleaner code, all good stuff...

Re: Actual lifetime of static array slices?

2022-11-15 Thread Ali Çehreli via Digitalmars-d-learn
On 11/15/22 06:05, Siarhei Siamashka wrote: > Ali commented that "the > compiler cannot do anything about it in all cases and we wouldn't want > it to spend infinite amount of time to try to determine everything". Yes, that's my understanding. > This sounds like he justifies the compiler's

Re: Actual lifetime of static array slices?

2022-11-14 Thread Ali Çehreli via Digitalmars-d-learn
On 11/14/22 19:05, Elfstone wrote: > @safe > int[] foo() > { > int[1024] static_array; > // return static_array[]; // Error: returning `static_array[]` > escapes a reference to local variable `static_array` That is trivial for the compiler to catch. >

Re: dirEntries removes entire branches of empty directories

2022-11-11 Thread Ali Çehreli via Digitalmars-d-learn
On 11/11/22 08:00, Ali Çehreli wrote: > It may have to do something with the performance of the hard disk. I meant "the reason you got a much better improvement" may have to do something with the performance differences of your hard disk and mine. Ali

Re: dirEntries removes entire branches of empty directories

2022-11-11 Thread Ali Çehreli via Digitalmars-d-learn
On 11/11/22 05:13, kdevel wrote: > dmd -O compiled patched (see below!) version applied to /usr/bin on my > desktop > yields: > > ftw : 363 ms, 750 ÎŒs, and 5 [*] > dirEntries: 18 secs, 831 ms, 738 ÎŒs, and 3 [*] Great. I did not use -O with my test. It may have to do something with the

Re: dirEntries removes entire branches of empty directories

2022-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 12:06, Ali Çehreli wrote: > I am using its sibling 'ftw' Now that we know that dirEntries works properly, I decided not to use ftw. However, ftw performs about twice as fast as dirEntries (despite some common code in the implementation below). I am leaving it here in case somebody

Re: dirEntries removes entire branches of empty directories

2022-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 11:30, Vladimir Panteleev wrote: > On Wednesday, 9 November 2022 at 19:05:58 UTC, Ali Çehreli wrote: >> Running the program shows no output; 'a' is not visited as a directory >> entry. > > That's not what happens for me: Does not happen for me today either. (?) I must have confused

Re: dirEntries removes entire branches of empty directories

2022-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 11:05, Ali Çehreli wrote: > Can you think of a workaround to achieve that? Me, me, me! :) I've learned about the Posix function 'nftw' (but I am using its sibling 'ftw'). It was pretty easy to use but there is a quality issue there: They failed to support a 'void*' context for

Re: dirEntries removes entire branches of empty directories

2022-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 11:48, Imperatorn wrote: > That's not the behaviour I get in Windows. Windows users deserve it! :p (At least it is better in this case. :) ) > When I create the subdirectory, I see it even if it's empty struct DirIteratorImpl has different implementations for Windows, etc. Ali

dirEntries removes entire branches of empty directories

2022-11-09 Thread Ali Çehreli via Digitalmars-d-learn
In case it matters, the file system is ext4. 1) Create a directory: mkdir deleteme and then run the following program: import std; void main() { foreach (e; dirEntries(absolutePath("./deleteme"), SpanMode.breadth)) { writeln(e.name); } } Understandably, the top level

Re: Passing a string by reference

2022-11-08 Thread Ali Çehreli via Digitalmars-d-learn
On 11/8/22 04:53, Alexander Zhirov wrote: > On Tuesday, 8 November 2022 at 12:43:47 UTC, Adam D Ruppe wrote: >> Just use plain `string`. > > So it's always working with thick pointers? Yes, D's arrays are fat pointers. strings are arrays of immutable(char). >> nope, an object isn't created

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 08:40, H. S. Teoh wrote: > D does not have the equivalent of C++'s allocating a class instance on > the stack. Not by default but we have two different ways, either may be discouraged: import std.typecons : scoped; import std.stdio; class C { int i; } void main() { //

Re: Unit testing a function returning void

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 03:00, Bruno Pagis wrote: >void print() { > writeln("array = ", this.array); >} Similar to Paul Backus's program but I would try to avoid the file system for unit tests when possible. In this case, you can print into a sink, which can be useful in other ways as well:

Re: save() feature for iota

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 04:58, Paul Backus wrote: > https://issues.dlang.org/show_bug.cgi?id=23453 Even though iterating over UTF value ranges don't make sense in general, they would work for some values including the ASCII range. Ali

Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread Ali Çehreli via Digitalmars-d-learn
On 11/1/22 10:27, H. S. Teoh wrote: > Maybe try running Digger to reduce the code for you? Did you mean dustmite, which is accessible as 'dub dustmite ' but I haven't used it. My guess for the segmentation fault is that the OP is executing destructor code that assumes some members are

Re: CTFE in betterC needs the GC

2022-10-29 Thread Ali Çehreli via Digitalmars-d-learn
On 10/29/22 20:41, arandomonlooker wrote: > string exampleCTFE(string a, string b) { > return a ~ b; > } Although you need that function only at compile time, it is an ordinary function that could be called at run time as well. The function needs GC for that concatenation in the general

Re: ubyte + ubyte = int

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/26/22 14:19, Ali Çehreli wrote: >https://dlang.org/spec/type.html#integer-promotions Reading "Value Range Propagation" further down that link, I learned that e.g. masking 'decimal' with 0xf makes the code compile: return ((decimal & 0xf) + ubyte('0')); return

Re: ubyte + ubyte = int

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/26/22 14:10, 0xEAB wrote: > I guess, this fancy behavior is inherited from C. Yes. It is called integer promotions: https://dlang.org/spec/type.html#integer-promotions (The next section is related as well.) > I know this is advanced stuff, but the compiler *could* even prove that >

Re: Replacing tango.text.Ascii.isearch

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 22:49, Siarhei Siamashka wrote: > Unicode is significantly simpler than a set of various > incompatible 8-bit encodings Strongly agreed. > I'm surely > able to ignore the peculiarities of modern Turkish Unicode The problem with Unicode is its main aim of allowing characters of

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 19:25, Salih Dincer wrote: > with static in main(): If 'static' makes a difference on your side as well, it is your turn to create a bug report. :) (Last time you discovered a bug, I was too quick to report it. :/) Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 17:16, Salih Dincer wrote: > Excuse me, but they still write in purple prose about dynamic > array literature here! I've heard positive things about D's arrays from people who use D in production. Especially slices... > I've known D for more than 10 years, but the topic we're

Re: auto scope question?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 15:07, WhatMeWorry wrote: > auto screen = executeShell(cmdLine); > auto s; That can't work because there is no information to infer the type of 's'. Judging from the return type of getPath, perhaps it's string[]: string[] s; This is the question we should answer first: What

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 13:36, matheus wrote: > On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote: >> Static arrays are value types. What that means is, when we say float[3], there are just 3 floats without any overhead. >> Dynamic arrays are reference types. That phrase can be confusing

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 13:12, Paul Backus wrote: > In order to create a copy of a static array Although .dup works for static arrays as well, you meant "dynamic array" and everyones knows it. :) > with its own block of > memory, separate from the original, you have to use the built-in `.dup` > method:

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 11:23, Steven Schveighoffer wrote: >> Why do I say incorrect things like that? :) > You were right actually. As always! Now I'm confused. :o) Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 11:01, Ali Çehreli wrote: > static arrays don't have .ptr to point > to any member. Why do I say incorrect things like that? :) Of course static arrays have .ptr as well but that always point to their own body of N elements. They own their elements... I move away from the keyboard

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 10:54, Salih Dincer wrote: > So I don't understand why it causes problems with > dynamic arrays! So why is there nothing wrong with the static array in > the example below? The same rules as other uses of dynamic arrays... > //A[] a = [A.init];/* In that case, there is a

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 08:50, Andrey Zherikov wrote: > I'd like to tune default ctor but structs can't have custom one. > Adding a ctor with parameter seems a hack to me There is static opCall, which may be seen as a hack as well. :) The following all print the same thing now: import std.stdio; struct

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 07:53, Adam D Ruppe wrote: > On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: >> A[] a = [A.init]; > > This is a problem - this is referring to a static array instance, shared > across all copies of B. You almost certainly don't want this. Agreed. It should be

Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/22 14:26, Per Nordlöw wrote: What property of a container (type) `T` enables iteration as ```d foreach (k, v; T.init) {     ... } ``` ? I thought it sufficed to define `T.byKeyValue` but its presence seem to have no effect. Another option is to use range functions where front()

Re: Find in assoc array then iterate

2022-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/22 08:21, Kevin Bailey wrote: > his claim that there was no value. I think he was questioning the need for iterating from a point forward inside an unordered container. When the container is unordered, the elements that are accessed after a found element could be anything. I think

Re: Real simple question... for good programmers

2022-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/22 14:53, WhatMeWorry wrote: > > > string[] tokens = userSID.output.split!isWhite; > writeln("tokens = ", tokens); Could you please show minimal compilable code that demonstrates the issue. I spent some time with some guesses but failed (to get my code to compile with

Re: Find in assoc array then iterate

2022-10-21 Thread Ali Çehreli via Digitalmars-d-learn
On 10/21/22 15:03, 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 easy to iterate through

Re: Catching C errors

2022-10-19 Thread Ali Çehreli via Digitalmars-d-learn
On 10/19/22 09:47, data pulverizer wrote: > It's okay, I've found a work around. Do you simply check the return value? Ali

Re: Catching C errors

2022-10-19 Thread Ali Çehreli via Digitalmars-d-learn
On 10/19/22 07:05, data pulverizer wrote: > I am calling code from a C API, and would like to know how to catch exit > errors If you are talking about the exit() Posix function, you can't do anything about that because its purpose is to cause "normal process termination". Ali

Re: warning LNK4255 - How to solve this warning

2022-10-18 Thread Ali Çehreli via Digitalmars-d-learn
On 10/18/22 12:26, Hipreme wrote: > Is there any way to know which files produced this error or at least the > symbol names that are clashing? I'm totally helpless about this error. There is 'nm' on Posix systems that lists symbols in object files (including libraries and programs). Ali

Re: parallel is slower than serial

2022-10-18 Thread Ali Çehreli via Digitalmars-d-learn
On 10/18/22 06:24, Guillaume Piolat wrote: > To win something with OS threads, you must think of tasks that takes on > the order of milliseconds rather than less than 0.1ms. > Else you will just pay extra in synchronization costs. In other words, the OP can adjust work unit size. It is on the

Re: Reading and wiping notes also adding more notes

2022-10-17 Thread Ali Çehreli via Digitalmars-d-learn
On 10/17/22 22:40, Joel wrote: > I have two text fields. The one on the left has the whole text, new > stuff being added to the bottom. The one on the right has text I've been > wiping as I'm reading. I think this can be modelled as a string array and an index showing where the active part

Re: probably a trivial question...

2022-10-13 Thread Ali Çehreli via Digitalmars-d-learn
Changing the order of lines... On 10/13/22 16:43, WhatMeWorry wrote: > return s.split(';'); // single quotes That one is a single character and very lightweigth because it's just an integral value. You can't put more than one character within single quotes: ';x' // ERROR > return

Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread Ali Çehreli via Digitalmars-d-learn
On 10/5/22 13:40, torhu wrote: auto sw = StopWatch(); Either this: auto sw = StopWatch(AutoStart.yes); or this: auto sw = StopWatch(); sw.start(); Ali

Re: Remove elements without losing capacity

2022-10-04 Thread Ali Çehreli via Digitalmars-d-learn
On 10/4/22 10:59, Riccardo M wrote: > The inherent reason for `remove` to cancel previous capacity and > requiring new allocations is exactly to prevent overwriting data that > could be owned by something else? Yes. A related topic is how the "end slice" never loses that capacity: void main()

Re: rotate left an array

2022-10-03 Thread Ali Çehreli via Digitalmars-d-learn
On 10/3/22 17:00, Paul Backus wrote: > On Monday, 3 October 2022 at 21:06:36 UTC, Ali Çehreli wrote: >> On 10/3/22 13:48, Andrey Zherikov wrote: >>> a "rotated view". >> >> Without indexes: >> >> import std.range : empty; >> >> auto rotatedView(R)(R range) >> in (!range.empty) >> { >> import

Re: rotate left an array

2022-10-03 Thread Ali Çehreli via Digitalmars-d-learn
On 10/3/22 13:48, Andrey Zherikov wrote: a "rotated view". Without indexes: import std.range : empty; auto rotatedView(R)(R range) in (!range.empty) { import std.range : chain, front, only, popFront; const fr = range.front; range.popFront(); return chain(range, only(fr)); }

Re: Stop writeln from calling object destructor

2022-10-02 Thread Ali Çehreli via Digitalmars-d-learn
On 10/2/22 10:55, data pulverizer wrote: > On Sunday, 2 October 2022 at 17:28:51 UTC, data pulverizer wrote: >> Sorry I'll need to implement all the overloaded copy constructors and >> see if that fixes it. > > I've got it, something weird happened to my copy constructor. This was > my original

Re: Stop writeln from calling object destructor

2022-10-02 Thread Ali Çehreli via Digitalmars-d-learn
On 10/2/22 10:28, data pulverizer wrote: > On Sunday, 2 October 2022 at 17:19:55 UTC, data pulverizer wrote: >> Any reason why this could be? > What I noticed first in your original code was that it would be considered buggy because it was not considering copying. Every struct that does

Re: Linker Error with Template Function

2022-10-01 Thread Ali Çehreli via Digitalmars-d-learn
On 10/1/22 11:15, Kyle Ingraham wrote: > storing structs as > `void*` in a wrapper struct with information about their module and > identifier saved elsewhere. Perhaps unrelated but that part reminded me of the following discussion:

Re: How can I get the "owner" of a method?

2022-09-30 Thread Ali Çehreli via Digitalmars-d-learn
On 9/30/22 14:11, solidstate1991 wrote: > extern (C) public int registerDDelegate(alias Func, That can be a lambda that takes ClassType. I wrote the following along with place holder as I assumed them to be: class C { string s; void foo() { import std.stdio : writeln;

Re: Interfacing with basic C++ class

2022-09-29 Thread Ali Çehreli via Digitalmars-d-learn
On 9/29/22 01:28, Riccardo M wrote: > if one should > slightly rearrange C++ code as well. Right. Additionally, the order of members must match (I am pretty sure, which means I am not :p). > I am a recent addition to D > language :) Welcome! :) > Do you know that this is documented

Re: Interfacing with basic C++ class

2022-09-28 Thread Ali Çehreli via Digitalmars-d-learn
On 9/28/22 12:57, Riccardo M wrote: > class MyClass { > public: > int field; > MyClass(int a) : field(a) {} Make the following function 'virtual': > int add(int asd) { virtual int add(int asd) { I think the C++ class does not get a vptr without a virtual function and

Re: to delete the '\0' characters

2022-09-23 Thread Ali Çehreli via Digitalmars-d-learn
On 9/23/22 11:37, Salih Dincer wrote: > * character**S** > * at the **END** > * of the **STRING** I think the misunderstanding is due to the following data you've posted earlier (I am abbreviating): 53 F6 6E 6D 65 64 65 6E 20 79 75 72 64 75 6D 75 6E 20 FC 73 74 FC 6E 64 65 20 74 FC 74 65 6E

Re: to delete the '\0' characters

2022-09-22 Thread Ali Çehreli via Digitalmars-d-learn
On 9/22/22 14:31, Salih Dincer wrote: > string splitz(string s) > { >import std.string : indexOf; >auto seekPos = s.indexOf('\0'); >return seekPos > 0 ? s[0..seekPos] : s; > } If you have multiple '\0' chars that you will continue looking for, how about the following? import std;

Re: to delete the '\0' characters

2022-09-22 Thread Ali Çehreli via Digitalmars-d-learn
On 9/22/22 08:19, Ali Çehreli wrote: > string noZeroes(string s) > { > return s.byCodeUnit.filter!(c => c != '\0'); > } That won't compile; the return type must be 'auto'. Ali

Re: to delete the '\0' characters

2022-09-22 Thread Ali Çehreli via Digitalmars-d-learn
On 9/22/22 03:53, Salih Dincer wrote: > Is there a more accurate way to delete the '\0' characters at the end of > the string? I tried functions in this module: > https://dlang.org/phobos/std_string.html Just to remind, the following are always related as well because strings are arrays, which

Re: Why this function just decides to not call another function and do its thing instead?

2022-09-17 Thread Ali Çehreli via Digitalmars-d-learn
On 9/17/22 10:14, frame wrote: On Saturday, 17 September 2022 at 15:04:48 UTC, solidstate1991 wrote: And then instead just decides that the `localName` and `namespaceURI` pairs are not equal, and in those cases the Visual Studio debugger doesn't detect any entering into any of the

Re: dub lint

2022-09-15 Thread Ali Çehreli via Digitalmars-d-learn
On 9/15/22 16:14, Christian Köstlin wrote: > There is `dub run dscanner -- --defaultConfig` which creates a default > config in `~/.config/dscanner/dscanner.ini` (for linux and osx). Thanks! I love such features. It is so useful for a program to write out its configuration file. (My tools did

Re: dub lint

2022-09-15 Thread Ali Çehreli via Digitalmars-d-learn
On 9/15/22 15:04, Ali Çehreli wrote: > Is there a way to silence specific 'dub lint' warnings? Answering myself, I don't think it's possible but luckily my catching an Error was in unittests only so I can do either of the following to skip unittest code when linting: a) Pass --skipTests to

Re: dub lint

2022-09-15 Thread Ali Çehreli via Digitalmars-d-learn
On 9/15/22 14:32, Ali Çehreli wrote: > (However, like all linters it's not perfect but I still like having that > power.) The following code is flagged because it catches Error: unittest { try { assert(false); } catch (Error) { // Cool... } } [warn]:

dub lint

2022-09-15 Thread Ali Çehreli via Digitalmars-d-learn
I've always thought of dub as a package manager and a build tool. But it actually makes it easy to use other tools: - dub lint: Runs some checks on your project. What I liked is how it removed the need to figure out how to install dscanner, which it uses behind the scenes. It installed

Re: need help to translate C into D

2022-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 9/13/22 04:07, test123 wrote: > On Tuesday, 13 September 2022 at 10:59:36 UTC, Dennis wrote: >> Side node, you can use `immutable` instead of `__gshared const`, it >> amounts to the same for global variables. > > because __enums_layout.ptr need to be part of other object, and this > const ptr

Re: Function attribute best practices

2022-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 9/13/22 10:08, Paul Backus wrote: > Here's my attempt, covering all the attributes found under > [`MemberFunctionAttribute`][1] in the language spec: > > |Attribute|Affects |Inferred?| > |-||-| > |nothrow |Function|Yes | > |pure |Function|Yes | > |@nogc

Re: Function attribute best practices

2022-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/22 09:39, Paul Backus wrote: > Yes. Except for `@trusted`, explicit attributes on template code are a > smell. Except for 'const' as well because some templates are member functions. And 'const' on a member function cannot be left to inference because it happens to be a part of the

Re: Function attribute best practices

2022-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/22 11:29, Steven Schveighoffer wrote: > So you are thinking about this the wrong way I believe. Clearly. > When you put `pure` on a template function, you are saying "only > instantiations where this function can be pure are allowed". Makes sense. I was trying to put as many

Re: Function attribute best practices

2022-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/22 10:29, H. S. Teoh wrote: write a unittest where you instantiate Foo with a deliberately-impure type Yes. A current on-topic thread on the difficulties of covering all corner cases: https://forum.dlang.org/thread/dmnfdqiplbldxkecp...@forum.dlang.org Ali

Re: Function attribute best practices

2022-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/22 09:48, H. S. Teoh wrote: >> @nogc nothrow pure @safe >> unittest >> { >> // ... >> } >> >> No, it isn't because unless my unittest code is impure, I can't catch >> my incorrect 'pure' etc. on my member functions. > [...] > > Sure you can. The `pure unittest` code obviously must

Function attribute best practices

2022-09-12 Thread Ali Çehreli via Digitalmars-d-learn
The following range Foo is trying to be helpful by adding as many attributes as it can ('const' is missing because ranges cannot be 'const' because at least popFront() needs to be mutable): import std.algorithm; struct Foo(R) { R r; int i; bool empty() @nogc nothrow pure @safe

Re: Why I get delegate when passing address of function?

2022-09-11 Thread Ali Çehreli via Digitalmars-d-learn
On 9/11/22 09:26, Ali Çehreli wrote: // This combines a class instance (which is a pointer behind the scene)     // Combine with the class object In both places I meant "class variable". Ali

Re: Why I get delegate when passing address of function?

2022-09-11 Thread Ali Çehreli via Digitalmars-d-learn
On 9/11/22 02:54, Injeckt wrote: > And what I should do to pass non-static function? You can combine your class object with other arguments and your thread function will know how to unwrap your class object to call its member function: import std.stdio; // I am not on Windows, so I am

Re: Dictionary of Templated Functions

2022-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 9/10/22 15:35, jwatson-CO-edu wrote: > So, my solution > will be to construct a catch-all struct `Payload` and have that be my > argument type from which various functions can draw the data of their > choice. Two Phobos features may be helpful there:

Re: Can you access the same classes from C++ and D and vise versa, or do the classes have to not form dependency cycle?

2022-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 9/10/22 13:04, Daniel Donnell wrote: > https://dlang.org/spec/cpp_interface.html At DConf, Manu indicated that that page is outdated and that D's C++ support is actually a lot better. He kind-of-promised to update that page but I doubt it happened yet if ever. :) > one has to be compiled

Re: Using .require for struct types

2022-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 9/10/22 09:33, Erdem Demir wrote: > DListOfA returnVal = temp.require("a", DListOfA());--> I wish I > could use ref DListOfA here But keeping a reference to a temporary would not work because the life of that temporary ends by the end of that expression (practically, at the

Re: Validate static asserts

2022-09-09 Thread Ali Çehreli via Digitalmars-d-learn
On 9/9/22 10:35, Dennis wrote: > On Friday, 9 September 2022 at 16:41:54 UTC, Andrey Zherikov wrote: >> What's about new `compileOutput` trait that returns compiler output? >> ```d >> static assert(__traits(compileOutput, { }) == "message"); >> ``` > > As a compiler dev, that sounds terrifying.

Re: Validate static asserts

2022-09-09 Thread Ali Çehreli via Digitalmars-d-learn
On 9/9/22 07:35, Andrey Zherikov wrote: > might not compile due to many different reasons I faced a related situation recently: My error string generation was buggy, which taught me that the compiler does not even compile the string part of 'static assert' in the 'true' case. The following

Re: Storing a lambda alongside type-erased data

2022-09-08 Thread Ali Çehreli via Digitalmars-d-learn
On 9/8/22 08:02, Paul Backus wrote: > This is actually pretty much exactly what VariantN does Great information, thanks! I am slowly getting up there. :) Ali

Storing a lambda alongside type-erased data

2022-09-07 Thread Ali Çehreli via Digitalmars-d-learn
I am sure nothing is new here and I may have thought of this before but it was a revelation today. :) I've been trying to come up with a way of storing arbitrary number of objects of arbitrary types, which means I would be using a ubyte array. But then how do I use the data later without

Re: Error "Unexpected '\n' when converting from type LockingTextReader to type int"

2022-09-07 Thread Ali Çehreli via Digitalmars-d-learn
On 9/7/22 16:24, Synopsis wrote: > a- What is the difference with this syntax with the exclamation mark? > ```readf!"%s\n"(f1.num);``` That's the templated version, which is safer because it checks at compile time (important distinction) that the arguments and the format specifiers do match.

Re: Comparing slices with std.variant.Algebraic

2022-09-05 Thread Ali Çehreli via Digitalmars-d-learn
On 9/5/22 01:58, anonymouse wrote: > array [1.7, 3.7, 5.7, 7.7, 9.7] in both cases, which is what is being > asserted by those two lines. None of those values can be represented precisely in a floating point type. Without looking at the code, I wonder whether the tests will pass if you can

Re: Why do failed contracts don't dump stack backtrace in unittests?

2022-09-04 Thread Ali Çehreli via Digitalmars-d-learn
On 9/4/22 09:35, Paul Backus wrote:     // TODO: omit stack trace only if assert was thrown     // directly by the unittest. Thank you but I mean... :) I can understand removing a backtrace from the eyes of an end user but the consumer of a unittest output is a developer, no? Ali

  1   2   3   4   5   6   7   8   9   10   >