On Tuesday, 23 January 2024 at 18:15:29 UTC, Stephen Tashiro
wrote:
If the constructor of a class needs to create an array of
structs whose dimensions are inputs, what's the syntax for
doing this?
For a non-example, the following program errors in main()
because in t.array[][] "index [0] is
On Tuesday, 23 January 2024 at 19:32:31 UTC, Stephen Tashiro
wrote:
Thank you.
I don't really understand what the syntax
new Point[][](the_dimension,the_dimension);
denotes. Does it represent a function? To look up this topic,
what are the proper keywords?
By experimentation, I found
On Tuesday, January 23, 2024 12:32:31 PM MST Stephen Tashiro via Digitalmars-
d-learn wrote:
> On Tuesday, 23 January 2024 at 18:23:22 UTC, Renato wrote:
> > This works , your mistake was to not actually assign the array
> > to the class' field!
> >
> > Change this line:
> >
> > ```d
> > auto
On Tuesday, 23 January 2024 at 18:23:22 UTC, Renato wrote:
This works , your mistake was to not actually assign the array
to the class' field!
Change this line:
```d
auto array = new Point[][](the_dimension,the_dimension);
```
To this:
```d
this.array = new
On Tuesday, 23 January 2024 at 18:15:29 UTC, Stephen Tashiro
wrote:
If the constructor of a class needs to create an array of
structs whose dimensions are inputs, what's the syntax for
doing this?
For a non-example, the following program errors in main()
because in t.array[][] "index [0] is
If the constructor of a class needs to create an array of structs
whose dimensions are inputs, what's the syntax for doing this?
For a non-example, the following program errors in main() because
in t.array[][] "index [0] is out of bounds".
import std.stdio;
struct Point
{
uint
On Thursday, 3 October 2019 at 04:32:52 UTC, Brett wrote:
Ok, fine!
auto r =
Now r is a reference, great!
No, r is a pointer, not a reference. D does not have reference
variables.
But now the semantics of using the array completely change and
errors abound!
Probably because you're
On Thursday, 3 October 2019 at 04:32:52 UTC, Brett wrote:
struct Y { double q; }
struct X { Y[] a; }
X x;
auto r = x.a;
r is not a reference?!?!
Arrays are (ptr,length) pairs. r is a copy of them:
#! /usr/bin/env rdmd
import std.stdio;
struct X { int[] a; }
void main() {
struct Y { double q; }
struct X { Y[] a; }
X x;
auto r = x.a;
r is not a reference?!?!
When updating x.a, r is not updated ;/ [I'm not sure if it just
creates a slice or what]
Ok, fine!
auto r =
Now r is a reference, great!.
But now the semantics of using the array completely change
I'm trying to organize a large amount of simple data into
manageable parcels of information that I can access efficiently.
What I want to do is bake a static array into a class but be
allowed to do the banking at runtime (because I want each array
to be a different fixed length). Barring that,
On Monday, 18 January 2016 at 15:15:46 UTC, Dennis Croft wrote:
I'm trying to organize a large amount of simple data into
manageable parcels of information that I can access
efficiently. What I want to do is bake a static array into a
class but be allowed to do the banking at runtime (because
Here's what I suggest:
alias T = int;
class VariableLengthClass {
private:
string someMember;
size_t length_;
T[0] data_;
public:
static make(Args...)(size_t length, Args args) {
static assert(
typeof(this).init.data_.offsetof ==
On Thursday, 27 August 2015 at 11:45:14 UTC, anonymous wrote:
On Thursday 27 August 2015 13:15, BBasile wrote:
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150
On Thursday, 27 August 2015 at 12:56:26 UTC, anonymous wrote:
On Thursday 27 August 2015 14:35, BBasile wrote:
Anyway. I cheat a bit with attributes but as long as it's only
for me...I know this kinds of functions are not phobos-level.
Sure, as long as you're cautious and regard those
On Thursday 27 August 2015 14:35, BBasile wrote:
Anyway. I cheat a bit with attributes but as long as it's only
for me...I know this kinds of functions are not phobos-level.
Sure, as long as you're cautious and regard those functions as unsafe, you
may be fine. You still risk accidentally
I'm a c++ programmer trying to understand how memory allocation
works in D.
I created a struct and added a destructor to it. My understanding
is that structs have deterministic destructors - they are called
when the struct goes out of scope (unless it is allocated with
new).
Now if I put
Hi,
On Thursday, 27 August 2015 at 10:05:31 UTC, John Burton wrote:
understanding is that structs have deterministic destructors -
they are called when the struct goes out of scope
Yes, when they are declared right at the scope, and not contained
in something that might live past the current
On Thursday, 27 August 2015 at 10:05:31 UTC, John Burton wrote:
I'm a c++ programmer trying to understand how memory allocation
works in D.
I created a struct and added a destructor to it. My
understanding is that structs have deterministic destructors -
they are called when the struct goes
Ok that's great thank you.
It's quite hard trying to get a proper understanding of memory
allocation in D after years of C++ / RAII / unique_ptr /
shared_ptr . I understand the details of course but it's going to
take a while to really know it.
Is there any way to explicitly free a dynamic
Thanks again for the updates. I've experimented some more and
believe I understand.
To be honest I'm finding it very hard to find the right idioms in
D for safe and efficient programming when I'm so used to C++ /
RAII everywhere. I'll adapt though :P
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote:
Thanks again for the updates. I've experimented some more and
believe I understand.
To be honest I'm finding it very hard to find the right idioms
in D for safe and efficient programming when I'm so used to C++
/ RAII
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote:
To be honest I'm finding it very hard to find the right idioms
in D for safe and efficient programming when I'm so used to C++
/ RAII everywhere. I'll adapt though :P
This is true for every new language you learn. You first
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote:
Thanks again for the updates. I've experimented some more and
believe I understand.
To be honest I'm finding it very hard to find the right idioms
in D for safe and efficient programming when I'm so used to C++
/ RAII
On Thursday 27 August 2015 13:15, BBasile wrote:
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150
https://github.com/BBasile/iz/blob/master/import/iz/types.d#L191
Your use of @trusted is wrong and dangerous.
Hi. I am trying to write my first D program, and am quite stuck in several
areas. This is on Ubuntu 10.10 with the dmd DMD64 D Compiler v2.055.
I want to create a generic struct for multi-dimensional arrays,
in which the value parts can be shared. E.g., an array comprises
a vector of its raveled
On Thu, Jan 26, 2012 at 08:34:12PM +, Robert Bernecky wrote:
Hi. I am trying to write my first D program, and am quite stuck in several
areas. This is on Ubuntu 10.10 with the dmd DMD64 D Compiler v2.055.
[...]
However, none of this stuff works. Here's what I get:
dmd prd.d -unittest
The important mangled message here is:
prd.o:(.data+0x250): undefined reference to
`_D5Array12__ModuleInfoZ'
This is a linker error, your code compiled fine. The English
translation:
There is an undefined reference to module Array
You are compiling without including all files you need
Awesome! I feel much better now; thank you both for your instant help!
dmd prd.d Array.d -unittest
rbe@rattler:~/plural$ prd
[0]
[0, 1, 2, 3, 4]
Created int
iota shape is %d
[0]
iota value is %d
[0, 1, 2, 3, 4]
got to unittest for Array.d
[0]
[0, 1, 2, 3, 4]
Created int
[0]
[0, 1, 2, 3, 4]
On Thu, 26 Jan 2012 21:53:39 +, Robert Bernecky wrote:
Awesome! I feel much better now; thank you both for your instant help!
dmd prd.d Array.d -unittest
rbe@rattler:~/plural$ prd
[0]
[0, 1, 2, 3, 4]
Created int
iota shape is %d
[0]
iota value is %d
[0, 1, 2, 3, 4]
got to
On Thursday, 26 January 2012 at 22:10:23 UTC, Justin Whear wrote:
If you want your Array code to be a separate library/project,
you can compile it like so:
dmd Array.d -lib
Then when you compile your other project:
dmd prd.d -I/location/of/Array.d -L/location/of/Array.so
Justin
It is
30 matches
Mail list logo