Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-28 Thread monkyyy via Digitalmars-d-learn
On Saturday, 28 June 2025 at 15:20:44 UTC, WraithGlade wrote: D is a great language and well designed, but as I've been learning it I have noticed that nearly always when there is something I dislike about the language (which is relatively seldom) it is because some form of "best practice" or

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-28 Thread Lance Bachmeier via Digitalmars-d-learn
On Saturday, 28 June 2025 at 15:20:44 UTC, WraithGlade wrote: There are very few imposed structural "best practices" that are genuinely universal in my experience. Good naming of variables would be a rare example of a universally good practice, in my opinion, but in contrast even pervasive and

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-28 Thread WraithGlade via Digitalmars-d-learn
On Friday, 27 June 2025 at 20:08:31 UTC, Lance Bachmeier wrote: ... I think you're referring to [this description in the spec](https://dlang.org/spec/class.html#fields): The D compiler is free to rearrange the order of fields in a class to optimally pack them. Consider the fields much like

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, June 27, 2025 1:55:30 PM Mountain Daylight Time WraithGlade via Digitalmars-d-learn wrote: > Thanks for responding to my question and for your time, etc. > > I was aware of `align` but as far as I am aware it is orthogonal > to what I'm asking about. The Andrei book says that D > automa

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-27 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 27 June 2025 at 19:55:30 UTC, WraithGlade wrote: orthogonal to what I'm asking about. The Andrei book says that D automatically rearranges members of `class`s in memory to avoid wasting memory due to padding between members whose width is less than the native CPU word size alignment,

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-27 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 27 June 2025 at 19:55:30 UTC, WraithGlade wrote: Thanks for responding to my question and for your time, etc. I was aware of `align` but as far as I am aware it is orthogonal to what I'm asking about. The Andrei book says that D automatically rearranges members of `class`s in memory

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-27 Thread WraithGlade via Digitalmars-d-learn
Thanks for responding to my question and for your time, etc. I was aware of `align` but as far as I am aware it is orthogonal to what I'm asking about. The Andrei book says that D automatically rearranges members of `class`s in memory to avoid wasting memory due to padding between members whos

Re: Is there a way to tell D to rearrange struct members or to not rearrange class members?

2025-06-27 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 27 June 2025 at 11:23:56 UTC, WraithGlade wrote: I've read both of the available printed D books in their entirety (Ali's and Andrei's) and I noticed Andrei's book (circa ~2010) mentions that the D compiler rearranges the members of `class` objects to be more optimal by reducing ali

Re: Is there a way to Deferred binding symbol from dynamic library?

2024-11-29 Thread IchorDev via Digitalmars-d-learn
On Tuesday, 26 November 2024 at 10:34:07 UTC, Dakota wrote: On Saturday, 23 November 2024 at 12:09:22 UTC, IchorDev wrote: Why not load the libraries at runtime and look the pointers up with symbol names? Or do you really need the compiler to do it for you? Because I need link some part sta

Re: Is there a way to Deferred binding symbol from dynamic library?

2024-11-26 Thread Dakota via Digitalmars-d-learn
On Saturday, 23 November 2024 at 12:09:22 UTC, IchorDev wrote: Why not load the libraries at runtime and look the pointers up with symbol names? Or do you really need the compiler to do it for you? Thanks for suggestion. Because I need link some part static c library, they link global var

Re: Is there a way to Deferred binding symbol from dynamic library?

2024-11-24 Thread JermainOkuneva via Digitalmars-d-learn
You can use pragma(linkerDirective) to specify linker options directly within D code: pragma(linkerDirective, "-Wl,-undefined,dynamic_lookup"); For more information, please visit [geometry dash scratch](https://geometry-dashscratch.com) for more details.

Re: Is there a way to Deferred binding symbol from dynamic library?

2024-11-23 Thread IchorDev via Digitalmars-d-learn
On Friday, 22 November 2024 at 06:13:26 UTC, Dakota wrote: Try build a dynamic library, a lot function symbol and global symbol need to be deferred binding from runtime app. Why not load the libraries at runtime and look the pointers up with symbol names? Or do you really need the compiler to

Re: Is there a way to make a struct without a distinction between constant, immutable, and mutable?

2024-11-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 18 November 2024 at 23:43:46 UTC, Liam McGillivray wrote: Is there a way to make it so that this struct has only one qualifier? No distinction? Can you give an example of a problem and list the error messages? -Steve

Re: Is there a way to make a struct without a distinction between constant, immutable, and mutable?

2024-11-19 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 18 November 2024 at 23:43:46 UTC, Liam McGillivray wrote: I am doing work on the `units-d` library. This library contains some struct templates which don't contain any variables. Because of this, all instances are effectively constant. However, when they are placed as arguments in ot

Re: Is there a way to tell LDC2 to only check the syntax of the source file?

2023-12-06 Thread realhet via Digitalmars-d-learn
On Wednesday, 6 December 2023 at 11:53:09 UTC, realhet wrote: Hello, I've found another trick: - prepend "version(none):" in front of the source. - ignore the optional "Error: declaration expected, not `module`" message - Take seriously all the other errors, those are only syntax errors, se

Re: is there a way to use sumtype in `switch/case` (with multiple statements)? or how can I get the `tag` and `storage`?

2023-10-07 Thread mw via Digitalmars-d-learn
On Saturday, 7 October 2023 at 19:30:23 UTC, mw wrote: On Saturday, 7 October 2023 at 19:25:51 UTC, mw wrote: Or how can I get the `tag` and `storage` myself? https://github.com/dlang/phobos/blob/a3f22129dd2a134338ca02b79ff0de242d7f016e/std/sumtype.d#L310 If I add this line to the above func

Re: is there a way to use sumtype in `switch/case` (with multiple statements)? or how can I get the `tag` and `storage`?

2023-10-07 Thread mw via Digitalmars-d-learn
On Saturday, 7 October 2023 at 19:25:51 UTC, mw wrote: Or how can I get the `tag` and `storage` myself? https://github.com/dlang/phobos/blob/a3f22129dd2a134338ca02b79ff0de242d7f016e/std/sumtype.d#L310 If I add this line to the above func `isF`: ``` writeln(t.tag); ``` it won't compile: s

Re: Is there a way to get the name of the current function?

2023-03-07 Thread rempas via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:28:41 UTC, ryuukk_ wrote: ``` import std.stdio; void main() { writeln("file:", __FILE__); writeln("function is: ", __FUNCTION__); writeln("function is: ", __PRETTY_FUNCTION__ ); } $ dmd -run tester.d file:tester.d function is: tester.m

Re: Is there a way to get the name of the current function?

2023-03-07 Thread rempas via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:19:22 UTC, JG wrote: Yes, see here: https://dlang.org/spec/expression.html#specialkeywords OMG, so that's when they are located! I was trying to search the spec and find them in different pages but had no luck! Thanks a lot for the help, have a great day!

Re: Is there a way to get the name of the current function?

2023-03-07 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:11:49 UTC, rempas wrote: For example, in the given code: ```d void my_function() { import std.stdio; writeln("The name of the function is: ", ); } ``` Is there something to put in the place of `` to get the name of the function? ``` import std.stdio; vo

Re: Is there a way to get the name of the current function?

2023-03-07 Thread JG via Digitalmars-d-learn
On Tuesday, 7 March 2023 at 22:11:49 UTC, rempas wrote: For example, in the given code: ```d void my_function() { import std.stdio; writeln("The name of the function is: ", ); } ``` Is there something to put in the place of `` to get the name of the function? Yes, see here: https://d

Re: Is there a way to get a template’s parameters and constraints?

2023-01-22 Thread Adam Ross Walker via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? Apologies, I missed the key part of your question. But I think the above can be adapted if you were so inclined.

Re: Is there a way to get a template’s parameters and constraints?

2023-01-22 Thread Adam Ross Walker via Digitalmars-d-learn
There is a way but it's horrible. You can take the `.stringof` and parse the result. I knocked this up for something but it's not well tested and there are probably templates that it handles incorrectly. I'm not claiming this is any good, I just happened to have it. ```d enum TemplateParam

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: For what I want, `constraintsOf` may expect every template parameter to be a type and to have a constraint. If I'm not mistaken, the following will help: https://dlang.org/phobos/std_range_primitives.html SDB@79=

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 20 January 2023 at 17:15:31 UTC, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? No, reflection over templates is very limited.

Re: Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/20/23 12:15 PM, Quirin Schroll wrote: Is there a trait (or a combination of traits) that gives me the constraints of a template? Example: ```D void f(T1 : long, T2 : const(char)[])(T x) { } template constraintsOf(alias templ) { /*Magic here*/ } alias constraints = constraintsOf!f; // tuple

Re: Is there a way to enforce UFCS?

2023-01-06 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 6 January 2023 at 15:31:09 UTC, Salih Dincer wrote: If you don't want to get the above output you should use the previous example. But don't forget to connect alias and opCall. For example, you can use @property in version 2.0.83 without all the fanfare. I forgot one thing: if yo

Re: Is there a way to enforce UFCS?

2023-01-06 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 5 January 2023 at 23:05:17 UTC, thebluepandabear wrote: them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though. In older versions, it worked when printing values ​​with writeln. But

Re: Is there a way to enforce UFCS?

2023-01-05 Thread thebluepandabear via Digitalmars-d-learn
them or remove them. I agree, forbidding function call syntax would be a great usecase for `@property`. It will probably never get implemented though.

Re: Is there a way to enforce UFCS?

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 02:32:17PM +, Dom DiSc via Digitalmars-d-learn wrote: [...] > I think this is really another usecase for @property: we should forbid the > function call syntax for them (so one needs to use them like a variable). [...] > Properties are not functions. If you want a funct

Re: Is there a way to enforce UFCS?

2023-01-05 Thread Dom DiSc via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: ```d class Foo { int bar; void setBar(Foo foo, int value) { foo.bar = value; } } void main() { foo.setBar(100); // Not UFCS - just method call to the class foo.setBar = 100; // Not UFCS - simply a setter function call (eq

Re: Is there a way to enforce UFCS?

2023-01-04 Thread thebluepandabear via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 14:21:46 UTC, bauss wrote: On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo,

Re: Is there a way to enforce UFCS?

2023-01-04 Thread bauss via Digitalmars-d-learn
On Wednesday, 4 January 2023 at 03:42:28 UTC, thebluepandabear wrote: ... My question is: is there a way to enforce UFCS-syntax? None of your code actually uses UFCS. This is UFCS: ``` class Foo { int bar; } void setBar(Foo foo, int value) { foo.bar = value; } void main() { foo.setBa

Re: Is there a way to enforce UFCS?

2023-01-03 Thread Ali Çehreli via Digitalmars-d-learn
On 1/3/23 19:42, thebluepandabear wrote: > @property { As your post proves, that feature is at most half-baked and is discouraged. Today, there is just one known obscure effect of using it. > void name(string name) { > _name = name; > } > d.name = "Po

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread rikki cattermole via Digitalmars-d-learn
On 28/09/2022 7:18 AM, Alain De Vos wrote: Don't forget there is also BSD Should already be supported. Platform specific settings are supported through the use of field name suffixes. Suffixes are dash separated list of operating system/architecture/compiler identifiers, as defined in the D

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Alain De Vos via Digitalmars-d-learn
Don't forget there is also BSD

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread rikki cattermole via Digitalmars-d-learn
Alternatively we could just extend platforms to work in places other than configurations. https://dub.pm/package-format-json.html#configuration-settings

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/26/22 4:57 PM, Christian Köstlin wrote: Or posix only? Or not windows? Kind regards, Christian We have specific directives based on os, I had an idea that you could say something like: ```json "dependencies-windows": { "not-available" : "*" } ``` But it still tries to find this pa

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Christian Köstlin via Digitalmars-d-learn
On 27.09.22 13:07, Ahmet Sait wrote: On Monday, 26 September 2022 at 20:57:06 UTC, Christian Köstlin wrote: Or posix only? Or not windows? Kind regards, Christian Not necessarily a dub solution but you can do something like this: ```d version(Posix) { } else     static assert(0, "Unsupported

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Ahmet Sait via Digitalmars-d-learn
On Monday, 26 September 2022 at 20:57:06 UTC, Christian Köstlin wrote: Or posix only? Or not windows? Kind regards, Christian Not necessarily a dub solution but you can do something like this: ```d version(Posix) { } else static assert(0, "Unsupported platform."); ``` This will result in a

Re: Is there a way to

2022-09-12 Thread Kyle Ingraham via Digitalmars-d-learn
On Sunday, 11 September 2022 at 00:56:39 UTC, Adam D Ruppe wrote: On Sunday, 11 September 2022 at 00:32:18 UTC, Kyle Ingraham wrote: I can't use default parameters because I want to be able to call the delegate with arguments extracted from a URL path at runtime Some kind of wrapper might not

Re: Is there a way to

2022-09-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 11 September 2022 at 00:32:18 UTC, Kyle Ingraham wrote: I can't use default parameters because I want to be able to call the delegate with arguments extracted from a URL path at runtime Some kind of wrapper might not only be your best option, it might be your only option. Your de

Re: Is there a way to

2022-09-10 Thread Kyle Ingraham via Digitalmars-d-learn
On Sunday, 11 September 2022 at 00:04:55 UTC, Adam D Ruppe wrote: On Saturday, 10 September 2022 at 23:37:30 UTC, Kyle Ingraham wrote: How can I write a type that is strict for the first two parameters but tolerant of any other parameter following those? That's not a type per se, but you can a

Re: Is there a way to

2022-09-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 10 September 2022 at 23:37:30 UTC, Kyle Ingraham wrote: How can I write a type that is strict for the first two parameters but tolerant of any other parameter following those? That's not a type per se, but you can assign wrapper at the assignment thing. Like your_delegate = (a,

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Tuesday, 22 February 2022 at 00:44:58 UTC, jmh530 wrote: On Tuesday, 22 February 2022 at 00:36:38 UTC, bachmeier wrote: [snip] Yes. std.random is another. I gave up out on the current one. Luckily I already had external libraries for that before I started using D. Have you tried mir.rand

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 22 February 2022 at 00:36:38 UTC, bachmeier wrote: [snip] Yes. std.random is another. I gave up out on the current one. Luckily I already had external libraries for that before I started using D. Have you tried mir.random?

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 22:58:17 UTC, Ali Çehreli wrote: On 2/21/22 09:34, bachmeier wrote: > I may have to look for an alternative > JSON library for D. std.json is not the most fun independent of this issue. std.json is a very good module. At work, we had to write additional code to c

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/22 14:58, Ali Çehreli wrote: > std.json is a very good module. Correction: std.json is NOT a very good module. Ali

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 15:13:52 UTC, Kagamin wrote: On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON lib

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/22 09:34, bachmeier wrote: > I may have to look for an alternative > JSON library for D. std.json is not the most fun independent of this issue. std.json is a very good module. At work, we had to write additional code to cover its defficiencies. Looking forward to versioning in Phob

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 17:50:56 UTC, bachmeier wrote: I looked at the source for `parseJSON` and I see references only to `JSONOptions.strictParsing` and `JSONOptions.specialFloatLiterals`. I may be missing something, but I don't see any option to iterating over every element and unes

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 17:32:23 UTC, bachmeier wrote: On Monday, 21 February 2022 at 04:02:23 UTC, Steven Schveighoffer wrote: On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ```d import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/f

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON library. Escaping slashes as a default is a huge mistake IMHO

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bachmeier via Digitalmars-d-learn
On Monday, 21 February 2022 at 04:02:23 UTC, Steven Schveighoffer wrote: On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ```d import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/file"}`, JSONOptions.doNotEscapeSlashes)); } ``` but the outp

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread Kagamin via Digitalmars-d-learn
On Monday, 21 February 2022 at 09:04:06 UTC, bauss wrote: Why are we even escaping them by default, it should be the other way around, that slashes are only escaped if you ask for it; that's how it literally is in almost every JSON library. Really? I always see escaped slashes in JSON, e.g. wi

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-21 Thread bauss via Digitalmars-d-learn
On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ``` import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/file"}`, JSONOptions.doNotEscapeSlashes)); } ``` but the output is ``` {"a":"path\/file"} ``` Is there a way to avoid the escaping of

Re: Is there a way to not escape slashes when parsing JSON?

2022-02-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 21 February 2022 at 03:42:55 UTC, bachmeier wrote: I tried this ```d import std.json, std.stdio; void main() { writeln(parseJSON(`{"a": "path/file"}`, JSONOptions.doNotEscapeSlashes)); } ``` but the output is ``` {"a":"path\/file"} ``` Is there a way to avoid the escaping of

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 17:20:59 UTC, max haughton wrote: This is handled by the compiler backend. The simplest way it can do this kind of optimization is by "inlining" the function. This is done by transplanting the function body into the place it's used. At this point the compiler

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread max haughton via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 16:51:47 UTC, rempas wrote: On Wednesday, 29 December 2021 at 16:27:22 UTC, max haughton wrote: Inlining + constant propagation. Fancier iterations on those exist too but 90% of the speedup will come from those since for it to matter they likely would've been u

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 16:27:22 UTC, max haughton wrote: Inlining + constant propagation. Fancier iterations on those exist too but 90% of the speedup will come from those since for it to matter they likely would've been used in first place. Sounds like black magic? So If I write th

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread max haughton via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 15:53:38 UTC, rempas wrote: On Wednesday, 29 December 2021 at 11:09:04 UTC, max haughton wrote: If the value is known at compile time the compiler can pretty easily do that for you unless you're really unlucky. How is this even possible? Inlining + constant

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 14:49:40 UTC, Steven Schveighoffer wrote: On 12/29/21 3:55 AM, rempas wrote: Thanks! That's cool but I don't want this to be this way. Or at least I want it to be able to take a default value so we don't have to get passed all the time. OK: ``` extern (C)

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 11:09:04 UTC, max haughton wrote: If the value is known at compile time the compiler can pretty easily do that for you unless you're really unlucky. How is this even possible?

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/29/21 3:56 AM, rempas wrote: On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton wrote: Why do you need this? What's wrong with a normal branch in this case. Runtime performance. I want the value to get checked at compile time and use "static if" with it Oof, just let the compi

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/29/21 3:55 AM, rempas wrote: Thanks! That's cool but I don't want this to be this way. Or at least I want it to be able to take a default value so we don't have to get passed all the time. OK: ``` extern (C) void main() {   void print_num(int mul = 100)(int num) {     static if (is(

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread max haughton via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 08:56:47 UTC, rempas wrote: On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton wrote: Why do you need this? What's wrong with a normal branch in this case. Runtime performance. I want the value to get checked at compile time and use "static if" with i

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 01:34:22 UTC, Stanislav Blinov wrote: One can also do this kind of stuff: ```d import core.stdc.stdio; struct Literal(alias val) { enum value = val; } enum lit(alias val) = Literal!val.init; void print_num(Arg)(int num, Arg mul) { static if (is(Arg =

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton wrote: Why do you need this? What's wrong with a normal branch in this case. Runtime performance. I want the value to get checked at compile time and use "static if" with it

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:06:50 UTC, Steven Schveighoffer wrote: On 12/28/21 4:19 PM, rempas wrote: Here: ``` extern (C) void main() {   void print_num(int mul)(int num) {     static if (is(mul == ten)) {   printf("%d\n", num * 10);     } else static if (is(mul == three)) {  

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:30:30 UTC, Ali Çehreli wrote: On 12/28/21 2:06 PM, Steven Schveighoffer wrote:    void print_num(int mul)(int num) { Wasn't there a way of telling whether an 'auto ref' parameter is copied or not? void print_num()(int num, auto ref int mul) { // ? } An

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Ali Çehreli via Digitalmars-d-learn
On 12/28/21 2:06 PM, Steven Schveighoffer wrote:    void print_num(int mul)(int num) { Wasn't there a way of telling whether an 'auto ref' parameter is copied or not? void print_num()(int num, auto ref int mul) { // ? } And that would indicate that the argument was an rvalue? I realize

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread max haughton via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 21:19:29 UTC, rempas wrote: I would like to know if that's possible. Actually I would like to do something like the following: ``` extern (C) void main() { void print_num(int num, comp_time_type int mul) { static if (is(mul == ten)) { printf("%d\n", n

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/28/21 4:19 PM, rempas wrote: Here: ``` extern (C) void main() {   void print_num(int mul)(int num) {     static if (is(mul == ten)) {   printf("%d\n", num * 10);     } else static if (is(mul == three)) {   printf("%d\n", num * 3);     } else {   printf("%d\n", num);   

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 21:19:29 UTC, rempas wrote: I would like to know if that's possible. Actually I would like to do something like the following: ``` extern (C) void main() { void print_num(int num, comp_time_type int mul) { static if (is(mul == ten)) { printf("%d\n", n

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-19 Thread someone via Digitalmars-d-learn
On Monday, 19 July 2021 at 03:52:51 UTC, SealabJaster wrote: On Monday, 19 July 2021 at 03:51:02 UTC, SealabJaster wrote: ... There's also Ali Cehreli's book, which is excellent. I stepped into D alongside Andrei and Ali's books. Ali's one I was aware it existed but I didn't start to read i

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread someone via Digitalmars-d-learn
On Monday, 19 July 2021 at 03:05:24 UTC, Paul Backus wrote: On Monday, 19 July 2021 at 01:45:27 UTC, SealabJaster wrote: On Monday, 19 July 2021 at 01:26:25 UTC, someone wrote: ... Not 100% sure this works in all cases, but this version doesn't need the caller to make use of a mixin: https:

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread SealabJaster via Digitalmars-d-learn
On Monday, 19 July 2021 at 03:51:02 UTC, SealabJaster wrote: ... There's also Ali Cehreli's book, which is excellent. e.g. here's the section on UDAs: http://ddili.org/ders/d.en/uda.html

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread SealabJaster via Digitalmars-d-learn
On Monday, 19 July 2021 at 01:56:21 UTC, someone wrote: ... Prepare yourself, as you may become a metaprogramming junkie in the near future. Throw in `static if`[0] `static foreach`[1] `string mixin()`[2] `CTFE`[3] and make some crazy, random, arcane mess of fun spaghetti. I've wrote two

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread SealabJaster via Digitalmars-d-learn
On Monday, 19 July 2021 at 03:05:24 UTC, Paul Backus wrote: ... Yea, that's true.

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread Paul Backus via Digitalmars-d-learn
On Monday, 19 July 2021 at 01:45:27 UTC, SealabJaster wrote: On Monday, 19 July 2021 at 01:26:25 UTC, someone wrote: ... Not 100% sure this works in all cases, but this version doesn't need the caller to make use of a mixin: https://run.dlang.io/is/3jLxLz If you only need to print variable

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread someone via Digitalmars-d-learn
On Monday, 19 July 2021 at 01:45:27 UTC, SealabJaster wrote: On Monday, 19 July 2021 at 01:26:25 UTC, someone wrote: ... Not 100% sure this works in all cases, but this version doesn't need the caller to make use of a mixin: https://run.dlang.io/is/3jLxLz http://dlang.org/traits.html ... h

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread SealabJaster via Digitalmars-d-learn
On Monday, 19 July 2021 at 01:26:25 UTC, someone wrote: ... Not 100% sure this works in all cases, but this version doesn't need the caller to make use of a mixin: https://run.dlang.io/is/3jLxLz

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread someone via Digitalmars-d-learn
On Monday, 19 July 2021 at 00:52:39 UTC, Paul Backus wrote: The closest you can get is to use a string mixin: ```d enum debugWriteln(string expression) = `writeln(q"(` ~ expression ~ `)", " = ", ` ~ expression ~ `);`; // Usage: mixin(debugWriteln!"lobjExchanges.count"); ``` clever :)

Re: is there a way to get the identifier (call it name) of what is being passed to a function ?

2021-07-18 Thread Paul Backus via Digitalmars-d-learn
On Monday, 19 July 2021 at 00:07:25 UTC, someone wrote: Every time I use it, of course, I have to double-type the tag and the value. I wonder if there's some mechanism to just type the following: ```d debugwriteln(lobjExchanges.count); ``` ... and some way to get the identifier of what's bei

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

2021-06-26 Thread someone via Digitalmars-d-learn
On Saturday, 26 June 2021 at 04:24:05 UTC, frame wrote: If you pass each file to the compiler like in your script then every naming convention becomes irrelevant because the compiler does not need to do a file system lookup anyway and a module "foo_bar" could be also in the file xyz.d. You p

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

2021-06-25 Thread frame via Digitalmars-d-learn
On Saturday, 26 June 2021 at 02:19:18 UTC, someone wrote: What I like most of it is that it scales well for big and complex apps while being really flexible ... and neat :) If you pass each file to the compiler like in your script then every naming convention becomes irrelevant because the co

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

2021-06-25 Thread someone via Digitalmars-d-learn
On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer wrote: That being said, I strongly recommend just to name the file the same as the module name. Although you made it clear that you do not favor this use-case I am really satisfied with your solution because, at least to me, has

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

2021-06-21 Thread someone via Digitalmars-d-learn
On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer wrote: It does work. However, you have to tell the compiler the file to compile. When an import is used, the compiler does 2 stages: 1. Search through already-seen modules, and see if one matches 2. Search the filesystem to find a

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

2021-06-21 Thread frame via Digitalmars-d-learn
On Monday, 21 June 2021 at 13:29:59 UTC, Steven Schveighoffer wrote: It does work. However, you have to tell the compiler the file to compile. Which completely ignores filenames if the compiler is satisified. You may assume by reading the manual that the compiler would make an automatic tra

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

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

2021-06-21 Thread frame via Digitalmars-d-learn
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. From the manual: If the file name

Re: is there a way to output formatted text following the locale settings ?

2021-05-28 Thread someone via Digitalmars-d-learn
On Saturday, 29 May 2021 at 02:59:43 UTC, Paul Backus wrote: D warns for format specifiers that do not conform to the C99 standard, and the `'` flag character is not part of C99. GCC gives a similar warning with `-Wall -pedantic`: Crystal clear !

Re: is there a way to output formatted text following the locale settings ?

2021-05-28 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 29 May 2021 at 02:26:57 UTC, someone wrote: ```d core.stdc.stdio.printf("%'d", intAmount); /// Deprecation: format specifier `"%'"` is invalid ... but it works: 1,234,567 as specified in my locale :) ``` D warns for format specifiers that do not conform to the C99 standard,

Re: is there a way to output formatted text following the locale settings ?

2021-05-28 Thread someone via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 00:40:30 UTC, Paul Backus wrote: In that case, you will want to use the C library functions from [`core.stdc.stdio`][1]. ```d import core.stdc.stdio; import core.stdc.locale; import std.stdio; void main ( ) { core.stdc.locale.setlocale(LC_ALL, ""); int in

Re: is there a way to output formatted text following the locale settings ?

2021-05-25 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 26 May 2021 at 00:18:29 UTC, someone wrote: Thanks for your reply, but no, let me clarify: I do not want 123\`456\`789 or whatever else custom delimiter. I just want to output what is already set in the LC_ALL locale environment variable which in my case results in 123,456,789

Re: is there a way to output formatted text following the locale settings ?

2021-05-25 Thread someone via Digitalmars-d-learn
On Tuesday, 25 May 2021 at 23:41:39 UTC, Paul Backus wrote: From [the documentation of `formattedWrite`][1]: Separator Inserts the separator symbols ',' every X digits, from right to left, into numeric values to increase readability. The fractional part of floating point values inserts t

Re: is there a way to output formatted text following the locale settings ?

2021-05-25 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 25 May 2021 at 22:37:25 UTC, someone wrote: writeln(format("%`d", intAmount)); /// please, note the backtick instead of , From [the documentation of `formattedWrite`][1]: Separator Inserts the separator symbols ',' every X digits, from right to left, into numeric values

Re: Is there a way to work with processes in Windows without extern(c)?

2021-01-13 Thread dog2002 via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 15:11:40 UTC, Dennis wrote: On Wednesday, 13 January 2021 at 14:04:52 UTC, dog2002 wrote: [...] I don't think this is part of the standard library. Here's a piece of code I wrote a while ago if that's useful: [...] Thank you so much!

Re: Is there a way to work with processes in Windows without extern(c)?

2021-01-13 Thread Dennis via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:04:52 UTC, dog2002 wrote: I could use extern(c) and Process Walking (Process32First, Process32Next), but maybe there is a way to get the list by means of D? I don't think this is part of the standard library. Here's a piece of code I wrote a while ago if tha

Re: Is there a way to force emitting of stack frame for a specific function?

2020-10-09 Thread Johan via Digitalmars-d-learn
On Friday, 9 October 2020 at 02:01:30 UTC, Andrey Zherikov wrote: The question: is it possible to tell compiler to always generate stack frame for my stackFrame function? "pragma(inline, false)" doesn't help here - the result is completely the same. (Do you mean a stack frame, or a frame poi

  1   2   3   4   >