On 4/25/22 21:32, Salih Dincer wrote:
> So the problem is that the structure is not in the inter-module space
Nested structs carry an additional pointer to their containing context.
When they don't need the context, we define them with 'static':
void foo() {
static struct Bar { }
}
> If
So the problem is that the structure is not in the inter-module
space
On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote:
This works:
```d
import std;
void main() {
struct Foo { string s; }
Foo[] arr = ["abc", "def", "ghi"].map!Foo.array;
arr.writeln; // => [Foo("abc"),
On 4/25/22 19:37, Salih Dincer wrote:
> a lot of errors
Hm. I can't reproduce any of that. I did two things:
1) Added necessary import directives
2) Moved all expressions into the main() function
I did not change anything else. The program below compiles and works
with all these
On Tuesday, 26 April 2022 at 00:57:54 UTC, Ali Çehreli wrote:
On 4/25/22 16:59, Salih Dincer wrote:
> Because it cannot be used with other possibilities such as
> ```chunks()``` and ```take()```.
There must be something wrong. map is commonly used with
chunks(), take(), etc.
> Also it
On 4/25/22 14:32, cc wrote:
> Hard to word this question right, but is it possible to get the UDAs
> assigned to a class/structure's member variable declaration, within that
> variable's definition? e.g.
That sounds backwards to me too. :) Policy-based design can work here:
import std.stdio;
On 4/25/22 16:02, frame wrote:
> On Monday, 25 April 2022 at 02:07:50 UTC, Ali Çehreli wrote:
>> > import core.memory: GC;
>> GC.free(GC.addrOf(cast(void *)(i.ptr)));
>> That is wrong because you did not allocate that address yourself.
>
> Hmm? The GC did allocate here(?)
Yes. I still
On 4/25/22 16:59, Salih Dincer wrote:
> Because it cannot be used with other possibilities such as
> ```chunks()``` and ```take()```.
There must be something wrong. map is commonly used with chunks(),
take(), etc.
> Also it cannot be customized with
> ```toString()```.
Can you show examples
On Monday, 25 April 2022 at 23:41:47 UTC, Chris Katko wrote:
So to use a typedef'd struct... I have to basically add the
original type on top of the typedef'd type every time? Surely
it's not this clunky?
I mean, why even use a typedef then. Why not use just pair,
sPair, vPair, etc as
On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote:
```d
import std;
void main() {
struct Foo { string s; }
Foo[] arr = ["abc", "def", "ghi"].map!Foo.array;
arr.writeln; // => [Foo("abc"), Foo("def"), Foo("ghi")]
}
```
Thank you...
Very very nice and simple but not
On Monday, 25 April 2022 at 12:53:14 UTC, Mike Parker wrote:
On Monday, 25 April 2022 at 08:54:52 UTC, Chris Katko wrote:
D
struct pair
{
float x,y;
}
alias sPair = Typedef!pair; // pair of xy in screen space
coordinates
alias vPair = Typedef!pair; // pair of xy in viewport space
On Monday, 25 April 2022 at 02:07:50 UTC, Ali Çehreli wrote:
> import core.memory: GC;
GC.free(GC.addrOf(cast(void *)(i.ptr)));
That is wrong because you did not allocate that address
yourself.
Hmm? The GC did allocate here(?)
On 4/24/22 17:26, Salih Dincer wrote:
>
On Monday, 25 April 2022 at 15:23:12 UTC, Ali Çehreli wrote:
auto arr = iota(10).map!(i => Foo(i.text)).array;
On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote:
Foo[] arr = ["abc", "def", "ghi"].map!Foo.array;
Ahh that'll do it alright, thanks
Hard to word this question right, but is it possible to get the
UDAs assigned to a class/structure's member variable declaration,
within that variable's definition? e.g.
```d
import std.stdio;
import std.traits;
enum SPECIAL;
struct Foo {
void foo() {
static if
On 4/25/22 16:36, cc via Digitalmars-d-learn wrote:
```d
struct Foo {
string s;
this(string s) { this.s = s; }
}
Foo foo = "a";
Foo[] foos = ["a"]; // Error: cannot implicitly convert expression `["a"]` of type `string[]` to
`Foo[]`
Foo[] foos = cast(Foo[]) ["a"]; // Error: e2ir:
Indeed code below works,
```
import std.stdio: write,writeln;
class Node {
int data;
Node next;
}
class List {
Node node=null;
this(int[] AR){foreach(i ; AR)pushfront(i);}
void pushfront(int data) {
Node newnode=new Node();
On Monday, 25 April 2022 at 01:40:01 UTC, Alain De Vod wrote:
Following program is a single linked list.
We expect as output 1 2 3 1 2 3
But the output is only 1 2 3
```
If you don't need List to be treated as a true range, but just
want to iterate, a simple way to do this is with opApply:
On 4/25/22 07:36, cc wrote:
> ```d
> struct Foo {
> string s;
> this(string s) { this.s = s; }
> }
> Foo foo = "a";
I don't understand why that syntax exists. I always write it like this:
auto foo = Foo("a");
> Foo[] foos = ["a"]; // Error: cannot implicitly convert expression
>
On Monday, 25 April 2022 at 15:13:51 UTC, Stanislav Blinov wrote:
Make it explicit:
```d
Foo[] foos = [Foo("a")];
```
There's that too, but I still have to iterate manually. e.g.:
```d
string[] ss = loadABunchOfStringsFromSomewhere();
//Foo[] foos = ss; //error
Foo[] foos;
On 4/25/22 03:48, Salih Dincer wrote:
> It is also possible with the copy constructor of a struct. I don't know
> how to do with class...
Classes don't have language provided construction because nobody needs
it and in fact they have to protect themselves when a language provides
it. (See,
On Monday, 25 April 2022 at 14:36:25 UTC, cc wrote:
```d
struct Foo {
string s;
this(string s) { this.s = s; }
}
Foo foo = "a";
Foo[] foos = ["a"]; // Error: cannot implicitly convert
expression `["a"]` of type `string[]` to `Foo[]`
Foo[] foos = cast(Foo[]) ["a"]; // Error:
On Monday, 25 April 2022 at 15:00:13 UTC, Alain De Vos wrote:
Not really an answer but this works,
```
void main(){
Foo foo = "a";
Foo[] foos;
foos ~=foo;
}%
```
Right, I can append individual elements, but can't assign or
append a slice of a type that can be individually cast to the
struct.
Not really an answer but this works,
```
struct Foo {
string s;
this(string s) { this.s = s; }
}
void main(){
Foo foo = "a";
Foo[] foos;
foos ~=foo;
}%
```
```d
struct Foo {
string s;
this(string s) { this.s = s; }
}
Foo foo = "a";
Foo[] foos = ["a"]; // Error: cannot implicitly convert
expression `["a"]` of type `string[]` to `Foo[]`
Foo[] foos = cast(Foo[]) ["a"]; // Error: e2ir: cannot cast `"a"`
of type `string` to type `Foo`
On Mon, Apr 25, 2022 at 01:28:01PM +, Alain De Vos via Digitalmars-d-learn
wrote:
> Could thc or hboehm provide solutions ?
In general, GC (of any kind) does not (and cannot) guarantee the order
objects will be collected in. So in the dtor, you cannot assume that any
objects you depend on
Could thc or hboehm provide solutions ?
GC-allocated objects are run (when they are run). If you need
deterministic destruction e.g. for resource management, do not
use GC.
Descend destroy and free functions should return something.
"destroy" should return if the destructor was called successfully.
"free" should return the exact
On Monday, 25 April 2022 at 07:19:31 UTC, bauss wrote:
Yes and in addition to Ali's message then remember it's
private for the module only.
Oops typo.
What I meant is that private is module level, so it's __not__
private in the module, but it is for other modules.
Thanks for the reply.
On Monday, 25 April 2022 at 08:54:52 UTC, Chris Katko wrote:
D
alias sPair = Typedef!pair; // pair of xy in screen space
coordinates
alias vPair = Typedef!pair; // pair of xy in viewport space
coordinates
//etc
This doesn't do what you think it does. Both `sPair` and `vPair`
are
On Monday, 25 April 2022 at 02:22:42 UTC, Ali Çehreli wrote:
Looks good to me.
There are other ways as well:
Thanks a lot. All I wanted to implement more than ctor with
different parameters and avoid code duplication.
On Monday, 25 April 2022 at 08:54:52 UTC, Chris Katko wrote:
D
struct pair
{
float x,y;
}
alias sPair = Typedef!pair; // pair of xy in screen space
coordinates
alias vPair = Typedef!pair; // pair of xy in viewport space
coordinates
//etc
How do you initialize a typedef'd struct?
``d
On Monday, 25 April 2022 at 10:13:43 UTC, Alain De Vos wrote:
Ali, thanks for the answer but i rephrase my question.
How to destroy,free , for garbage-collection-cycle in the
destructor of this code :
// But How to force destroy and free , GC-cycle for heap object
i ?
Short answer: use
Note, heap object i is not an instance of the class C
On Monday, 25 April 2022 at 09:38:05 UTC, Alain De Vos wrote:
This program works ok, (but List is no Range)
It is also possible with the copy constructor of a struct. I
don't know how to do with class...
```d
struct Node {
int element;
Node * next;
}
On Monday, 25 April 2022 at 10:13:43 UTC, Alain De Vos wrote:
destructor of this code :
```d
~this(){
writeln("Free heap");
import object: destroy;
import core.memory: GC;
i=null;
// But How to force destroy and free , GC-cycle for heap
object i ?
};
```
If
Ali, thanks for the answer but i rephrase my question.
How to destroy,free , for garbage-collection-cycle in the
destructor of this code :
```
import std.stdio: writeln;
class C{
int[] i=null;
this(){
writeln("Allocate heap");
i=new int[1];
This program works ok, (but List is no Range)
```
class Node {
int data;
Node next;
}
class List {
Node node=null;
this(int[] AR){foreach(i ; AR)pushfront(i);}
bool empty() const {return !node;}
void popFront() {node=node.next;}
float
D
struct pair
{
float x,y;
}
alias sPair = Typedef!pair; // pair of xy in screen space
coordinates
alias vPair = Typedef!pair; // pair of xy in viewport space
coordinates
//etc
void test()
{
pair v0 = pair(1f, 2f); // works fine, but what about the
typedefs?
vPair v1 = vPair(1f, 2f);
On Monday, 25 April 2022 at 05:17:28 UTC, Salih Dincer wrote:
On Monday, 25 April 2022 at 02:19:46 UTC, Ali Çehreli wrote:
This type violates a fundamental rule: Containers and ranges
are separate concepts. Your List is a container, not a range.
I changed your code by moving the range
On Monday, 25 April 2022 at 07:18:44 UTC, bauss wrote:
On Monday, 25 April 2022 at 00:18:03 UTC, Vinod K Chandran
wrote:
Hi all,
Please take a look at this code. Is this the right way to use
private constructors ?
```d
class Foo {
int p1 ;
string p2 ;
bool p3 ;
private
On Monday, 25 April 2022 at 00:18:03 UTC, Vinod K Chandran wrote:
Hi all,
Please take a look at this code. Is this the right way to use
private constructors ?
```d
class Foo {
int p1 ;
string p2 ;
bool p3 ;
private this(int a, string b, bool c) {
this.p1 = a
40 matches
Mail list logo