Re: array setting : Whats going in here?

2023-10-09 Thread Imperatorn via Digitalmars-d-learn
On Monday, 9 October 2023 at 02:19:20 UTC, Jonathan M Davis wrote: On Sunday, October 8, 2023 8:08:46 AM MDT Imperatorn via Digitalmars-d-learn wrote: [...] Except that in those examples, they _do_ match. It's perfectly valid to copy elements of a string to a char[]. It's just copying immuta

Re: Type constraint

2023-10-09 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 8 October 2023 at 10:09:02 UTC, IchorDev wrote: On Wednesday, 4 October 2023 at 01:46:42 UTC, Joel wrote: I think the if without static is still static, since it's part of the function name part, or so (outside of the curly bracket scope). You can't have regular if-statements insid

Re: Type constraint

2023-10-09 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 3 October 2023 at 14:35:31 UTC, Joel wrote: Oh, I found, ```d static if (isIntegral!T) ``` seems to work. If you are using a struct, another way to affect the whole is as follows: ```d struct S(T) {  invariant() {      static assert(isIntegral!T); }  auto addUp() { /**/ }

How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread rempas via Digitalmars-d-learn
Let's see the following example: ```d import std.stdio; static foreach(i; 0 .. 10) { mixin(create_fn!(i.stringof)); } enum create_fn(string num) = ` void function_`~ num ~`() { writeln("Hello from function `~ num ~`!"); } `; void main() { function10(); } ``` I'm trying to create a ser

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread mw via Digitalmars-d-learn
use: import std.conv; ... i.to!string ... ``` import std.stdio; import std.conv; static foreach(i; 0 .. 10) { mixin(create_fn!(i.to!string)); } enum create_fn(string num) = ` void function_`~ num ~`() { writeln("Hello from function `~ num ~`!"); } `; void main() { function_9(); }

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread rempas via Digitalmars-d-learn
On Monday, 9 October 2023 at 16:42:38 UTC, mw wrote: use: import std.conv; [...] Damn, sorry, forgot to mention. I cannot use Phobos.

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread mw via Digitalmars-d-learn
On Monday, 9 October 2023 at 16:51:31 UTC, rempas wrote: On Monday, 9 October 2023 at 16:42:38 UTC, mw wrote: use: import std.conv; [...] Damn, sorry, forgot to mention. I cannot use Phobos. but you `import std.stdio;`? Or copy the std/conv.d over to your build, or copy / write a toStrin

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread rempas via Digitalmars-d-learn
On Monday, 9 October 2023 at 16:53:55 UTC, mw wrote: but you `import std.stdio;`? Or copy the std/conv.d over to your build, or copy / write a toString(int) function yourself, which is compile-time callable. I do on that example just to use "write". It wouldn't be necessary, but I just inc

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread Imperatorn via Digitalmars-d-learn
On Monday, 9 October 2023 at 16:55:41 UTC, rempas wrote: On Monday, 9 October 2023 at 16:53:55 UTC, mw wrote: but you `import std.stdio;`? Or copy the std/conv.d over to your build, or copy / write a toString(int) function yourself, which is compile-time callable. I do on that example just

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 9, 2023 10:55:41 AM MDT rempas via Digitalmars-d-learn wrote: > On Monday, 9 October 2023 at 16:53:55 UTC, mw wrote: > > but you `import std.stdio;`? > > > > Or copy the std/conv.d over to your build, > > > > or copy / write a toString(int) function yourself, which is > > compil

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread rempas via Digitalmars-d-learn
On Monday, 9 October 2023 at 17:42:48 UTC, Imperatorn wrote: You could just add your own int to string I guess? That will be a good idea! I'll do it in the future if that is the case, as it's not important, and I want to finish my job. Thank you and have a great day!

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread rempas via Digitalmars-d-learn
On Monday, 9 October 2023 at 17:52:58 UTC, Jonathan M Davis wrote: The closest to a built-in solution would be toString on classes and structs, but structs don't necessarily have a toString. Rather, in many cases, Phobos does introspection on the struct to figure out how to convert the struct

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 9 October 2023 at 16:33:32 UTC, rempas wrote: I'm trying to create a series of function. There will be ten of them, and they will be called `function_0`, `function_1`, etc. However, in my example, "stringof" returns the character "i" itself and turns that into a string instead of get

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread Imperatorn via Digitalmars-d-learn
On Monday, 9 October 2023 at 22:49:11 UTC, Salih Dincer wrote: On Monday, 9 October 2023 at 16:33:32 UTC, rempas wrote: I'm trying to create a series of function. There will be ten of them, and they will be called `function_0`, `function_1`, etc. However, in my example, "stringof" returns the c