Thank you all for the info! I'll try to find another way to do it
as it is not possible
to match the exact behavior I want! Have a great day everyone!
Here is another one that uses nested templates:
import std.stdio;
template TestArray(ulong element_n) {
struct TestArrayImpl(Type) {
int[element_n] elements;
this(ulong number) {
pragma(msg, "The type is: ", Type);
writeln("Constructing with ", number);
}
}
auto
On 8/8/22 9:36 AM, Steven Schveighoffer wrote:
On 8/8/22 1:38 AM, rempas wrote:
In the following struct (as an example, not real code):
```
struct TestArray(ulong element_n) {
int[element_n] elements;
this(string type)(ulong number) {
pragma(msg, "The type is: " ~
On 8/8/22 1:38 AM, rempas wrote:
In the following struct (as an example, not real code):
```
struct TestArray(ulong element_n) {
int[element_n] elements;
this(string type)(ulong number) {
pragma(msg, "The type is: " ~ typeof(type).stringof);
}
}
```
I want to create it and be
On 8/7/22 22:38, rempas wrote:
> I want to create it and be able to successfully initialize the template
> parameters
> of the constructor but until now, I wasn't able to find a way to
> successfully do
> that.
The following method uses a convenience function but it's not really needed:
import
On Monday, 8 August 2022 at 05:38:31 UTC, rempas wrote:
In the following struct (as an example, not real code):
```
struct TestArray(ulong element_n) {
int[element_n] elements;
this(string type)(ulong number) {
pragma(msg, "The type is: " ~ typeof(type).stringof);
}
}
```
I want to
On Monday, 8 August 2022 at 12:26:50 UTC, rempas wrote:
On Monday, 8 August 2022 at 11:03:21 UTC, Dom Disc wrote:
You should first describe what you want to do clearly.
On Monday, 8 August 2022 at 11:03:21 UTC, Dom Disc wrote:
But if you only want to know the type of the parameter, you can
do this:
```D
struct TestArray(ulong element_n) {
int[element_n] elements;
this(type)(type number)
{
pragma(msg, "The type is: " ~ type.stringof);
}
}
```
On Monday, 8 August 2022 at 08:27:49 UTC, bauss wrote:
Yeah I think the only template argument you can have for
constructors are `this` which will refer to things like the
class that inherited the current class etc. not sure what else,
but you can't really pass anything to it yourself
And then you can instantiate it with
```D
auto val = TestArray!10(ubyte(60)); // if you want type to be
ubyte
```
On Monday, 8 August 2022 at 06:58:42 UTC, bauss wrote:
On Monday, 8 August 2022 at 05:38:31 UTC, rempas wrote:
In the following struct (as an example, not real code):
```
struct TestArray(ulong element_n) {
int[element_n] elements;
this(string type)(ulong number) {
pragma(msg, "The
On Monday, 8 August 2022 at 07:37:16 UTC, rempas wrote:
Thank you for all the great info! Unfortunately, while there is
no problem in this example, this will
not do for my real code as I need to have the argument in the
constructor. Alternative, I have to
change the design of the program
On Monday, 8 August 2022 at 06:58:42 UTC, bauss wrote:
```
this(string type)(ulong number) {
```
You cannot do this.
Instead your type should look like this:
First let's change it up a little bit.
```
struct TestArray(ulong element_n, string type) {
int[element_n] elements;
this(ulong
On Monday, 8 August 2022 at 05:38:31 UTC, rempas wrote:
In the following struct (as an example, not real code):
```
struct TestArray(ulong element_n) {
int[element_n] elements;
this(string type)(ulong number) {
pragma(msg, "The type is: " ~ typeof(type).stringof);
}
}
```
I want to
In the following struct (as an example, not real code):
```
struct TestArray(ulong element_n) {
int[element_n] elements;
this(string type)(ulong number) {
pragma(msg, "The type is: " ~ typeof(type).stringof);
}
}
```
I want to create it and be able to successfully initialize the
15 matches
Mail list logo