Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/21 3:30 PM, apz28 wrote: On Friday, 23 July 2021 at 18:44:47 UTC, Steven Schveighoffer wrote: On 7/22/21 7:43 PM, apz28 wrote: In any case, it's possible that fbConnection being null does not mean a null dereference, but I'd have to see the class itself. I'm surprised if you don't

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/21 7:43 PM, apz28 wrote: FbConnection is a class, FbXdrReader is a struct and for this call, response.data is not null & its' length will be greater than zero and FbConnection is not being used. So why DMD try to evaluate at compiled time hence error 1. Should not evaluate at compile

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/21 2:38 PM, apz28 wrote: On Wednesday, 21 July 2021 at 20:39:54 UTC, Dukc wrote: On Wednesday, 21 July 2021 at 14:15:51 UTC, Steven Schveighoffer wrote: 2. It's hard for me to see where the null dereference would be in that function (the `bool` implementation is pretty simple). DMD

Re: associative array with Parallel

2021-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/22/21 1:46 AM, seany wrote: Consider :     int [] ii;     foreach(i,dummy; parallel(somearray)) {   ii ~= somefunc(dummy);     } This is not safe, because all threads are accessing the same array and trying to add values and leading to collision. Correct. You must synchronize

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/21/21 7:56 AM, apz28 wrote: On Wednesday, 21 July 2021 at 11:52:39 UTC, apz28 wrote: On Wednesday, 21 July 2021 at 04:52:44 UTC, Mathias LANG wrote: It seems the compiler is doing extra analysis and seeing that a null pointer is being dereferenced. Can you provide the code for

Re: betterC shared static ctor

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/21/21 5:07 AM, vit wrote: Thanks, it works, but now I have different problem. I need call static method for all instantions of template struct from `crt_constructor`. Is there way to iterate over all instantions of template? Not unless you register them somehow upon instantiation. Or

Re: How to parse a json node that contains children of different types?

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/20/21 11:00 PM, Mathias LANG wrote: But if you take a step back, I think you might find this solution is far from ideal. Having worked on a JSON library myself, I can tell you they are all implemented with a tagged union. And converting a tagged union to a tagged union is no improvement.

Re: Yet another parallel foreach + continue question

2021-07-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/21 10:58 PM, H. S. Teoh wrote: I didn't check the implementation to verify this, but I'm pretty sure `break`, `continue`, etc., in the parallel foreach body does not change which iteration gets run or not. `break` should be undefined behavior (it is impossible to know which loops

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

2021-07-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/15/21 1:43 PM, Tejas wrote: How do you write the equivalent of that in D? Is the answer still the same? Manually keep it in the same module, or is there a programmatic way of converting this to D? Functions in the same module can access `private` members. Functions in the same package

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/21 9:00 AM, Alain De Vos wrote: When I read a record out of the database I receive a jsonb datatatype as a string. How do I convert this string into a json object and parse and manipulate it? Isn't jsonb just a storage assumption for the database (so it can do efficient

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 5:13 PM, rempas wrote: On Friday, 9 July 2021 at 20:54:21 UTC, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in

Re: mixin template's alias parameter ... ignored ?

2021-07-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/11/21 8:49 AM, Adam D Ruppe wrote: On Sunday, 11 July 2021 at 05:20:49 UTC, someone wrote: ```d mixin template templateUGC (    typeStringUTF,    alias lstrStructureID    ) {    public struct lstrStructureID {   typeStringUTF whatever;    } This creates a struct with teh literal

Re: assert(false) and GC

2021-07-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/10/21 12:32 PM, Mathias LANG wrote: On Saturday, 10 July 2021 at 01:38:06 UTC, russhy wrote: On Saturday, 10 July 2021 at 01:23:26 UTC, Steven Schveighoffer wrote: I think it's the throwing/catching of the `Throwable` that is allocating. But I don't know from where the allocation

Re: assert(false) and GC

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 8:44 PM, russhy wrote: On Friday, 9 July 2021 at 23:34:25 UTC, Ali Çehreli wrote: On 7/9/21 4:12 PM, russhy wrote: >> One way of forcing compile-time evaluation in D is to define an enum >> (which means "manifest constant" in that use). That's all I meant. It was a general comment.

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 5:04 PM, Ali Çehreli wrote: On 7/9/21 1:54 PM, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 11:31 AM, Dennis wrote: On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former give extra options

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 10:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read"

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/21 3:52 PM, Sebastiaan Koppe wrote: On Wednesday, 7 July 2021 at 13:30:28 UTC, Steven Schveighoffer wrote: On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully).

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/6/21 11:42 PM, Jon Degenhardt wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: This is pretty minimal, but does what I want it to do. Is it ready for inclusion in Phobos? Not by a longshot! A truly generic interleave would properly forward everything else that

to compose or hack?

2021-07-06 Thread Steven Schveighoffer via Digitalmars-d-learn
So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully). Looking around phobos I found inside the documentation of

Re: How to disable assigning a value to a property?

2021-07-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/6/21 9:27 AM, Jack Applegame wrote: On Tuesday, 6 July 2021 at 12:33:20 UTC, Adam D Ruppe wrote: The language always allows `a = b;` to be rewritten as `a(b);`. And that's sad. It should happen for properties only. Yes, I lament that there is no way to control how people call your

Re: anonymous functions and scope(exit)

2021-07-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/3/21 4:08 PM, frame wrote: On Saturday, 3 July 2021 at 17:39:18 UTC, Steven Schveighoffer wrote: But in practice, the compiler does not have to clean up anything when an `Error` is thrown. Whether it does or not is defined by the implementation. This should be really mentionend in the

Re: anonymous functions and scope(exit)

2021-07-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/3/21 1:20 PM, Luis wrote: This is intentional ? ```     should(function void() {     auto emptyStack = SimpleStack!int();     scope(exit) emptyStack.free; // <= This is never called     emptyStack.reserve(16);     emptyStack.top;    

Re: how much "real-life" code can be marked @safe ?

2021-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/1/21 8:26 PM, someone wrote: ... just wondering: I am writing pretty trivial code, nothing out of the ordinary, and attempted to check how much of it could be marked safe ... It should be quite a bit. - Lots of tiny common library functions are pretty easy - Getter/Setter properties

Re: Printing Tuple!(...)[] using for loop?

2021-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/2/21 12:21 AM, Kirill wrote: I have a `Tuple!(string, ..., string)[] data` that I would like to print out: `a   b   c` `1   2   3` `4   5   6`     Furthermore, I want to be able to print any N rows and M columns of that table. For instance:     `b   c`     `2   3`     or

Re: SegFault trying to chunk lazily joined ranges

2021-07-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/1/21 10:56 AM, Keivan Shah wrote: Using the handler I was able to get the stack trace and it seems that the segFault is caused by `joiner` trying to call `.save` on a null object leading to a `NullPointerError`. But I have not been able to debug it further. Mostly it seems that there is

Re: How to reset the website when the user leaves it, with vibe.d?

2021-06-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/29/21 4:25 PM, vnr wrote: Nevertheless, the problem persists and seems to be even deeper, indeed, my site is hosted on Heroku and I can see what a user who is on another machine has written (behavior I just found out). Fortunately, this little site is only for entertainment purposes, but

Re: Wrap + add methods?

2021-06-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/28/21 11:53 AM, Paul Backus wrote: On Monday, 28 June 2021 at 15:17:34 UTC, Steven Schveighoffer wrote: I have a situation where I want to wrap a certain type to add a few methods to that type. UFCS is not an option, because the library that will use this type will not import the UFCS

Wrap + add methods?

2021-06-28 Thread Steven Schveighoffer via Digitalmars-d-learn
I have a situation where I want to wrap a certain type to add a few methods to that type. UFCS is not an option, because the library that will use this type will not import the UFCS methods. `std.typecons.Proxy` doesn't seem to wrap static methods, and besides, I want to return wrappers if

Re: is it possible to sort a float range ?

2021-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/21 7:07 PM, someone wrote: On Wednesday, 23 June 2021 at 22:46:28 UTC, Steven Schveighoffer wrote: Use the `release` method: ```d return lnumRange.sort!(...).release; ``` Fantastic, issue solved, I previously used sort ascending even descending but first time on floats. So I

Re: Detect if a struct is a 3-float vector

2021-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/21 6:36 PM, JN wrote: I'm looking for a way to test a struct for these conditions: 1. has members named x, y and z 2. these members are floating point type This works, but feels kinda verbose, is there some shorter way? Can I somehow avoid the hasMember/getMember calls? ```d import

Re: is it possible to sort a float range ?

2021-06-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/23/21 6:30 PM, Jordan Wilson wrote: On Wednesday, 23 June 2021 at 19:53:24 UTC, someone wrote: Please, look for the line marked +++ This is a structure with a public property returning a (still unsorted) range built on-the-fly from already-set properties, a basic range from a to z with

Re: how to filter associative arrays with foreach ?

2021-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/21 5:00 PM, Elronnd wrote: On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: Is there a way to filter the collection at the foreach-level to avoid the inner if ? Here's how I would do it: foreach (k, v; coll) {     if (k == unwanted) continue;     ... } You still have an if,

Re: is there a way to: import something = app-xyz-classes-something; ?

2021-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/21 4:55 AM, frame wrote: On Monday, 21 June 2021 at 03:32:58 UTC, someone wrote: Since memory serves I use to name files with - instead of the more common _ The module name has to be strict and "-" is not allowed. However, you should be able to import files with a "-" in the name.

Re: do I incur a penality on compile time if I explicitly declare default behavior ?

2021-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/21 12:12 AM, someone wrote: I mean, coding as following: ```d int intWhatever = 0; /// default being zero anyway foreach (classComputer objComputer, objComputers) { ... } /// explicitly declaring the type instead of letting the compiler to figure it out struc Whatever {    public

Re: BetterC, int to string?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 9:46 AM, Steven Schveighoffer wrote: On 6/18/21 5:05 AM, Mike Brown wrote: Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? std.conv.to really should

Re: BetterC, int to string?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 5:05 AM, Mike Brown wrote: Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? std.conv.to really should support it, that seems like a bug. But just FYI,

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 12:40 AM, Mathias LANG wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. However, sometimes the data I'm switching on is coming from elsewhere (i.e. a

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 6:35 AM, Johan wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 5:54 PM, H. S. Teoh wrote: On Thu, Jun 17, 2021 at 05:41:28PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [.[..] Oh, and to throw a monkey wrench in here, the value is a string, not an integer. So I can't use std.conv.to to verify the enum is valid (plus, then I'm

semi-final switch?

2021-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash the

Re: Arrays of variants, C++ vs D

2021-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 5:01 PM, Ali Çehreli wrote: What's the difference? In both cases an int is being converted to a Foo. I think the "working" case is against the design of D. Likely there is a subtlety that I am missing... The difference might be that construction has only one set of overloads

Re: Vibe.d diet templates

2021-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 4:22 PM, kdevel wrote: On Thursday, 17 June 2021 at 19:14:28 UTC, Steven Schveighoffer wrote: On 6/17/21 12:26 PM, JG wrote: However, what I *have* wanted is to have attribute values support `Nullable!T` such that they are only included if the item is non-null. See

Re: Arrays of variants, C++ vs D

2021-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 4:15 PM, H. S. Teoh wrote: On Thu, Jun 17, 2021 at 07:44:31PM +, JN via Digitalmars-d-learn wrote: [...] Foo[int] foos = [ 0: Foo("abc"), 1: Foo(5) ]; } ``` Why does D need the explicit declarations whereas C++ can infer it? Because D does not

Re: Vibe.d diet templates

2021-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 12:26 PM, 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? I haven't found a need for it, as I'm usually only dynamically configuring attribute values, not attribute names. But my web-fu is

Re: In general, who should do more work: popFront or front?

2021-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/21 12:24 AM, surlymoor wrote: All my custom range types perform all their meaningful work in their respective popFront methods, in addition to its expected source data iteration duties. The reason I do this is because I swear I read in a github discussion that front is expected to be

Re: Dynamically allocated Array mutable but non resizeable

2021-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/21 11:09 AM, Jalil David Salamé Messina wrote: I'm searching for a way to do something like this in D: ```cpp struct MyStruct {   const size_t length;   int *const data;   MyStruct(size_t n) : length(n) {     data = new int[length];   } } ``` This way it is mutable, but non

Re: dub build output redirect

2021-06-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/8/21 10:05 AM, seany wrote: Hi Thank you for pointing this out. Indeed, much later in the code, there is a `readln()`. But, the program needs to run 1-2 minutes, until it reaches that point - it is doing a complex AI calculation. However, for these 1-2 minutes, there is no output. Not

Re: dub build output redirect

2021-06-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/8/21 8:38 AM, seany wrote: I have compiled a complex project via `dub build`. I used both `-b release` and `-b debug`. But i cant redirect the output (generated by `writeln`) to a file. I call by : `./executable --param p1 > a`. But execution hangs immediately. If I do `./executable

Re: Schroedinger's Ranges

2021-06-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/3/21 9:00 AM, kdevel wrote: a) What is the rationale behind not making byLineCopy the default? byLine was the original implementation. byLineCopy was added later after the need for it became apparent. See: https://forum.dlang.org/post/lg4l7s$11rl$1...@digitalmars.com THX. BTW

Re: How to compile Phobos with other D code to create a shared library?

2021-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/1/21 2:18 PM, data pulverizer wrote: Doing `Runtime.initialize` is working with Julia but not yet R, I'm getting a clock/GLIBC error ``` Error in dyn.load("rbasic.so") :   unable to load shared object 'code/rbasic.so':   lib/x86_64-linux-gnu/librt.so.1: undefined symbol:

Re: cloning array

2021-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/21 11:32 AM, Sean wrote: Is this normal behavior of dup? if so, how can I get the behavior i am searching for? Thank you. Yes. `dup` is a shallow copy. To get the behavior you want: ```d auto deepdup(T)(T[] arr) { import std.algorithm, std.array; static if(is(T == U[], U))

Re: How to compile Phobos with other D code to create a shared library?

2021-06-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/31/21 5:46 PM, data pulverizer wrote: On Monday, 31 May 2021 at 21:26:15 UTC, Steven Schveighoffer wrote: You need to call it wherever you think it might not have been called yet. It's reentrant, so if you call it more than once, it will only initialize once, and count how many times

Re: How to compile Phobos with other D code to create a shared library?

2021-05-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/31/21 5:20 PM, data pulverizer wrote: On Monday, 31 May 2021 at 21:01:19 UTC, Steven Schveighoffer wrote: ticksPerSecond is initialized in the runtime just before static constructors are run. See

Re: How to compile Phobos with other D code to create a shared library?

2021-05-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/31/21 4:41 PM, data pulverizer wrote: On Monday, 31 May 2021 at 20:32:11 UTC, kinke wrote: On Monday, 31 May 2021 at 19:21:52 UTC, data pulverizer wrote: ldc2 jbasic.d -O3 -link-defaultlib-shared --betterC --boundscheck=off -nogc -shared -of=jbasic.so The problem is almost certainly

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/31/21 12:50 PM, Christian Köstlin wrote: On 2021-05-31 13:40, CandG wrote: On Thursday, 27 May 2021 at 14:44:29 UTC, Steven Schveighoffer wrote: On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum

Re: How long does the context of a delegate exist?

2021-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/21 4:46 PM, IGotD- wrote: On Thursday, 27 May 2021 at 18:13:17 UTC, Adam D. Ruppe wrote: If the delegate is created by the GC and stored it will still be managed by the GC, along with its captured vars. As long as the GC can see the delegate in your example you should be OK. But if

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum :/ It's not possible currently. I keep posting all my thunderbird posts *as if* the forum will highlight them in the hopes that some day it will

Re: DUB doesn't seem to respect my config, am I doing something wrong?

2021-05-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/23/21 3:17 AM, rempas wrote: On Sunday, 23 May 2021 at 04:56:18 UTC, Mike Parker wrote: I just looked in the dub documentation for "build" and "compiler" entries, which I had never heard of, and I see none now. As Jordan said, those have always been configured on the command line. Did you

Re: property functions

2021-05-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/16/21 11:47 AM, Adam D. Ruppe wrote: On Sunday, 16 May 2021 at 15:12:25 UTC, Nick wrote: Is this warning still valid? The @property thing doesn't do much. All it does is change typeof(a.prop) from function over to the return value of the function. (Which actually makes it required for

Re: dual-context deprecation

2021-05-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/17/21 9:47 AM, jmh530 wrote: The code below (simplified from my actual problem) generates a warning that member function b "requires a dual-context, which is deprecated". However when I look at the list of deprecated features [1], I'm not seeing which one this is referring to. Is it a

Re: stack out of scope ?

2021-05-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/16/21 12:32 PM, Alain De Vos wrote: Why doesn't this program dups core ? Is s not recycled ? ``` import std.stdio:writeln; void main(){ //I point to the heap int[] p=[1,2,3]; {     int[3]s=[1,2,3];     //I point to the stack     p=s; } //Why do I still live ?

Re: how do I implement opSlice for retro range?

2021-05-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/21 11:49 PM, Jack wrote: How can I implement ranges in the retro range? I'd like to do this without allocate a new array with .array from std.array, can I do that? use like this: ```d     auto arr = [1, 2, 3, 4, 5];     auto a = new A!int(arr);     auto b = a.retro[0 .. 2]; // 4, 5

Re: ref struct member function

2021-05-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/21 3:21 PM, PinDPlugga wrote: This works but issues a deprecation warning: ``` onlineapp.d(30): Deprecation: returning `this` escapes a reference to parameter `this` onlineapp.d(30):    perhaps annotate the parameter with `return` Fraction(1, 3) ``` I found several other ways to

Re: cannot I override and mark it as private?

2021-05-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/12/21 5:55 PM, Basile B. wrote: On Wednesday, 12 May 2021 at 19:35:31 UTC, Jack wrote: I'd to change the visibility of a method overrided from public to private but it doesn't work tho to protected it does. Why is that? ... Why is that? why must I leave it accessible somehow (even if it's

Re: Understanding RefCounted

2021-05-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/12/21 1:16 PM, JG wrote: 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

Re: Understanding RefCounted

2021-05-12 Thread Steven Schveighoffer via Digitalmars-d-learn
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 the call something to do with front? ``` private struct

Re: Should this always work?

2021-05-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/4/21 6:03 AM, Ola Fosheim Grøstad wrote: On Tuesday, 4 May 2021 at 01:20:15 UTC, Q. Schroll wrote: On Saturday, 1 May 2021 at 06:17:36 UTC, Mike Parker wrote: On Saturday, 1 May 2021 at 04:55:10 UTC, frame wrote: I always thought as long as an object implements an interface, it should be

Re: Should this always work?

2021-05-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/4/21 9:21 AM, Paul Backus wrote: On Tuesday, 4 May 2021 at 10:21:42 UTC, Ola Fosheim Grøstad wrote: On Saturday, 1 May 2021 at 16:06:05 UTC, Steven Schveighoffer wrote: An interface cast involves a thunk (constant pointer adjustment) to get to the interface/object Yes, but it isn't a

Re: Since dmd 2.096.0: import `x.t` is used as a type

2021-05-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/3/21 11:04 AM, jmh530 wrote: On Sunday, 2 May 2021 at 18:36:25 UTC, Basile B. wrote: [snip] BTW during the PR review the problem you encounter [was anticipated](https://github.com/dlang/dmd/pull/12178#issuecomment-773886263) si I guess you're stuck with [the author

Re: Since dmd 2.096.0: import `x.t` is used as a type

2021-05-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/2/21 4:32 PM, kdevel wrote: On Sunday, 2 May 2021 at 18:36:25 UTC, Basile B. wrote: [...] BTW during the PR review the problem you encounter [was anticipated](https://github.com/dlang/dmd/pull/12178#issuecomment-773886263) si I guess you're stuck with [the author

Re: Should this always work?

2021-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/21 12:55 AM, frame wrote: I always thought as long as an object implements an interface, it should be able to cast it from a void* if it really points to a supporting object. I have the similar structure: ```d interface AI {    string doSomething(); } template S() {    void foo() {

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/30/21 9:24 AM, Meta wrote: On Friday, 30 April 2021 at 13:05:00 UTC, Steven Schveighoffer wrote: On 4/29/21 1:50 PM, Meta wrote: The reason for this, apparently, is in the definition of `ifThrown`: ``` CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1

Re: write once type?

2021-04-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/30/21 9:24 AM, sighoya wrote: On Friday, 30 April 2021 at 01:30:54 UTC, Steven Schveighoffer wrote: In my case, for value of a certain type in the loop, I was storing a specific field from the first one I found, and then verifying that all the other values of that type (not exactly the

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/29/21 1:50 PM, Meta wrote: The reason for this, apparently, is in the definition of `ifThrown`: ``` CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, lazy scope T2 errorHandler) nothrow ``` It's not marked as `nothrow` in the function's

Re: write once type?

2021-04-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/29/21 5:31 PM, sighoya wrote: On Tuesday, 20 April 2021 at 19:56:33 UTC, Steven Schveighoffer wrote: Not only that, but I may also want to keep processing the loop and do something different if the value has already been set instead of returning immediately, which necessitates a second

Re: vibe-core sporadic internal errors

2021-04-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/27/21 11:48 AM, Steven Schveighoffer wrote: I suspect vibe-core or event core may have some subtle bugs in them that are not easily repeatable, but often result in half-rendered web pages. Has anyone else seen this? I recently updated to the latest vibe-core and vibe to see if the

vibe-core sporadic internal errors

2021-04-27 Thread Steven Schveighoffer via Digitalmars-d-learn
I suspect vibe-core or event core may have some subtle bugs in them that are not easily repeatable, but often result in half-rendered web pages. Has anyone else seen this? I recently updated to the latest vibe-core and vibe to see if the problem goes away and it doesn't. A log of the

Re: When should I use SortedRange.release?

2021-04-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/23/21 1:35 PM, Bastiaan Veelo wrote: For reference, `SortedRange.release` is [documented](https://dlang.org/phobos/std_range.html#.SortedRange) as such: "Releases the controlled range and returns it." Wow thanks! I love functions that are named exactly as what they do ;-) Seriously

Re: CTFE Assignment to anonymous union shows unexpected behavior

2021-04-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/22/21 6:47 PM, Rekel wrote: I'm not sure why this is happening, but after simplifying my code I traced it back to what the title may suggest. The original cause of my issues being summarized by debug print statements returning a union as: Mat([nanf, nanF, . . . .], [[1.0F, 0.0F, . . . .])

Re: Dlang equivalent of #define/#ifdef : not... version

2021-04-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/21/21 2:38 AM, Dukc wrote: On Tuesday, 20 April 2021 at 23:58:46 UTC, Steven Schveighoffer wrote: static if(i_am_a_feature) {    ... } This would be correct if `i_am_a_feature` would be always defined, just set to `false` if not existent. But I think the idea was to not define the symbol

Re: Dlang equivalent of #define/#ifdef : not... version

2021-04-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/20/21 2:57 PM, ichneumwn wrote: Hi, Trying to convert a C header to D. The underlying package exists in different versions and may or may not expose certain functionality (modules/extensions). One should check at compile time that the header provides the relevant definitions, through

Re: write once type?

2021-04-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/20/21 3:56 PM, Steven Schveighoffer wrote: I have had the need in some cases to *maybe* set a const value inside a loop. One can sometimes abstract this into a lambda function, but sometimes this is not possible (e.g. if the loop is static). Not only that, but I may also want to keep

write once type?

2021-04-20 Thread Steven Schveighoffer via Digitalmars-d-learn
I have had the need in some cases to *maybe* set a const value inside a loop. One can sometimes abstract this into a lambda function, but sometimes this is not possible (e.g. if the loop is static). Not only that, but I may also want to keep processing the loop and do something different if

Re: How do I create classes dynamically?

2021-04-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/14/21 4:38 PM, Mario wrote: Maybe I am just too short in D, but I wanted to find out if it is possible to create classes dynamically. My problem is, I just don't know where to start reading. Maybe at mixin templates? CreateClassWithName!("MyDynamicClassName"); should create the

Re: How to allow +=, -=, etc operators and keep encapsulation?

2021-04-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/12/21 2:16 PM, Jack wrote: Give this class: ```d class A { int X() { return x; } int X(int v) { return x = v;} private int x; } ``` I'd like to allow use ```+=```, ```-=``` operators on ```X()``` and keep encapsulation. What's a somehow elegant way to do that? It's

Re: Range Error

2021-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/11/21 4:41 PM, Bastiaan Veelo wrote: On Sunday, 11 April 2021 at 19:45:30 UTC, Ruby The Roobster wrote: What am I doing wrong here? Is it the 'for' loop? Yes, there is a `7` where there should be an `i` on this line: ```d   for(int i=7;7>=0;i--) ``` This will go on forever, so you get a

Re: Need for speed

2021-04-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/21 3:44 PM, ag0aep6g wrote: On 01.04.21 21:36, Steven Schveighoffer wrote: On 4/1/21 3:27 PM, ag0aep6g wrote: On 01.04.21 21:00, Berni44 wrote: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` [...] Yes, but you can recommend

Re: Need for speed

2021-04-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/21 3:27 PM, ag0aep6g wrote: On 01.04.21 21:00, Berni44 wrote: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` Please don't recommend `-boundscheck=off` to newbies. It's not just an optimization. It breaks @safe. If you want

Re: Asking about performance of std concatenation vs. Appender vs. custom class

2021-04-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/21 10:53 AM, ludo wrote: The results are below (you can also git clone the repo + dub test): | Concatenation method | benchmark in ms| |-|-| |with std:    | 385 ms| |with stdReserve: | 327 ms| |with stdLength:  | 29 ms| |with

Re: why use string for this example of appender?

2021-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/21 5:32 PM, ludo wrote: Hi guys, I am working on an old software in D1, which defines at some point an array.d module. See my github file: https://tinyurl.com/5ffbmfvz If you go line 347, you see an ArrayBuilder struct, which is supposed to behave exactly like an array but with

Re: Static array initialisation

2021-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/21 2:03 PM, DLearner wrote: On Wednesday, 31 March 2021 at 18:00:32 UTC, Steven Schveighoffer wrote: The answer is no, the compiler does not write to memory beyond the 100 elements. That memory *might* happen to have an 8 in there. That's not proof of anything though. I entirely

Re: Static array initialisation

2021-03-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/31/21 1:54 PM, DLearner wrote: On Wednesday, 31 March 2021 at 17:46:25 UTC, Imperatorn wrote: On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote: Hi I did:    immutable uint  MemSize=100;  // Memory size in bytes. // Memory Pool    ubyte[MemSize]  MemPool = 8; And had a look

Re: How to parse JSON in D?

2021-03-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/21 3:05 AM, Imperatorn wrote: On Monday, 29 March 2021 at 18:19:35 UTC, Steven Schveighoffer wrote: On 3/29/21 1:48 PM, Imperatorn wrote: On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote: [...] https://youtu.be/un-bZdyumog?t=27m25s FYI that package is here:

Re: How to parse JSON in D?

2021-03-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/29/21 1:48 PM, Imperatorn wrote: On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote: We need to parse a bunch of JSON files. What does D have? It has std.json which is strangely slower than Python json :( Ok, we go to dub repository and search for something that is faster.

Re: Implicit conversion of unique chars[] to string

2021-03-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/22/21 5:58 PM, ag0aep6g wrote: On 22.03.21 21:38, Per Nordlöw wrote: Am I the only one being annoyed by the fact that chainPath(...).array doesn't implicit convert to string despite the array returned from .array is allocated by the GC. Works for me: import std.array:

Re: Strange error

2021-03-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/21/21 3:18 AM, Jack Applegame wrote: Could someone please explain what is wrong with this code? https://glot.io/snippets/fwxn2198kv ```d import std.stdio; struct Sample{   void function() func1;   void function() func2; } void noth(Sample smpl)() {   smpl.func1(); // Error:

Re: How do I check if this field is of this template struct?

2021-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/19/21 12:41 PM, Jack wrote: On Friday, 19 March 2021 at 08:54:50 UTC, Paul Backus wrote: On Friday, 19 March 2021 at 07:14:46 UTC, Jack wrote: give below template struct, how can I list the members x, y and z? I've tried something with OriginalType and TemplateOf but no luck... it seems

Re: How to delete dynamic array ?

2021-03-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/17/21 12:06 PM, jmh530 wrote: On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: On Wednesday, 17 March 2021 at 10:54:10 UTC, jmh530 wrote: This is one of those things that is not explained well enough. Yes. I made this article to clear up that point:

  1   2   3   4   5   6   7   8   9   10   >