Re: trouble with associative Arrays
On Saturday, 20 January 2024 at 15:16:00 UTC, atzensepp wrote: The section looks now simpler although I guess that there are more appropriate mechanisms available (csvreader): string [] orgids[string]; foreach (line; range) { if (!line.empty) { auto row =
Re: trouble with associative Arrays
Thank you T for your hint. This worked perfectly On Saturday, 20 January 2024 at 14:44:49 UTC, H. S. Teoh wrote: Because .byLine reuses its line buffer. You want .byLineCopy instead. The section looks now simpler although I guess that there are more appropriate mechanisms available (csvreader
Re: trouble with associative Arrays
On Sat, Jan 20, 2024 at 02:33:24PM +, atzensepp via Digitalmars-d-learn wrote: > Hello, > > I am new with D and want to convert a c program for a csv file manipulation > with exhaustive dynamic memory mechanics to D . > > When reading a CSV-file line by line I would like to create an associa
trouble with associative Arrays
Hello, I am new with D and want to convert a c program for a csv file manipulation with exhaustive dynamic memory mechanics to D . When reading a CSV-file line by line I would like to create an associative array to get the row values by the value in the second column. Although I save the row
Re: Comparison of multidimensional associative arrays
On Wednesday, 8 February 2023 at 19:04:15 UTC, Alexander Zhirov wrote: [...] I would write a data structure and use struct members to reason about things, but that's probably just preference. ``` import std; struct DatabaseEntry { int id = -1; string deleted; string name; t
Re: Comparison of multidimensional associative arrays
On Wednesday, 8 February 2023 at 19:32:22 UTC, Ali Çehreli wrote: This should do it: [...] Yes, it works! I'll try it tomorrow on a large array of data. Thank you very much! This turns out to be a simple loop with a comparison of the existence of a key (whether it is included in an array or n
Re: Comparison of multidimensional associative arrays
On 2/8/23 11:04, Alexander Zhirov wrote: > That is, the result is arrays of table B that are missing OR not equal > to arrays in table A. This should do it: alias MyType = string[string][int]; // 'a' is subtracted from 'b' MyType difference(MyType b, MyType a) { MyType result; foreach
Re: Comparison of multidimensional associative arrays
On Wednesday, 8 February 2023 at 18:57:00 UTC, Anonymouse wrote: Can you explain how you determine how/if two entries are different? I apologize. I have not written, in fact, what I need to get. Array `A` ```d [ 4:["id":"4", "deleted":"f", "name":"6.2"], 3:["id":"3", "deleted":"f", "n
Re: Comparison of multidimensional associative arrays
On Wednesday, 8 February 2023 at 17:55:03 UTC, Alexander Zhirov wrote: Not an easy task for me, maybe you can advise your compact solution. There are two associative arrays of type `string[string][int]`. It is necessary to find the differences and return them when comparing: Can you explain
Re: Comparison of multidimensional associative arrays
On Wednesday, 8 February 2023 at 18:08:40 UTC, Ali Çehreli wrote: Just because this sounds complicated, I hope the data structure can be designed differently to be more friendly to this operation. (?) Ali This is the result of an SQL query. Roughly speaking, I need to compare the result of
Re: Comparison of multidimensional associative arrays
On 2/8/23 09:55, Alexander Zhirov wrote: > the differences Is it considered a difference if a key exists but the value is different? Or is that an error case if you encounter that? > return them when comparing: The representation seems difficult as well. When given this: > 6:["id":"6",
Comparison of multidimensional associative arrays
Not an easy task for me, maybe you can advise your compact solution. There are two associative arrays of type `string[string][int]`. It is necessary to find the differences and return them when comparing: ```d [ 6:["id":"6", "deleted":"f", "nam
Re: Why dtor are not executed when removing a struct from associative arrays?
On 9/21/21 2:06 AM, Tejas wrote: On Monday, 20 September 2021 at 18:13:53 UTC, Steven Schveighoffer wrote: On 9/20/21 10:22 AM, Tejas wrote: In case you still want to delete stuff deterministically despite what Steve said, I suggest you make your `struct` a reference and use `core.memory.__del
Re: Why dtor are not executed when removing a struct from associative arrays?
On Monday, 20 September 2021 at 18:13:53 UTC, Steven Schveighoffer wrote: On 9/20/21 10:22 AM, Tejas wrote: In case you still want to delete stuff deterministically despite what Steve said, I suggest you make your `struct` a reference and use `core.memory.__delete`(not recommended to use this
Re: Why dtor are not executed when removing a struct from associative arrays?
On 9/20/21 10:22 AM, Tejas wrote: In case you still want to delete stuff deterministically despite what Steve said, I suggest you make your `struct` a reference and use `core.memory.__delete`(not recommended to use this carelessly, btw) Do not call `__delete` here, use `destroy`. `__delete` wi
Re: Why dtor are not executed when removing a struct from associative arrays?
On 9/20/21 5:23 AM, Learner wrote: I was expecting S instance dtor called S is being destructed If you are sure the element can be destroyed, you can call destroy(): import std.stdio; enum someSpecialInitValue = 777; struct S { int i = someSpecialInitValue; this(int i) { this.i =
Re: Why dtor are not executed when removing a struct from associative arrays?
On Monday, 20 September 2021 at 14:03:09 UTC, Tejas wrote: On Monday, 20 September 2021 at 13:48:01 UTC, Tejas wrote: On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: [...] I think it *is* being called: ```d import std.stdio; struct S { int a; this(int param){
Re: Why dtor are not executed when removing a struct from associative arrays?
On Monday, 20 September 2021 at 13:48:01 UTC, Tejas wrote: On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: [...] I think it *is* being called: ```d import std.stdio; struct S { int a; this(int param){ a = param; } ~this() {
Re: Why dtor are not executed when removing a struct from associative arrays?
On 9/20/21 8:23 AM, Learner wrote: I was expecting something like going out of scope for that ```d import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1); writeln("Why no dtor c
Re: Why dtor are not executed when removing a struct from associative arrays?
On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1);
Re: Why dtor are not executed when removing a struct from associative arrays?
On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1);
Why dtor are not executed when removing a struct from associative arrays?
I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1); writeln("Why no dtor call on remove?"); } I was expecting S
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 08:31:16 UTC, Ali Çehreli wrote: Two options for byKey and byKeyValue: import std; void main() { auto aa = [ "WS2" : 42, "WS3" : 43 ]; string strComputerIDunwanted = "WS2"; foreach (key; aa.byKey.filter!(k => k != strComputerIDunwanted)) { writeln(key, '
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 15:32:09 UTC, wjoe wrote: something like this ? ``` D import std.array; import std.algorithm; udtComputers.byPair .filter!(p => p.key != strComputerIDunwanted) .each!( (p) { /* foreach body */ } ); ``` This seems really interesting :) Almost th
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 22:08:56 UTC, Steven Schveighoffer wrote: It's actually visually shorter than doing the filter. Indeed; in a few very-specific situations I usually write code like this since it allows me to concentrate on the task at hand and not on the details to access the need
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 21:00:42 UTC, Elronnd wrote: Here's how I would do it: foreach (k, v; coll) { if (k == unwanted) continue; ... } You still have an if, but the actual loop body doesn't have to be nested, so it's easy to follow the control flow. almost the same
Re: how to filter associative arrays with foreach ?
On 6/21/21 5:00 PM, Elronnd wrote: On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: Is there a way to filter the collection at the foreach-level to avoid the inner if ? Here's how I would do it: foreach (k, v; coll) { if (k == unwanted) continue; ... } You still have an if,
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: Is there a way to filter the collection at the foreach-level to avoid the inner if ? Here's how I would do it: foreach (k, v; coll) { if (k == unwanted) continue; ... } You still have an if, but the actual loop body doesn't have
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: I often need to iterate through a filtered collection (associative array) as following: ```d string strComputerIDunwanted = "WS2"; /// associative array key to exclude foreach (strComputerID, udtComputer; udtComputers) { /// .remove!(a
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 08:35:19 UTC, frame wrote: An associative array is not a range but a struct, so it is extra work to create a range from the AA to apply range functions. You can get a range from it by using something like std.array.byPair() but for this usage you would be better of
Re: how to filter associative arrays with foreach ?
On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: I often need to iterate through a filtered collection (associative array) as following: ```d string strComputerIDunwanted = "WS2"; /// associative array key to exclude foreach (strComputerID, udtComputer; udtComputers) { /// .remove!(a
Re: how to filter associative arrays with foreach ?
On 6/20/21 8:59 PM, someone wrote: I often need to iterate through a filtered collection (associative array) as following: ```d string strComputerIDunwanted = "WS2"; /// associative array key to exclude foreach (strComputerID, udtComputer; udtComputers) { /// ..remove!(a => a == strComputerID
how to filter associative arrays with foreach ?
I often need to iterate through a filtered collection (associative array) as following: ```d string strComputerIDunwanted = "WS2"; /// associative array key to exclude foreach (strComputerID, udtComputer; udtComputers) { /// .remove!(a => a == strComputerIDunwanted) ... ? if (strCompute
Re: Parallel foreach iteration with Associative Arrays
On Saturday, 17 April 2021 at 02:14:50 UTC, Paul Backus wrote: `parallel` requires a range [1], and an associative array is not a range. To get a range of an AA's keys and values, you can use the method `.byKeyValue`: foreach (pair; parallel(example.byKeyValue)) { writeln(pair.key,
Re: Parallel foreach iteration with Associative Arrays
On Saturday, 17 April 2021 at 01:57:34 UTC, Kirill wrote: I'd like to iterate over an associative array and output it's key and value using parallel from std.parallelism. But I get an error message: ParallelForeach!(int[string]) error instantiating. My code: auto example = ["apples": 100, "
Parallel foreach iteration with Associative Arrays
I'd like to iterate over an associative array and output it's key and value using parallel from std.parallelism. But I get an error message: ParallelForeach!(int[string]) error instantiating. My code: auto example = ["apples": 100, "orange": 250, "banana": 175]; foreach(key, value; parallel(
Re: Static initialization of associative arrays
On Thursday, 11 March 2021 at 18:41:08 UTC, Ali Çehreli wrote: On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static this
Re: Static initialization of associative arrays
On Thursday, 11 March 2021 at 19:12:34 UTC, H. S. Teoh wrote: On Thu, Mar 11, 2021 at 06:06:35PM +, Chris Piker via immutable int[string] aa; shared static this() { aa = [ "abc": 123, "def": 456, /* ... */ ]; } Hi H.S.T Yes, I'm using static if, but do you
Re: Static initialization of associative arrays
On Thursday, 11 March 2021 at 18:41:08 UTC, Ali Çehreli wrote: On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static this
Re: Static initialization of associative arrays
On Thu, Mar 11, 2021 at 06:06:35PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > Today I ran across a situation where an immutable associative array > would be handy. While perusing the language spec I noticed here: > > https://dlang.org/spec/hash-map.html#static_initialization > >
Re: Static initialization of associative arrays
On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static this() { aa = [ 1: "one" ]; } void main() { assert(aa.length ==
Static initialization of associative arrays
Hi D At work I've begun writing programs in D that I would typically write in python. My goal is to get away from split python/C development and just use one language most of the time. Today I ran across a situation where an immutable associative array would be handy. While perusing the lan
Re: How to efficiently resolve Associative Arrays not being sorted?
On 6/2/20 3:32 AM, BoQsc wrote: I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else? What are the ways to
Re: How to efficiently resolve Associative Arrays not being sorted?
On 6/2/20 12:32 AM, BoQsc wrote: > I want to read a file, put it into an array, make some search and > replace on the content and output the modified text. How large is the data? If it fits into memory, just read the whole thing, update it, sort the keys, and then output like this: import s
Re: How to efficiently resolve Associative Arrays not being sorted?
On Tuesday, 2 June 2020 at 07:32:56 UTC, BoQsc wrote: I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else
How to efficiently resolve Associative Arrays not being sorted?
I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else? What are the ways to resolve this randomness in
Re: Does anyone have gdb pretty printers for buildin types like associative arrays?
On Sunday, 15 March 2020 at 16:42:52 UTC, Panke wrote: Should this just work and by box is not correctly configured or do I need some pretty printers? If so, has someone already made them? Take a look at: https://forum.dlang.org/post/ztyhmmxalpiysgjkv...@forum.dlang.org
Does anyone have gdb pretty printers for buildin types like associative arrays?
At least on my installation they are printed as just a pointer. Should this just work and by box is not correctly configured or do I need some pretty printers? If so, has someone already made them?
Re: += on associative arrays leads to surprising result
On Tuesday, 27 August 2019 at 16:45:53 UTC, Samir wrote: I never understood why the intial value of floats, doubles and reals was NaN. That's for detecting uninitialised variables. If the result of a calculation is NaN, it's likely, that you forgot to initialise the variable.
Re: += on associative arrays leads to surprising result
On Tuesday, 27 August 2019 at 16:12:07 UTC, berni wrote: What's your oppinion on this? As someone relatively new to programming in general and to D in particular, this behavior does, on the surface, seem inconsistent. Good to see that a bug exists for this, per ag0aep6g. I never understoo
Re: += on associative arrays leads to surprising result
On 27.08.19 18:12, berni wrote: import std.stdio; void main() { real[int] a; a[0] += 100; writeln(a); } results (independed of the used compiler) in [0:100] I was a little bit surprised, because a[0] += 100 should be the same as a[0] = a[0]+100, which leads to a range violatio
+= on associative arrays leads to surprising result
import std.stdio; void main() { real[int] a; a[0] += 100; writeln(a); } results (independed of the used compiler) in [0:100] I was a little bit surprised, because a[0] += 100 should be the same as a[0] = a[0]+100, which leads to a range violation error. Furthermore, as we work
Re: Merging two associative arrays
On Saturday, 24 August 2019 at 19:55:48 UTC, a11e99z wrote: auto ab = a.byPair.chain( b.byPair).assocArray ? Not sure, if it is simpler, but a least without tmp. :) Thanks.
Re: Merging two associative arrays
On Saturday, 24 August 2019 at 19:35:25 UTC, berni wrote: I've got two associative arrays and want to get a new one, which is created out of both of them: This works: string[int] a = [1:"one", 7:"seven"]; string[int] b = [5:"five", 9:"nine"]; s
Merging two associative arrays
I've got two associative arrays and want to get a new one, which is created out of both of them: This works: string[int] a = [1:"one", 7:"seven"]; string[int] b = [5:"five", 9:"nine"]; string[int] tmp = a.dup; foreach (k,v;b) tmp[k] = v; asser
Re: Why does struct initializer works for arrays but not for associative arrays?
based on the fact that it's being used in a struct literal. - Jonathan M Davis Thanks for the information. As it works fine for dynamic arrays and the coding in the compiler seems identical for arrays and associative arrays I really wonder why it not work. Although I really anticipate
Re: Why does struct initializer works for arrays but not for associative arrays?
On Wednesday, 14 March 2018 at 15:17:54 UTC, Jonathan M Davis wrote: On Wednesday, March 14, 2018 13:36:51 Andre Pany via Digitalmars-d-learn wrote: [...] Well, I think that you have two issues here: 1. Struct literals work in only a few, specific circumstances. Why, I don't know, but IIRC,
Re: Why does struct initializer works for arrays but not for associative arrays?
On Wednesday, March 14, 2018 13:36:51 Andre Pany via Digitalmars-d-learn wrote: > Hi, > > I do not understand why struct initializer works for arrays but > not for > associative arrays: > > struct Bar > { > string s; > } > > struct Foo > { &g
Re: Why does struct initializer works for arrays but not for associative arrays?
On Wednesday, 14 March 2018 at 13:36:51 UTC, Andre Pany wrote: Hi, I do not understand why struct initializer works for arrays but not for associative arrays: struct Bar { string s; } struct Foo { Bar[string] asso; Bar[] arr; } void main() { Foo foo = { arr: [{s
Why does struct initializer works for arrays but not for associative arrays?
Hi, I do not understand why struct initializer works for arrays but not for associative arrays: struct Bar { string s; } struct Foo { Bar[string] asso; Bar[] arr; } void main() { Foo foo = { arr: [{s: "123"}], asso: ["0": {s: &quo
Re: Associative arrays with keys containing mutable indirections
On 10/30/17 6:49 AM, Tony wrote: I prefer the built-in associative array over using some template library. It has the clean look and ease-of-use that you get with a similar data structure in dynamic languages like Python. I consider it a top feature of D. There is a misunderstanding here. The
Re: Associative arrays with keys containing mutable indirections
I prefer the built-in associative array over using some template library. It has the clean look and ease-of-use that you get with a similar data structure in dynamic languages like Python. I consider it a top feature of D.
Re: Associative arrays with keys containing mutable indirections
On Sunday, October 29, 2017 22:24:57 Nordlöw via Digitalmars-d-learn wrote: > Shouldn't associative arrays with key types (K) having mutable > indirections (std.traits.hasAliasing!K) such as > > string[ubyte[]] > > be disallowed? > > If not, in what cases do we w
Associative arrays with keys containing mutable indirections
Shouldn't associative arrays with key types (K) having mutable indirections (std.traits.hasAliasing!K) such as string[ubyte[]] be disallowed? If not, in what cases do we want this?
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 16:34:15 UTC, H. S. Teoh wrote: On Tue, May 02, 2017 at 02:37:20PM +, ANtlord via Digitalmars-d-learn wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: > > Note that when declared as "enum", all places it's > referenced, a new associative array
Re: Top level associative arrays
On Tue, May 02, 2017 at 02:37:20PM +, ANtlord via Digitalmars-d-learn wrote: > On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: > > > > Note that when declared as "enum", all places it's referenced, a new > > associative array will be allocated. > > If it is allocated at all plac
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 14:37:20 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 12:41:01 UTC, Jacob Carlborg wrote: Note that when declared as "enum", all places it's referenced, a new associative array will be allocated. If it is allocated at all places I can move initialization to module ctor as says evilrat but how can I make an immutable a
Re: Top level associative arrays
On 2017-05-02 09:48, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { w
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 09:50:50 UTC, ANtlord wrote: On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So th
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 08:24:09 UTC, evilrat wrote: Making enum means that value should be available at compile time and AA's are fully dynamic. But if my memory serves me well, you can declare empty AA and delay initialization. So the closest solution is to move initialization of AA to sh
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "
Re: Top level associative arrays
On Tuesday, 2 May 2017 at 07:48:35 UTC, ANtlord wrote: Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "
Top level associative arrays
Hello! Is it possible to define associative array on top level of module? I try to compile this code and I get message `Error: non-constant expression ["s":"q", "ss":"qq"]` import std.stdio; auto dict = [ "s": "q", "ss": "qq" ]; void main() { writeln(val); } I solved i
Re: Best ways to declare associative arrays
= strip(readln()); arg_array[1] = strip(readln()); } void main() { string[2] test; change(test); } Also another disadvantage of associative arrays is that they are not ordered, so if for example in main() you read through the values in test with a foreach loop, you may get th
Re: Best ways to declare associative arrays
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: How would an experienced programmer declare an associative array of strings that has 2 keys? My initial impression was string[string][2] my_array; which does not seem to work. Here is a snippet of the code I am working on: import std.s
Re: Best ways to declare associative arrays
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: return def; I meant return arg_array;
Best ways to declare associative arrays
How would an experienced programmer declare an associative array of strings that has 2 keys? My initial impression was string[string][2] my_array; which does not seem to work. Here is a snippet of the code I am working on: import std.string; import std.stdio; string[string] change(ref str
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
of an immutable object. I would open an issue: https://issues.dlang.org/enter_bug.cgi?product=D Ali You cannot Assign Associative Arrays at compile-time. Because those are defined by druntime have no stable ABI. Thanks Stefan but at least there should be a better diagnostic instead of
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
://issues.dlang.org/enter_bug.cgi?product=D Ali You cannot Assign Associative Arrays at compile-time. Because those are defined by druntime have no stable ABI. Thanks Stefan but at least there should be a better diagnostic instead of the confusing current situation that Ali experienced. Ali
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
You cannot Assign Associative Arrays at compile-time. Because those are defined by druntime have no stable ABI.
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On 12/14/2016 04:02 AM, Ali wrote: > On Tuesday, 13 December 2016 at 23:29:31 UTC, Ali Çehreli wrote: >> On 12/13/2016 01:36 PM, Ali wrote: >> >>> Now about that second part of my problem >> >> I'm not entirely sure whether this should work but I think the problem >> is with mutating the 'fre
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
return B(x); } static immutable a = f1(); static immutable b = f2(); pragma(msg, a); pragma(msg, b); This fails to compile with "Error: non-constant expression ['A':2]". But, the pragma(msg) prints out the correct information for both a and b. What's the deal wi
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On 12/13/2016 01:36 PM, Ali wrote: Now about that second part of my problem I'm not entirely sure whether this should work but I think the problem is with mutating the 'frequencies' member of an immutable element of 'rooms'. The error message means that those non-const expressions canno
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On Tuesday, 13 December 2016 at 21:33:11 UTC, Ali Çehreli wrote: On 12/13/2016 12:30 PM, Ali wrote: > foreach (i, room; rooms) { > data[i].room = &room; That is the address of the local variable room. You need to use 'ref' there: foreach (i, ref room; rooms) { > - Ali Ahh
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On 12/13/2016 12:30 PM, Ali wrote: > foreach (i, room; rooms) { > data[i].room = &room; That is the address of the local variable room. You need to use 'ref' there: foreach (i, ref room; rooms) { > - Ali Ali "the real one :o)"
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
2016-12-13
Thread
bauss (wtf happend to my name took some old cached title LOL??) via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 21:21:34 UTC, Ali wrote: On Tuesday, 13 December 2016 at 21:08:31 UTC, drug007 wrote: (*d.room).name Oh yeah, tried that too. That at least compiles but gives a runtime exception (bad address). Try (*cast(Room*)(d.room)).name
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On Tuesday, 13 December 2016 at 21:08:31 UTC, drug007 wrote: (*d.room).name Oh yeah, tried that too. That at least compiles but gives a runtime exception (bad address).
Re: Accessing members through pointers to structs (also, CTFE associative arrays)
On 13.12.2016 23:30, Ali wrote: Hi, Long time watcher and recently started playing with D a bit more. Ran in to a couple of snags that I'll combine in one post. It involves a data set that contains a list of strings. Each string represents a Room name. What I'm trying to do is pluck out the room
Accessing members through pointers to structs (also, CTFE associative arrays)
data I'd rather just have a pointer to it. Is there a way to do that? Second problem is to do with associative arrays. At first the Room object had a frequencies object in it (ie: int[char] <- number of times a character appears in the name). In my parse function, if I add a foreach
Re: Accessing contents of associative arrays in an optimal way
Thank you!
Re: Accessing contents of associative arrays in an optimal way
On 07/09/2016 10:32 PM, phant0m wrote: As far as I know, AA implemented as a hashtable. So, will there be two searches performed (one search for each line)? records[3].value = 10; records[3].name = "name"; Yup. A good optimizer may be able to eliminate one, but conceptually there are two looku
Re: Accessing contents of associative arrays in an optimal way
On 07/09/2016 01:32 PM, phant0m wrote: > Suppose I have AA of structures: > > struct Foo { > int value; > string name; > } > > Foo[int] records; > > As far as I know, AA implemented as a hashtable. So, will there be two > searches performed (one search for each line)? > records[3].value
Accessing contents of associative arrays in an optimal way
Suppose I have AA of structures: struct Foo { int value; string name; } Foo[int] records; As far as I know, AA implemented as a hashtable. So, will there be two searches performed (one search for each line)? records[3].value = 10; records[3].name = "name"; How can I access elements o
Re: Reserving capacity in associative arrays
pacity in associative arrays? >>[snip] >>The underlying implementation of associative arrays appears >>to take >>an initial number of buckets, and there's a private resize() >>method, >>but it's not clear if there's a public way to use these. R
Re: Reserving capacity in associative arrays
On Tue, Feb 16, 2016 at 07:34:07PM +, Jon D via Digitalmars-d-learn wrote: > On Tuesday, 16 February 2016 at 16:37:07 UTC, Steven Schveighoffer wrote: > >On 2/14/16 10:22 PM, Jon D wrote: > >>Is there a way to reserve capacity in associative arrays? > >>[snip] > &
Re: Reserving capacity in associative arrays
On Tuesday, 16 February 2016 at 16:37:07 UTC, Steven Schveighoffer wrote: On 2/14/16 10:22 PM, Jon D wrote: Is there a way to reserve capacity in associative arrays? [snip] The underlying implementation of associative arrays appears to take an initial number of buckets, and there's a pr
Re: Reserving capacity in associative arrays
On Tuesday, 16 February 2016 at 17:05:11 UTC, Basile B. wrote: On Tuesday, 16 February 2016 at 16:37:07 UTC, Steven Schveighoffer wrote: There is not a public way to access these methods unfortunately. It would be a good addition to druntime I believe. -Steve After reading the topic i've ad
Re: Reserving capacity in associative arrays
On Tuesday, 16 February 2016 at 16:37:07 UTC, Steven Schveighoffer wrote: There is not a public way to access these methods unfortunately. It would be a good addition to druntime I believe. Recently, I added a clear method to the AA, which does not reduce capacity. So if you frequently build l