Re: list system drives

2021-02-01 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 2 February 2021 at 07:18:02 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 2 February 2021 at 06:31:27 UTC, Виталий Фадеев wrote: Give, please, Dlang tools for list system drives. Some like a: enumVolumes(); // [ 'C:\', 'D:\' ] I have found this code by a google search. I don't know

Re: list system drives

2021-02-01 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Tuesday, 2 February 2021 at 06:31:27 UTC, Виталий Фадеев wrote: Give, please, Dlang tools for list system drives. Some like a: enumVolumes(); // [ 'C:\', 'D:\' ] I have found this code by a google search. I don't know who the author was. I had to touch it a little since the codebase wa

list system drives

2021-02-01 Thread Виталий Фадеев via Digitalmars-d-learn
Give, please, Dlang tools for list system drives. Some like a: enumVolumes(); // [ 'C:\', 'D:\' ]

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Q. Schroll via Digitalmars-d-learn
On Monday, 1 February 2021 at 11:39:26 UTC, Per Nordlöw wrote: On Monday, 1 February 2021 at 11:37:49 UTC, Per Nordlöw wrote: Ok, so then my follow-up question becomes, does the right hand sides of these two assignment share the same AST node? If not, why? Because such a shared AST node could

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Q. Schroll via Digitalmars-d-learn
On Monday, 1 February 2021 at 20:00:26 UTC, Q. Schroll wrote: On Monday, 1 February 2021 at 09:40:20 UTC, Per Nordlöw wrote: An enum only exists at compile-time, and does not occupy any space. Each time it's referenced, a new instance of the value is created. Why is that? Short answer: An enum

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Q. Schroll via Digitalmars-d-learn
On Monday, 1 February 2021 at 09:40:20 UTC, Per Nordlöw wrote: An enum only exists at compile-time, and does not occupy any space. Each time it's referenced, a new instance of the value is created. Why is that? Short answer: An enum is a literal you can refer to by name. That's my mind-model f

Re: Quick question

2021-02-01 Thread Ali Çehreli via Digitalmars-d-learn
While we're on topic, the size of a class type and a class variable both are constant on a platform, e.g. 8 bytes on 64 bit systems. To get the size of actual instances (objects) of this type, one needs to use the classInstanceSize trait: class C { int i; } void main() { auto a = new C();

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/21 11:31 AM, Per Nordlöw wrote: On Monday, 1 February 2021 at 16:30:31 UTC, Per Nordlöw wrote: Btw, does     x ~ y ~ z ~ ... result in a single allocation? Provided all the operands has a `length` property. As long as they are all arrays, yes, the compiler calls a single runtime ca

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 15:47:33 UTC, Steven Schveighoffer wrote: "Concatenation always creates a copy of its operands, even if one of the operands is a 0 length array" Btw, does x ~ y ~ z ~ ... result in a single allocation?

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 16:30:31 UTC, Per Nordlöw wrote: Btw, does x ~ y ~ z ~ ... result in a single allocation? Provided all the operands has a `length` property.

Re: Quick question

2021-02-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 February 2021 at 16:19:13 UTC, Ruby The Roobster wrote: Thanks. However for a char[], .sizeof = .length because a char is one byte. Nope, char[].sizeof is a platform-specific constant not related to the length at all. void main() { import std.stdio; char[] a = "t

Re: Quick question

2021-02-01 Thread Ruby The Roobster via Digitalmars-d-learn
On Saturday, 30 January 2021 at 01:57:53 UTC, Adam D. Ruppe wrote: On Saturday, 30 January 2021 at 00:58:09 UTC, Ruby The Roobster wrote: I have question here. Is there a difference between .sizeof and .length(of a char[])? for future reference if someone stumbles on this, .sizeof is the sta

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/21 7:17 AM, ag0aep6g wrote: On 31.01.21 22:48, Per Nordlöw wrote: Why isn't "Name " ~ name ~ " could not be found" implicitly convertible to `string`? If concatenation is guaranteed to allocate a new array, then it should be "strongly pure", and the conversion should work. I'm n

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/21 4:48 PM, Per Nordlöw wrote: Why isn't     "Name " ~ name ~ " could not be found" implicitly convertible to `string`? One of my oldest Enhancement requests: https://issues.dlang.org/show_bug.cgi?id=1654 -Steve

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread ag0aep6g via Digitalmars-d-learn
On 31.01.21 22:48, Per Nordlöw wrote: Why isn't     "Name " ~ name ~ " could not be found" implicitly convertible to `string`? If concatenation is guaranteed to allocate a new array, then it should be "strongly pure", and the conversion should work. I'm not sure if it is guaranteed to allo

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 10:27:29 UTC, Jacob Carlborg wrote: Why isn't "Name " ~ name ~ " could not be found" implicitly convertible to `string`? Because if you have arrays of reference types, it's possible to change an element of the mutable array, which will affect the immutable

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 10:24:59 UTC, Mike Parker wrote: There is no "extra" instance because there's no single instance of an enum value. They have no address. When you use one, it's just as if you were writing the literal instead of the enum name. In other words: enum ea = [1, 2, 3];

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 11:37:49 UTC, Per Nordlöw wrote: Ok, so then my follow-up question becomes, does the right hand sides of these two assignment share the same AST node? If not, why? Because such a shared AST node could be potentially mutated in different ways in different contexts

Re: Type of string literal concatenated with non-immutable char array

2021-02-01 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 31 January 2021 at 21:48:09 UTC, Per Nordlöw wrote: Given char x[]; why is typeof("a" ~ x) `char[]` when typeof("a" ~ x.idup) is `string`? My case is class NameLookupException : Exception { this(string name) { super("Name " ~ name ~ " could not be f

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Mike Parker via Digitalmars-d-learn
On Monday, 1 February 2021 at 10:08:21 UTC, Per Nordlöw wrote: Agreed. My question is why does an `enum` require an extra instance from a compiler architecture point of view? Do all compilers handle compile-time enum instances in that way? There is no "extra" instance because there's no singl

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 1 February 2021 at 09:52:07 UTC, Jacob Carlborg wrote: If you don't want a new instance, then don't use `enum`. Use `immutable` instead. Agreed. My question is why does an `enum` require an extra instance from a compiler architecture point of view? Do all compilers handle compile-t

Re: Why are multiple instances of the single enum created?

2021-02-01 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 1 February 2021 at 09:40:20 UTC, Per Nordlöw wrote: An enum only exists at compile-time, and does not occupy any space. Each time it's referenced, a new instance of the value is created. Why is that? Seems like a waste of resources to the compiler. It makes perfect sense for numeric

Why are multiple instances of the single enum created?

2021-02-01 Thread Per Nordlöw via Digitalmars-d-learn
An enum only exists at compile-time, and does not occupy any space. Each time it's referenced, a new instance of the value is created. Why is that? Seems like a waste of resources to the compiler.

Re: emplace doesn't forward aeguments

2021-02-01 Thread kinke via Digitalmars-d-learn
On Saturday, 30 January 2021 at 17:29:15 UTC, vitamin wrote: On Thursday, 28 January 2021 at 23:18:21 UTC, kinke wrote: On Thursday, 28 January 2021 at 21:15:49 UTC, vitamin wrote: Is there reason why std.conv.emplace doesn't forward arguments to __ctor? Yeah, a bug in the emplace() version f

Re: Using mir to work with matrices

2021-02-01 Thread drug via Digitalmars-d-learn
On 1/29/21 8:20 PM, 9il wrote: On Friday, 29 January 2021 at 15:35:49 UTC, drug wrote: Between is there a plan to implement some sort of static slice where the lengths of the dimensions are known in compile time? Compiler help is very useful. No. BLAS/LAPACK API's can't use compile-time infor