Why does foreach allow ref element for non-ref front() of std.range.enumerate()

2020-01-26 Thread Boris-Barboris via Digitalmars-d-learn
import std; import std.range; void main() { int[] a = [3, 5, 7]; foreach (i, ref ae; a.enumerate) { writeln(i, " ", ae); ae = 6; } writeln(a); assert(a[].equal([6, 6, 6])); // fails, a is in initial state } Why does the compiler allow such 'ref ae' loop,

Re: Bitfields

2019-05-21 Thread Boris-Barboris via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote: Hi, Has anyone used D to work with arbitrary length bitfields with multiple occurences of a sub-bitfield. I am working with DVB Sections and EIT packets are defined as bitfields with loops in them and the header is 112 bits. The

Re: Tweakig -lowmem to be more eager

2019-05-20 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 19 May 2019 at 23:54:27 UTC, Anonymouse wrote: What makes it decide to collect? What triggers it? You can try setting heapSizeFactor option to something lower than 2 to increase collection frequency:

Re: Linked List iterating over and inserting an element around (before/after) the current position.

2019-05-19 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 19 May 2019 at 22:20:48 UTC, Josh wrote: This is just more curiosity, but do you happen to know why I have to use DList.linearRemove() instead of DList.remove()? These two functions are separate because they differ in complexity. remove is O(1), linearRemove on the other hand

Re: Anonymous mapped regions increases unlimitely on spawn

2018-12-14 Thread Boris-Barboris via Digitalmars-d-learn
On Friday, 14 December 2018 at 21:22:05 UTC, unDEFER wrote: So it looks like a bug, and I have reported about it: https://issues.dlang.org/show_bug.cgi?id=19487 Not an expert, but you may wish to try GC.minimize() (https://dlang.org/phobos/core_memory.html#.GC.minimize).

Re: Can you move a disabled this(this) struct in to a container type if it's an rvalue?

2018-12-13 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 13 December 2018 at 09:51:42 UTC, aliak wrote: Ie: struct S { @disable this(this); this(int i) {} } struct Container(T) { T value; this(T value) { this.value = value; } } void main() { auto a = Container!S(S(3)); // can't do this. } I can build a

Re: Throwing constructors and member destructors

2018-11-20 Thread Boris-Barboris via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov wrote: https://dlang.org/changelog/2.083.0.html#reboot14246 Wording "object" means both classes and structs?

Re: Throwing constructors and member destructors

2018-11-20 Thread Boris-Barboris via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov wrote: https://dlang.org/changelog/2.083.0.html#reboot14246 Nvm, found the info in the issue tracker, thank you for the link.

Throwing constructors and member destructors

2018-11-20 Thread Boris-Barboris via Digitalmars-d-learn
https://run.dlang.io/is/LdylJX Notice no "B destructor" line in stdout. Just got bitten by the assumption that my Buffer struct that transactionally aquires multiple external resources in constructor will rollback via member destructors that were successfully completed before the throw.

Re: custom sorting of lists ?

2018-10-14 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis wrote: Unless there's something about the implementation that's tied to the list itself, I would think that it would make more sense to make it a generic algorithm, then it will work with any non-random-access range, and it avoids

Re: Use nested functions as callbacks with Windows API functions?

2018-10-02 Thread Boris-Barboris via Digitalmars-d-learn
On Monday, 1 October 2018 at 23:07:29 UTC, spikespaz wrote: The problem with the code you have is that the callback needs to be extern (Windows). I don't know how to do that with a "lambda". Neither do I actually. Apparently it is impossible. Best I could squeeze out was this:

Re: Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread Boris-Barboris via Digitalmars-d-learn
On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote: I was hoping I could use something more akin to JavaScript's syntax: (void* hWnd, long) => {}. I tried this but I'm getting errors with the signature, it says the function is a delegate and apparently Windows API can't accept a

Re: Optional parameters?

2018-04-01 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 1 April 2018 at 22:44:45 UTC, Jonathan M Davis wrote: Which doesn't work in @safe code and doesn't work when you have an rvalue as you would when passing 42. Ultimately, using pointers ultimately either requires explicitly allocating stuff on the heap to be able to pass rvalues, or

Re: Optional parameters?

2018-04-01 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 1 April 2018 at 22:25:45 UTC, Jonathan M Davis wrote: How would a pointer help? Instead of doing foo(nullable(42)) he'd have to do foo(new int(42)) which is just one character shorter and ends up allocating on the heap, unlike with Nullable. - Jonathan M Davis foo();

Re: Optional parameters?

2018-04-01 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: I currently have a situation where I want to have a function that accepts a parameter optionally. I would simply use a pointer for this. Fighting D grammar seems too much of a hassle for such simple task.

Re: Fast GC allocation of many small objects

2018-03-31 Thread Boris-Barboris via Digitalmars-d-learn
On Friday, 30 March 2018 at 20:31:35 UTC, Per Nordlöw wrote: Is there a faster way of allocating many small class objects such as... maybe something like this: import std.conv: to; import std.stdio; class Node {} class StrNode : Node { string value; } void main() {

Re: "in" no longer "scope" since 2.079.0?

2018-03-27 Thread Boris-Barboris via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 09:27:07 UTC, Jonathan M Davis wrote: On Tuesday, March 27, 2018 09:15:43 Boris-Barboris via Now that DIP 1000 is being implemented, and scope is actually going to do something for more than just delegates, it was deemed too dangerous to have in suddenly really

"in" no longer "scope" since 2.079.0?

2018-03-27 Thread Boris-Barboris via Digitalmars-d-learn
Hello! Can someone point me to the changelong entry or maybe a pull request, wich changed the "in" from "scope const" to "const"? I thought the previous matter of things was pretty natural, and current "in" is now redundant. Would be glad to read up on this design decision.

Re: opDispatch with string mixin does not work as I would expect.

2018-02-09 Thread Boris-Barboris via Digitalmars-d-learn
On Saturday, 10 February 2018 at 06:32:43 UTC, German Diago wrote: The mixin line does not work. I want to generate the access to the field. How could I achieve that? struct Outer { struct Inner { int a; float b; } Inner i;

Re: Using Postgres connection functions

2018-01-16 Thread Boris-Barboris via Digitalmars-d-learn
On Saturday, 13 January 2018 at 17:58:14 UTC, Joe wrote: ...ddb. The latter perhaps has the distinction that it doesn't use libpq, but rather implements the Postgres FE/BE protocol. That's a bit *too* native for my taste. It means the library maintainer has to keep up with changes to the

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 21:16:40 UTC, Ali Çehreli wrote: And yes, there should be one destructor, which may be a no-op if you grab its resource and set it to null. On all compilers... That's a relief, thank you for your help.

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 20:05:46 UTC, Ali Çehreli wrote: To be complete, 'auto ref' passes lvalues by reference and rvalues by value, which you can detect with __traits(isRef): struct S{ } void foo()(auto ref S s) { static if (__traits(isRef, s)) { pragma(msg, "lvalue");

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote: No time to think about the rest of the design but just to get the code compiled, replace 'ref' with 'auto ref' like so: Ok, looks like this indeed passes rhs by reference, thank you. destcalls - number of times UniquePtr destructor

Re: struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote: No time to think about the rest of the design but just to get the code compiled, replace 'ref' with 'auto ref' like so: this(DT)(scope auto ref UniquePtr!DT rhs) { // ... } Ali i added this static variable:

Re: Dealing with the interior pointers bug

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 19:11:19 UTC, Cym13 wrote: Here it's the programmer's fault really. You should never use casts in normal code, cast is the ultimate switch to say "Look, I know what I'm doing, so disable all safety, don't try to make sense of it, and let me do my thing. If I'm

struct template constructors

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
Hi https://dpaste.dzfl.pl/0def4e286564 Is there a cleaner way to go than the one on the line 26? And why is the constructor /d475/f781.d(37): f781.UniquePtr!(A).UniquePtr.__ctor(DT)(ref scope UniquePtr!DT rhs) unfit for line 51? Is it because the expression " = UniquePtr!B.make()" cannot

Re: Dealing with the interior pointers bug

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 13:56:29 UTC, ag0aep6g wrote: For example, the type system guarantees that immutable data never changes. But the compiler allows you to cast from immutable to mutable and change the data. It's an invalid operation, but the compiler is not expected to catch that for

Re: Dealing with the interior pointers bug

2017-06-22 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 22 June 2017 at 09:45:09 UTC, Russel Winder wrote: I think the term "systems programming language" contains no actual data, so needs to be retired. In this situation it provides no reason for conservative garbage collection. It means the intent of language designer to let you

Re: D structs weak identity and RAII

2017-06-19 Thread Boris-Barboris via Digitalmars-d-learn
On Monday, 19 June 2017 at 06:34:49 UTC, Ali Çehreli wrote: It's unreliable because structs are value types in D, which means that they can be moved around freely. This is why self-referencing structs are illegal in D. I guess it's more like the spec states, that they can be moved vithout

D structs weak identity and RAII

2017-06-18 Thread Boris-Barboris via Digitalmars-d-learn
Hello, I was trying to write some templated unique pointers. Idea was simple: struct UniquePointer that handles underlying pointer in RAII-style and WeakPointer struct that is spawned by UniquePointer. Weak pointer is handled differently in my collections, wich subscribe to the event of

Re: DList efficiency

2017-06-08 Thread Boris-Barboris via Digitalmars-d-learn
On Thursday, 8 June 2017 at 22:42:14 UTC, Boris-Barboris wrote: 1). Do I understand correctly, that there is currently no way (aside from editing the sources of course) to efficiently (using one underlying iteration) remove all\first element(s) from DList based on a predicate? Oh, sorry, I

DList efficiency

2017-06-08 Thread Boris-Barboris via Digitalmars-d-learn
Good day to you reader! I have a couple questions about Phobos: 1). Do I understand correctly, that there is currently no way (aside from editing the sources of course) to efficiently (using one underlying iteration) remove all\first element(s) from DList based on a predicate? Can such

Re: protected behaviour on base class member access from another module

2017-04-30 Thread Boris-Barboris via Digitalmars-d-learn
Ok, sorry, look's like that was always the case in C++, so it's too late to question it. I'll just elevate it to package, I guess.

protected behaviour on base class member access from another module

2017-04-30 Thread Boris-Barboris via Digitalmars-d-learn
Hi! I have a base class in module A: module A; ... class GuiElement: GuiComponent { protected { GuiElement _parent; ... } template isGuiElement(T) { enum isGuiElement = is(T: GuiElement); } ... and derived class in module B: module B; ... class Div(uint dim, uint odim):

Re: strange CFTE issue

2017-04-09 Thread Boris-Barboris via Digitalmars-d-learn
On Sunday, 9 April 2017 at 16:44:41 UTC, ag0aep6g wrote: Or you can make it a template value parameter [2] with type `string[]`: string[] sfilter(T, string[] fields)() { string[] result; foreach (f; aliasSeqOf!fields) { /* ... loop body as you have it ... */ }

Re: strange CFTE issue

2017-04-09 Thread Boris-Barboris via Digitalmars-d-learn
On Wednesday, 15 March 2017 at 17:27:35 UTC, ag0aep6g wrote: Phobos has it: std.meta.aliasSeqOf "converts an input range [...] to an alias sequence." [1] Woops, forgot to give the URL for that "[1]". Here it is: http://dlang.org/phobos/std_meta.html#aliasSeqOf Hello, I have a similar