Re: Remove elements without losing capacity

2022-10-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/4/22 11:22 AM, Riccardo M wrote: Is it possible to remove elements from a range without losing its capacity? ``` void main() {     import std.algorithm.mutation : remove, SwapStrategy;     import std.stdio : writeln;     int[] arr = [1, 2, 3, 2, 4, 2, 5, 2];     assert(arr.length == 8

Re: Remove elements without losing capacity

2022-10-04 Thread Riccardo M via Digitalmars-d-learn
On Tuesday, 4 October 2022 at 15:42:21 UTC, Steven Schveighoffer wrote: Yes, you use `assumeSafeAppend`: ```d arr.length--; arr.assumeSafeAppend; assert(arr.capacity != 0); ``` Now, I want to clarify that you should only use this if you are sure you are done with the data you removed at the en

Connecting to D-Bus signals

2022-10-04 Thread Olivier Pisano via Digitalmars-d-learn
Hi, I am currently trying to connect to a signal on UDisks2 to be notified whenever the user plugs a USB drive on the system, but my method never gets called. Here is my code : import ddbus; import ddbus.c_lib; import std.stdio; final class UsbDevice { void onIn

Re: Remove elements without losing capacity

2022-10-04 Thread Ali Çehreli via Digitalmars-d-learn
On 10/4/22 10:59, Riccardo M wrote: > The inherent reason for `remove` to cancel previous capacity and > requiring new allocations is exactly to prevent overwriting data that > could be owned by something else? Yes. A related topic is how the "end slice" never loses that capacity: void main()

Re: Visual D doesn't work, now Visual Studio Code / D doesn't work!!!! ....

2022-10-04 Thread Alain De Vos via Digitalmars-d-learn
why not try neovim.

Re: Stop writeln from calling object destructor

2022-10-04 Thread data pulverizer via Digitalmars-d-learn
On Monday, 3 October 2022 at 11:08:00 UTC, Steven Schveighoffer wrote: On 10/2/22 12:21 PM, data pulverizer wrote: I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It has become a very serious problem when workin

Re: rotate left an array

2022-10-04 Thread Christian Köstlin via Digitalmars-d-learn
If you are ok with using things from std.range you could use something like this: ```d import std.range : cycle, drop, take; import std.stdio : writeln; int main(string[] args) { auto r = [1, 2, 3, 4, 5, 6, 7, 8]; writeln(r.cycle.drop(3).take(r.length)); return 0; } ``` Kind regar

Re: Remove elements without losing capacity

2022-10-04 Thread Riccardo M via Digitalmars-d-learn
On Tuesday, 4 October 2022 at 18:18:41 UTC, Ali Çehreli wrote: On 10/4/22 10:59, Riccardo M wrote: > The inherent reason for `remove` to cancel previous capacity and > requiring new allocations is exactly to prevent overwriting data that > could be owned by something else? Yes. A related topic