Re: Is there any generic iteration function that stops at first match?

2021-03-04 Thread mipri via Digitalmars-d-learn
On Friday, 5 March 2021 at 05:32:27 UTC, Jack wrote: On Friday, 5 March 2021 at 02:43:36 UTC, H. S. Teoh wrote: On Fri, Mar 05, 2021 at 02:13:39AM +, Jack via Digitalmars-d-learn wrote: something like filter[1] but that stops at first match? are there any native functions for this in D or

Re: vibe.d / experience / feedback

2020-10-01 Thread mipri via Digitalmars-d-learn
On Thursday, 1 October 2020 at 06:32:23 UTC, Robert M. Münch wrote: 5. One can't access the raw HTTP request body, things must be go through Vibe's JSON parser. To get access to the raw body, a lot of workarounds are necessary. given an HTTPServerRequest req, req.bodyReader.readAll for binary

Re: preset counter variable in a for loop

2020-02-28 Thread mipri via Digitalmars-d-learn
On Friday, 28 February 2020 at 12:44:52 UTC, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Well, that's the error. b has no

Re: Call method if declared only

2020-02-28 Thread mipri via Digitalmars-d-learn
On Friday, 28 February 2020 at 08:08:59 UTC, Виталий Фадеев wrote: Searching for beauty readable code... The pattern throughout Phobos is static tests, like isInputRange!R So something like this: import std.stdio; import std.traits; template canOnKey(T) { static if

Re: Question about the $ sign in arrays and strings

2020-02-19 Thread mipri via Digitalmars-d-learn
On Wednesday, 19 February 2020 at 07:49:36 UTC, Namal wrote: oooh... I used str = std.readln(); to get my string and there must have been some other sign, line break or whitespace or something at the end :( Now I understand it, thx That makes sense. readln includes the newline: $ echo

Re: Question about the $ sign in arrays and strings

2020-02-18 Thread mipri via Digitalmars-d-learn
On Wednesday, 19 February 2020 at 07:04:48 UTC, Namal wrote: Hello, I wanted to remove the lastchar in a string and figured that you can do that wit str = str[0..$-2]; but why is str = str[0..$] and str=str[0..$-1] the same ? Why do you think that they are the same? $ rdmd --eval 'auto

Re: How to iterate over range two items at a time

2020-02-16 Thread mipri via Digitalmars-d-learn
On Monday, 17 February 2020 at 05:04:02 UTC, Adnan wrote: What is the equivalent of Rust's chunks_exact()[1] method in D? I want to iterate over a spitted string two chunks at a time. [1] https://doc.rust-lang.org/beta/std/primitive.slice.html#method.chunks_exact And, after actually

Re: How to iterate over range two items at a time

2020-02-16 Thread mipri via Digitalmars-d-learn
On Monday, 17 February 2020 at 05:04:02 UTC, Adnan wrote: What is the equivalent of Rust's chunks_exact()[1] method in D? I want to iterate over a spitted string two chunks at a time. [1] https://doc.rust-lang.org/beta/std/primitive.slice.html#method.chunks_exact $ rdmd --eval '"hello

Re: How the hell to split multiple delims?

2020-02-15 Thread mipri via Digitalmars-d-learn
On Saturday, 15 February 2020 at 11:32:42 UTC, AlphaPurned wrote: I've tried 10 different ways with split and splitter, I've used all the stuff that people have said online but nothing works. I always get a template mismatch error. Why is something so easy to do so hard in D? auto toks =

Re: Filling an associated array of associated arrays

2020-01-14 Thread mipri via Digitalmars-d-learn
On Tuesday, 14 January 2020 at 23:23:51 UTC, Jamie wrote: I'm trying to initialise an associated array of associated arrays with values, taking the same approach I would for an associated array: This works: import std.stdio; void main() { string[string][string] table = ([

Re: Reading a file of words line by line

2020-01-14 Thread mipri via Digitalmars-d-learn
On Tuesday, 14 January 2020 at 16:39:16 UTC, mark wrote: I can't help feeling that the foreach loop's block is rather more verbose than it could be? WordSet words; auto rx = ctRegex!(r"^[a-z]+", "i"); auto file = File(filename); foreach (line; file.byLine) { auto

Re: Finding position of a value in an array

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 19:46:50 UTC, Ron Tarrant wrote: Thanks, mipri. Got it sorted. Here's a working proof... ``` import std.stdio; import std.algorithm; import std.conv; void main(string[] args) { MyObject[] objectArray; MyObject newObject; MyObject

Re: Finding position of a value in an array

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 19:08:27 UTC, Ron Tarrant wrote: On Monday, 30 December 2019 at 17:12:26 UTC, MoonlightSentinel wrote: D disallows implicit conversion from integers to pointers and hence they cannot be compared. You would need to explicitly cast your ulong to an appropriate

Re: Concatenation/joining strings together in a more readable way

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 10:23:14 UTC, Marcone wrote: On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}", "name")); // Helo name {} This function replace {}

Re: Finding position of a value in an array

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 14:30:12 UTC, Ron Tarrant wrote: On Sunday, 29 December 2019 at 09:44:18 UTC, MoonlightSentinel wrote: int i = a.countUntil(55); I was trying to do this with an array of pointers, but I get an error (which suggests to me that I don't know what data type a

Re: Concatenation/joining strings together in a more readable way

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 06:47:37 UTC, Marcone wrote: Use Python format() style: import std; import std: Format = format; // format() string format(T...)(T text){ string texto = text[0]; foreach(count, i; text[1..$]){ texto = texto.replaceFirst("{}",

Re: Finding position of a value in an array

2019-12-29 Thread mipri via Digitalmars-d-learn
On Sunday, 29 December 2019 at 08:26:58 UTC, Daren Scot Wilson wrote: Reading documentation... Array, Algorithms, ... maybe I've been up too late... how does one obtain the index of, say, 55 in an array like this int[] a = [77,66,55,44]; I want to do something like: int i =

Re: How create a function that receive a function and run it in another threading?

2019-12-26 Thread mipri via Digitalmars-d-learn
On Friday, 27 December 2019 at 06:08:16 UTC, Marcone wrote: import std; import core.thread; auto threading(lazy void fun){ return task!fun().executeInNewThread(); } void main(){ threading(writeln("Hello World!")); } I want to create a function threading() to run some function in

Re: Concatenation/joining strings together in a more readable way

2019-12-25 Thread mipri via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least point

Re: What would it take to bring preinstalled D language compiler in the major Linux Distributions?

2019-12-23 Thread mipri via Digitalmars-d-learn
On Monday, 23 December 2019 at 13:34:55 UTC, BoQsc wrote: I would love to see D language available out of box in major Linux distributions and use without much care of installation. Anyone have a though about it? Was there any serious efforts to bring D language to Major distributions? What

Re: range code doesn't work for multi-array

2019-12-16 Thread mipri via Digitalmars-d-learn
On Tuesday, 17 December 2019 at 07:40:28 UTC, AlphaPurned wrote: if arr is a single array the follow code works(removing [i]) but if it is a double array it fails. arr as type double[A][B]. arr[i] has type double[A]. v ~= arr[i].map!(a=>to!string(a)~",").join; with `Range = double[21]`

Re: D's equivalent List Comprehension

2019-12-13 Thread mipri via Digitalmars-d-learn
On Friday, 13 December 2019 at 15:20:02 UTC, Jesse Phillips wrote: I had mentioned my take on list comprehension here: https://forum.dlang.org/post/qslt0q$2dnb$1...@digitalmars.com#post-ycbohbqaygrgmidyhjma:40forum.dlang.org However someone put together a more comprehensive tutorial of its

Re: How add "version.txt" Version File by Command Line or by resources.res using dmd.exe

2019-12-08 Thread mipri via Digitalmars-d-learn
On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote: I want to add version to my program. I have configurated my version file "version.txt", but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by

Re: Are there any DUB packages for displaying an ascii table?

2019-12-08 Thread mipri via Digitalmars-d-learn
On Sunday, 8 December 2019 at 08:01:32 UTC, Soulsbane wrote: Been playing with Golang lately and it has quite a few modules for terminal tables. For example this one: github.com/brettski/go-termtables. Is there a D equivalent package? Can't seem to find any via search(which by the ways seems

Re: Populating nested AAs; "This wouldn't be so verbose in Ada 2020"

2019-12-07 Thread mipri via Digitalmars-d-learn
On Sunday, 8 December 2019 at 06:42:22 UTC, Paul Backus wrote: You can use the `require` function [1] for this: with (userHistory.require(host).require(user)) { if (isOk) ++ok; // renamed to avoid shadowing else ++evil; } Many "methods" for built-in AAs are located in the `object`

Populating nested AAs; "This wouldn't be so verbose in Ada 2020"

2019-12-07 Thread mipri via Digitalmars-d-learn
Hello, I've got this code: struct UserStats { int ok, evil; } // module-level variable UserStats[string][string] userHistory; and this code that populates it: // loop over DB query if (host !in userHistory) userHistory[host] = typeof(userHistory[host]).init; if

Re: Using map result type

2019-12-07 Thread mipri via Digitalmars-d-learn
On Sunday, 8 December 2019 at 01:10:21 UTC, AA wrote: I'd like to accept the return type of map. From some previous questions that I should accept a template? In general this is what you want to do with any kind of range code, because you're not working with definite types, but with types that

Re: How to invert bool false/true in alias compose?

2019-12-06 Thread mipri via Digitalmars-d-learn
On Saturday, 7 December 2019 at 04:00:53 UTC, Marcone wrote: import std; alias cmd = compose!(to!bool, wait, spawnShell, to!string); void main(){ writeln(cmd("where notepad.exe")); } Result: C:\Windows\System32\notepad.exe C:\Windows\notepad.exe false The result show "false"

Re: Unexpectedly nice case of auto return type

2019-12-06 Thread mipri via Digitalmars-d-learn
On Friday, 6 December 2019 at 23:25:30 UTC, Johannes Loher wrote: On Tuesday, 3 December 2019 at 10:06:22 UTC, Mike Parker wrote: On Tuesday, 3 December 2019 at 10:03:22 UTC, Basile B. wrote: That's interesting details of D developement. Since you reply to the first message I think you have

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread mipri via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:13:30 UTC, mipri wrote: Speaking of nice stuff and aliases, suppose you want to return a nice tuple with named elements? Option 1: auto auto option1() { return tuple!(int, "apples", int, "oranges")(1, 2); } Option 2: redundancy Tuple!(int,

Re: Intersection of two sets

2019-12-03 Thread mipri via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 18:45:18 UTC, Jan Hönig wrote: On Tuesday, 3 December 2019 at 13:55:51 UTC, Alex wrote: This depends on the available accesses on your sets. In terms of ranges: Are your sets InputRanges, ForwardRange, ... ? 2) Are there some build-in function for handling

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread mipri via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 10:02:47 UTC, Andrea Fontana wrote: On Tuesday, 3 December 2019 at 09:48:39 UTC, Basile B. wrote: You see what surprises me here is that we cannot express the special type that is `TypeNull` and that can only have one value (`null`) so instead we have to use

Re: Floating-Point arithmetic in dlang - Difference to other languages

2019-12-03 Thread mipri via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 09:22:49 UTC, Jan Hönig wrote: Today i have stumbled on Hacker News into: https://0.30004.com/ I am learning D, that's why i have to ask. Why does writefln("%.17f", .1+.2); not evaluate into: 0.30004, like C++ but rather to:

Re: how to implement a function in a different D source file

2019-11-25 Thread mipri via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 03:06:52 UTC, Omar wrote: the page here https://dlang.org/spec/function.html suggests you can implement a function in a different file ... mentioned the endeavour of no-bodied-functions as a way of presenting a black-box type of interface. oh, that's what you

Re: how to implement a function in a different D source file

2019-11-25 Thread mipri via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 03:06:52 UTC, Omar wrote: Hey, I'm very interested in this programming language, I already prefer it to C++ and if only i had adopted it years ago, but that's beside the point. I read a bunch of tuts today and the only thing I'm really stuck on at the moment

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread mipri via Digitalmars-d-learn
On Monday, 25 November 2019 at 12:08:54 UTC, Per Nordlöw wrote: On Monday, 25 November 2019 at 08:22:02 UTC, Jacob Carlborg wrote: On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote: I guess we need a builtin language qualifier for scoped classes for that to work, right? We have

Re: How to wait for a shell process to finish on ctrl+c before exiting?

2019-11-24 Thread mipri via Digitalmars-d-learn
On Sunday, 24 November 2019 at 15:44:00 UTC, aliak wrote: I'm writing some command line tooling stuff, and one of the command spins up a docker compose file (which in short, spins up some services and aggregates the output of each service to stdout). When a user presses ctrl+c, i would like

Re: What is the best way to program over "abstract" types in D?

2019-11-23 Thread mipri via Digitalmars-d-learn
On Saturday, 23 November 2019 at 21:52:40 UTC, Adam D. Ruppe wrote: On Saturday, 23 November 2019 at 20:22:44 UTC, Ola Fosheim Grøstad wrote: I guess it is possible to use introspection somehow? Yeah, you have to write a function that checks it with introspection and then static assert on it

Re: What is the best way to program over "abstract" types in D?

2019-11-23 Thread mipri via Digitalmars-d-learn
On Saturday, 23 November 2019 at 11:21:32 UTC, Ola Fosheim Grøstad wrote: ... I read your question as "can I have typeclasses in D?" I'll refer to typeclasses in a language other than Rust. You don't need to know the language. I think you knowing Rust at all might be clouding your vision,

Re: Spawning a process, then killing it on SIGINT

2019-11-23 Thread mipri via Digitalmars-d-learn
On Saturday, 23 November 2019 at 09:54:48 UTC, aliak wrote: Is there a way to go about killing a process after spawning it on a SIGINT? I can't do this for e.g. because kill is not @nogc. Well, this works: import std; import core.stdc.signal; extern(C) int kill(int pid, int sig) nothrow

Re: How to simulate Window's "Press any key to continue..."

2019-11-21 Thread mipri via Digitalmars-d-learn
On Friday, 22 November 2019 at 04:41:30 UTC, mipri wrote: ~this() { reset(); } Oh, if you don't ever call raw() this will break your terminal. I just copied some code from a toy program and adapted it, and didn't notice that until I posted.

Re: How to simulate Window's "Press any key to continue..."

2019-11-21 Thread mipri via Digitalmars-d-learn
On Friday, 22 November 2019 at 04:22:07 UTC, FireController#1847 wrote: Right, but readln will only wait until the user presses the delimiter (by default Enter/Return). I want it to wait until ANY key is pressed, not a specific key If curses is available you can use it, at the cost of

Re: How to simulate Window's "Press any key to continue..."

2019-11-21 Thread mipri via Digitalmars-d-learn
On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 wrote: I'm an extreme beginner to DLang (just started using it.. oh, an hour ago?), and I already can't figure out a, what I'd consider, fairly simplistic thing. This is my current code: module DTestApp1; import std.stdio;

Re: The effect of ref

2019-11-21 Thread mipri via Digitalmars-d-learn
On Friday, 22 November 2019 at 03:42:26 UTC, dokutoku wrote: Is there a difference in the execution speed and stability when executing the program by rewriting the parameter of the function argument like this? ```d void test1 (int * X) { // some processing } void test2 (ref int X) {

Re: How to get child class Type and members from parent class?

2019-11-20 Thread mipri via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); Here, class A knows that a 'v' member is present. So why not just put that member in

Re: What is the replacement for deprecated array removal

2019-11-18 Thread mipri via Digitalmars-d-learn
On Monday, 18 November 2019 at 21:25:12 UTC, kerdemdemir wrote: It is a bit weird that such a general case like removing list of elements does not work. And I really do not know the real use of [0,1,2,3].remove(1,2,3). I mean in unit test it looks cool but in real life you will have

Re: Strange double to uint conversion

2019-11-18 Thread mipri via Digitalmars-d-learn
On Monday, 18 November 2019 at 21:08:39 UTC, Luiz Silveira wrote: double f; If this is changed to `real f;`, you get the desired result. real is also the type used for the comparison code: https://dlang.org/spec/float.html#fp_const_folding

ints.choice vs. chars.choice

2019-11-18 Thread mipri via Digitalmars-d-learn
Howdy, The following program fails to compile if the second line is uncommented: import std; void main() { writeln([1, 2, 3].choice); //writeln(['a', 'b', 'c'].choice); } Error: template std.random.choice cannot deduce function from argument types !()(char[],

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread mipri via Digitalmars-d-learn
On Wednesday, 13 November 2019 at 14:01:13 UTC, BoQsc wrote: I don't like to see exclamation marks in my code in as weird syntax as these ones: to!ushort(args[1]) s.formattedRead!"%s!%s:%s"(a, b, c); I'd suggest learning to love it, or at least getting to it, vs. to(args[1]) C++ syntax.

Re: Running unittests of a module with -betterC

2019-10-29 Thread mipri via Digitalmars-d-learn
On Monday, 28 October 2019 at 08:51:02 UTC, Daniel Kozak wrote: On Mon, Oct 28, 2019 at 9:40 AM Per Nordlöw via Digitalmars-d-learn wrote: Is it possible to run the unittests of a module with -betterC like dmd -D -g -main -unittest -betterC f.d ? This currently errors as

Re: About the in expression, Why can't use with array.

2019-10-25 Thread mipri via Digitalmars-d-learn
On Friday, 25 October 2019 at 15:52:50 UTC, Paul Backus wrote: On Friday, 25 October 2019 at 09:25:21 UTC, Dennis wrote: I can overload the 'in' operator on my types to something that takes exponential time if I want, just like "+" can also be overloaded to a linear time operation on e.g.

Re: GtkD ListG Howto?

2019-10-11 Thread mipri via Digitalmars-d-learn
On Friday, 11 October 2019 at 19:53:33 UTC, Ron Tarrant wrote: Pixbuf airportImage1, airportImage2, airportImage3, airportImage4; void * image1, image2, image3, image4; airportImage1 = new Pixbuf("images/airport_25.png"); airportImage2 = new Pixbuf("images/airport_35.png"); airportImage3 = new

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread mipri via Digitalmars-d-learn
On Tuesday, 8 October 2019 at 10:48:45 UTC, Jonathan M Davis wrote: The result of this is that code like stack.popBack(); stack ~= foo; stack ~= bar; stack.popBack(); stack ~= baz; will end up allocating all over the place. Every time you append to the array after shrinking it, you're going to

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread mipri via Digitalmars-d-learn
On Monday, 7 October 2019 at 19:16:31 UTC, IGotD- wrote: On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread mipri via Digitalmars-d-learn
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if

Re: Blog Post #75: Cairo X - Noodling with the Mouse

2019-10-04 Thread mipri via Digitalmars-d-learn
On Friday, 4 October 2019 at 20:56:31 UTC, Greatsam4sure wrote: On Tuesday, 1 October 2019 at 09:58:42 UTC, Ron Tarrant wrote: Here's the second installment of the Nodes-n-noodles coverage in which we get the mouse involved: https://gtkdcoding.com/2019/10/01/0075-cairo-x-mouse-noodle.html

Re: What is the extension of ".pdf"

2019-10-04 Thread mipri via Digitalmars-d-learn
On Friday, 4 October 2019 at 19:58:16 UTC, Andre Pany wrote: Hi, I try to solve the puzzle https://www.codingame.com/training/easy/mime-type but have some issue because std.path:extension returns null for file name ".pdf" while the puzzle (test case 3) expects that the extension is ".pdf".

Re: Using algorithms with ranges

2019-10-03 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 08:52:22 UTC, Andrea Fontana wrote: On Thursday, 3 October 2019 at 05:33:04 UTC, mipri wrote: void main() { import std.range : iota; foreach (x; iota(1, 10).withHistory) writeln(x); } This doesn't work as expected, I think. auto r =

Re: Using algorithms with ranges

2019-10-03 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 08:52:22 UTC, Andrea Fontana wrote: On Thursday, 3 October 2019 at 05:33:04 UTC, mipri wrote: void main() { import std.range : iota; foreach (x; iota(1, 10).withHistory) writeln(x); } This doesn't work as expected, I think. auto r =

Re: Using algorithms with ranges

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 05:20:47 UTC, mipri wrote: It'd be nicer to do compose a range over iota, as in iota(1, 10).newThingWithHistory but I don't know how to do that yet. I guess c.f. std.range.retro This is a bit better: #! /usr/bin/env rdmd import std.stdio; auto

Re: Using algorithms with ranges

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:33:10 UTC, Brett wrote: I routinely have to generate data using points sequentially and refer to previous points in the data set, maybe even search them. I also may have to break up the algorithm in to parts. I'd like to get more in to ranges but I simply do

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Thursday, 3 October 2019 at 04:33:26 UTC, Brett wrote: I was trying to avoid such things since X is quite long in name. Not a huge deal... and I do not like the syntax because it looks like a constructor call. It is a constructor call, though. You can define your own as well: #!

Re: Why is it difficult to reference arrays in structs?

2019-10-02 Thread mipri via Digitalmars-d-learn
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() {

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:37:57 UTC, Brett wrote: X y = {3}; works fine. So one has to do x[0] = y; You could initialize x all at once. Complete example: import std.stdio; struct Point { int x, y; string toString() { import std.format : format;

Re: Struct initialization has no effect or error?

2019-10-02 Thread mipri via Digitalmars-d-learn
On Wednesday, 2 October 2019 at 17:54:20 UTC, H. S. Teoh wrote: On Wed, Oct 02, 2019 at 05:37:57PM +, Brett via Digitalmars-d-learn wrote: struct X { int a; } X[1] x; x[0] = {3}; or x[0] = {a:3}; fails; This works: x[0] = X(123); I'd knew I'd gotten the impression from