Alloca copy: What's _pastdata?

2018-04-02 Thread ARaspiK via Digitalmars-d-learn
I'm creating a minimal DRuntime (for messing around). Right now, I have a very basic program that doesn't even link to the C runtime, and uses syscalls for everything. I'm trying to implement alloca so that I can parse arguments (long story), and so I went to druntime/src/rt/alloca.d. Everyth

Re: Optional parameters?

2018-04-02 Thread Timoses 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 thought maybe Nullable!int might work: void foo(Nullable!int) {} void main() { foo(1); // error int x; foo(x); // e

Re: Optional parameters?

2018-04-02 Thread Cym13 via Digitalmars-d-learn
On Monday, 2 April 2018 at 09:31:35 UTC, Timoses wrote: 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 thought maybe Nullable!int might work: void foo(Nullable!int) {} vo

Constructor qualifiers; bug or expected behavior?

2018-04-02 Thread RazvanN via Digitalmars-d-learn
Hi all, Let's say we have this code: struct B { int a; this(int a) immutable { this.a = 7; } this(int a) { this.a = 10; } } void main() { B a = immutable B(2); writeln(a.a); a.a = 4; immutable B a2 = immutable B(3); writeln(a2.a)

Re: Constructor qualifiers; bug or expected behavior?

2018-04-02 Thread Eduard Staniloiu via Digitalmars-d-learn
On Monday, 2 April 2018 at 10:26:32 UTC, RazvanN wrote: Hi all, Let's say we have this code: struct B { int a; this(int a) immutable { this.a = 7; } this(int a) { this.a = 10; } } void main() { B a = immutable B(2); writeln(a.a); a.a = 4

Re: Constructor qualifiers; bug or expected behavior?

2018-04-02 Thread Seb via Digitalmars-d-learn
On Monday, 2 April 2018 at 11:41:55 UTC, Eduard Staniloiu wrote: On Monday, 2 April 2018 at 10:26:32 UTC, RazvanN wrote: [...] The compiler does an implicit conversion from the type `immutable B` to the type `B`. It is able to do safely do so because `struct B` has only value types that can

Re: Optional parameters?

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/18 12:00 PM, Jacob Carlborg wrote: Yeah, D doesn't allow user defined implicit conversions, which I think is required for this. I would make function overloading even more complex than it is today. Although it would be really handy for cases like this. Not necessarily implicit con

Re: Optional parameters?

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/2/18 5:31 AM, Timoses wrote: 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 thought maybe Nullable!int might work: void foo(Nullable!int) {} void main() {    foo(1);

Re: Optional parameters?

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/18 6:01 PM, Jonathan M Davis wrote: On Sunday, April 01, 2018 11:54:16 Steven Schveighoffer via Digitalmars-d- learn wrote: I currently have a situation where I want to have a function that accepts a parameter optionally. I thought maybe Nullable!int might work: void foo(Nullable!int) {

@property for simple methods?

2018-04-02 Thread Vladimirs Nordholm via Digitalmars-d-learn
Heyo. I have a struct with a couple "property" methods, like: struct A { auto foo(int bar) { /* do something */ } } Is there any reason for me to add the @property tags for the method? The following code compiles just fine with the struct above A a = A(); a.foo =

Re: @property for simple methods?

2018-04-02 Thread Dennis via Digitalmars-d-learn
On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag does can be found here: https://dlang.org/spec/function.html#property-functions This behavior is particularly useful for ge

How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-02 Thread Per Nordlöw via Digitalmars-d-learn
As a follow-up to https://forum.dlang.org/post/jfgpngdudtprzznrc...@forum.dlang.org I managed to put together the benchmark https://github.com/nordlow/phobos-next/blob/fa3526b15c746bda50a195f4e492ab2de9c15287/benchmarks/allocators/source/app.d which run (via ldc) dub run --build=release-nobou

Re: @property for simple methods?

2018-04-02 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:20:49 UTC, Dennis wrote: On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag does can be found here: https://dlang.org/spec/function.html#propert

Re: @property for simple methods?

2018-04-02 Thread Seb via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: On Monday, 2 April 2018 at 14:20:49 UTC, Dennis wrote: On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag

Re: @property for simple methods?

2018-04-02 Thread Dennis via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ? You're probably fine either way, it's mostly for making your intention clear. Jonathan M Davis made a great e

Re: Constructor qualifiers; bug or expected behavior?

2018-04-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 02, 2018 at 10:26:32AM +, RazvanN via Digitalmars-d-learn wrote: > Hi all, > > Let's say we have this code: > > struct B > { > int a; > this(int a) immutable > { > this.a = 7; > } > > this(int a) > { > this.a = 10; > } > } > > void mai

Re: Fast GC allocation of many small objects

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/18 4:31 PM, Per Nordlöw wrote: I'm working on a graph database with tens of millions of small nodes containing typically around 8-64 bytes of member data. Is there a faster way of allocating many small class objects such as class Node {     // abstract members } class StrNode : Node

Re: Fix transposed ranges

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/30/18 4:45 PM, Cym13 wrote: On Friday, 30 March 2018 at 20:43:09 UTC, Cym13 wrote: Hi, I've got the following code that takes a list of files as argument and xor them together (demo example sufficient for that discussion). [...] Forgot to mention but I'm also quite annoyed at the need f

Re: Fast GC allocation of many small objects

2018-04-02 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 2 April 2018 at 18:22:43 UTC, Steven Schveighoffer wrote: You may be interested in this proposal, which was inspired by trying to implement a reserve feature for AAs (requires a similar mechanism). https://issues.dlang.org/show_bug.cgi?id=17881 Ok, thanks. I'll push for it. One

Re: Fast GC allocation of many small objects

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/2/18 2:51 PM, Per Nordlöw wrote: On Monday, 2 April 2018 at 18:22:43 UTC, Steven Schveighoffer wrote: You may be interested in this proposal, which was inspired by trying to implement a reserve feature for AAs (requires a similar mechanism). https://issues.dlang.org/show_bug.cgi?id=17881

Re: Fix transposed ranges

2018-04-02 Thread Cym13 via Digitalmars-d-learn
On Monday, 2 April 2018 at 18:33:25 UTC, Steven Schveighoffer wrote: On 3/30/18 4:45 PM, Cym13 wrote: On Friday, 30 March 2018 at 20:43:09 UTC, Cym13 wrote: Hi, I've got the following code that takes a list of files as argument and xor them together (demo example sufficient for that discussion

Re: Fix transposed ranges

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/2/18 3:24 PM, Cym13 wrote: On Monday, 2 April 2018 at 18:33:25 UTC, Steven Schveighoffer wrote: On 3/30/18 4:45 PM, Cym13 wrote: On Friday, 30 March 2018 at 20:43:09 UTC, Cym13 wrote: Hi, I've got the following code that takes a list of files as argument and xor them together (demo exampl

Re: Fix transposed ranges

2018-04-02 Thread Cym13 via Digitalmars-d-learn
On Monday, 2 April 2018 at 19:45:31 UTC, Steven Schveighoffer wrote: On 4/2/18 3:24 PM, Cym13 wrote: [...] Well, it's tough, because you can compose ranges in infinite ways. All you need to generate the warning is some code like this: [...] That makes sense, thanks.

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-02 Thread Alexandru Jercaianu via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:52:34 UTC, Per Nordlöw wrote: As a follow-up to https://forum.dlang.org/post/jfgpngdudtprzznrc...@forum.dlang.org [...] Hi, I am not completely sure how to solve this, but maybe we can find some clues here [1]. It seems like we should use addRoot on the buffer

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-02 Thread Per Nordlöw via Digitalmars-d-learn
On Monday, 2 April 2018 at 20:43:01 UTC, Alexandru Jercaianu wrote: I am not completely sure how to solve this, but maybe we can find some clues here [1]. It seems like we should use addRoot on the buffer returned by GC.instance.allocate to keep it alive. Then, we can use addRange on each node a

Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/2/18 5:16 PM, Per Nordlöw wrote: On Monday, 2 April 2018 at 20:43:01 UTC, Alexandru Jercaianu wrote: I am not completely sure how to solve this, but maybe we can find some clues here [1]. It seems like we should use addRoot on the buffer returned by GC.instance.allocate to keep it alive. T

Re: Reactive data

2018-04-02 Thread crimaniak via Digitalmars-d-learn
On Saturday, 31 March 2018 at 16:08:36 UTC, lempiji wrote: --- import rx; auto firstWord = new BehaviorSubject!string("Change"); auto secondWord = new BehaviorSubject!string("me!"); auto bothWords = new BehaviorSubject!string(""); combineLatest!((a, b) => a ~ " " ~ b)(firstWord, seco

What is the equivalent of C++'s std::optional and std::nullopt in D?

2018-04-02 Thread helxi via Digitalmars-d-learn
For reference: https://en.cppreference.com/w/cpp/utility/optional

Re: What is the equivalent of C++'s std::optional and std::nullopt in D?

2018-04-02 Thread Uknown via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:10:09 UTC, helxi wrote: For reference: https://en.cppreference.com/w/cpp/utility/optional Nullable!T would be the closest thing: https://dlang.org/phobos/std_typecons.html#Nullable I'm not sure how comparable they are though.

Why toUTF8 not accept wchar[] as argument?

2018-04-02 Thread Domain via Digitalmars-d-learn
wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are: /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713): `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEnco

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-02 Thread Uknown via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote: On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote: wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are: /dlang/dmd/linux/bin64/../../src/phob

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-02 Thread Uknown via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote: wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are: /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713): `std.utf.toUTF8(S)(S s) if (is

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-02 Thread Domain via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote: On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote: wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are: /dlang/dmd/linux/bin64/../../src/phob

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-02 Thread bauss via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:46:51 UTC, Domain wrote: On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote: On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote: wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])

Re: Why toUTF8 not accept wchar[] as argument?

2018-04-02 Thread Seb via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 02:46:51 UTC, Domain wrote: On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote: On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote: wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])