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

2018-04-07 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 7 April 2018 at 07:50:37 UTC, Eduard Staniloiu wrote: On Friday, 6 April 2018 at 21:49:37 UTC, Per Nordlöw wrote: On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu wrote: So, say `reg` is your allocator, your workflow would be auto obj = reg.make!Type(args); /* do stuff

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

2018-04-06 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu wrote: So, say `reg` is your allocator, your workflow would be auto obj = reg.make!Type(args); /* do stuff */ reg.dispose(obj); // If Type has a __dtor, it will call obj.__dtor // and then reg.deallocate(obj) If I

Re: DIP 1009 (Add Expression-Based Contract Syntax) Accepted

2018-04-06 Thread Per Nordlöw via Digitalmars-d-announce
On Friday, 6 April 2018 at 12:26:36 UTC, Mike Parker wrote: Congratulations to Zach Tollen and everyone who worked on DIP 1009. It took a painful amount of time to get it through the process, but it had finally come out of the other side with an approval. The proposal itself was approved early

Making emplaceRef public

2018-04-06 Thread Per Nordlöw via Digitalmars-d-learn
Why isn't `std.conv.emplaceRef` public when `std.conv.emplace` is? AFAICT, emplaceRef(x, ...) is a bit more @safe than emplace(, ...) ...

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

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

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

Re: Could someone take a look at DIP PR 109?

2018-04-02 Thread Per Nordlöw via Digitalmars-d
On Wednesday, 28 March 2018 at 06:43:15 UTC, Shachar Shemesh wrote: https://github.com/dlang/DIPs/pull/109 I submitted it 12 days ago. So far, except for two thumbs up, I got no official reaction of any kind for it. I did get an unofficial list of suggestions from Andrei, which I have now

Re: newCTFE Status March 2018

2018-04-01 Thread Nordlöw via Digitalmars-d
On Sunday, 1 April 2018 at 18:32:00 UTC, Stefan Koch wrote: On Sunday, 1 April 2018 at 16:48:32 UTC, Per Nordlöw wrote: [...] Oh I was not aware people would try this :) I have fixed the build please pull. Thanks!

Re: Fast GC allocation of many small objects

2018-04-01 Thread Per Nordlöw via Digitalmars-d-learn
On Sunday, 1 April 2018 at 10:59:55 UTC, Alexandru jercaianu wrote: On Saturday, 31 March 2018 at 20:17:26 UTC, Per Nordlöw wrote: On Friday, 30 March 2018 at 23:09:33 UTC, Alexandru Jercaianu wrote: Hello, You can try the following: struct Node { char[64] arr; }

Re: newCTFE Status March 2018

2018-04-01 Thread Per Nordlöw via Digitalmars-d
On Friday, 30 March 2018 at 20:46:32 UTC, Stefan Koch wrote: 85 to 90% maybe. I expect that there will many bugs which were hidden by newCTFE not supporting classes, which will now be out in the open and have to be dealt with. Also the code is in need of cleanup before I would release it for

Re: Deprecating this(this)

2018-04-01 Thread Per Nordlöw via Digitalmars-d
On Sunday, 1 April 2018 at 01:56:40 UTC, Jonathan M Davis wrote: Another potential issue is whether any of this does or should relate to https://github.com/dlang/DIPs/pull/109 and it's solution for hooking into to moves. I'm not at all sure that what happens with that needs to be related to

Re: Fast GC allocation of many small objects

2018-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 31 March 2018 at 20:17:26 UTC, Per Nordlöw wrote: auto reg = Region!(NullAllocator, 16)(cast(ubyte[])buf); Thanks! Turns out that Region allocator wasn't fully qualified: https://github.com/dlang/phobos/pull/6400 This will make it possible to allocate with it in pure code

Re: Fast GC allocation of many small objects

2018-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 30 March 2018 at 23:09:33 UTC, Alexandru Jercaianu wrote: Hello, You can try the following: struct Node { char[64] arr; } enum numNodes = 100_000_000; void[] buf = GCAllocator.instance.allocate(numNodes * Node.sizeof); auto reg =

Re: Fast GC allocation of many small objects

2018-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 31 March 2018 at 19:31:37 UTC, Rubn wrote: Be willing to change your code, the allocator can change at any point. What you implement today may not work tomorrow, what you fix to work for tomorrow may not end up working the next day (in terms of releases). That really should be

Re: Fast GC allocation of many small objects

2018-03-30 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 30 March 2018 at 20:38:35 UTC, rikki cattermole wrote: Use a custom allocator (that could be backed by the GC) using std.experimental.allocators :) https://dlang.org/phobos/std_experimental_allocator.html is massive. I guess I should allocate my nodes using auto node =

Fast GC allocation of many small objects

2018-03-30 Thread Per Nordlöw via Digitalmars-d-learn
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 { string value; } // more

Re: newCTFE Status March 2018

2018-03-30 Thread Per Nordlöw via Digitalmars-d
On Friday, 30 March 2018 at 19:48:02 UTC, Stefan Koch wrote: Have a nice easter. Stefan Great, then there's hope.

Re: Checking if a structs .init value is zero bits only

2018-03-28 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 01:39:40 UTC, Seb wrote: Have a look at: https://github.com/dlang/phobos/pull/6024 (review/feedbackon this PR is welcome!) Exactly what I wanted. Thanks! In use here

Re: Checking if a structs .init value is zero bits only

2018-03-28 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 00:50:31 UTC, Ali Çehreli wrote: On 03/27/2018 05:15 PM, Per Nordlöw wrote: Is there a way to check if a struct `S` can be initialized using zero bits only, so that we can allocate and initialize an array of `S` in one go using `calloc`? If not, what should such

Checking if a structs .init value is zero bits only

2018-03-27 Thread Per Nordlöw via Digitalmars-d-learn
Is there a way to check if a struct `S` can be initialized using zero bits only, so that we can allocate and initialize an array of `S` in one go using `calloc`? If not, what should such a trait look like?

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-27 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 22:00:42 UTC, Johan Engelen wrote: Indeed. Please try to manually link first (without dub) by modifying the command on which dub errors: ``` ldmd2 -flto=thin

Re: Truly automatic benchmarking

2018-03-27 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 08:41:41 UTC, bauss wrote: Perhaps https://dlang.org/phobos/std_datetime_stopwatch.html#benchmark ? That fulfils neither of my two requirements mentioned in above; it requires explicit iteration count given by the caller and no automatic printing of results.

Truly automatic benchmarking

2018-03-27 Thread Nordlöw via Digitalmars-d-learn
Have anybody implemented anything near the expressiveness and ease of use of Rust's builtin benchmarking features https://doc.rust-lang.org/1.16.0/book/benchmark-tests.html I'm mostly interested in completely automatic printing of results such as test tests::bench_add_two ... bench:

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 22:13:02 UTC, Johan Engelen wrote: On Monday, 26 March 2018 at 22:07:49 UTC, Nordlöw wrote: When I try build my application using LDC and -flto=thin it fails in the final linking You must also pass `-flto=thin` during linking (a special plugin is needed for LTO,

Building application with LDC and -flto=thin fails in link stage

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
When I try build my application using LDC and -flto=thin it fails in the final linking as ldmd2 -of.dub/build/application-release-nobounds-lto-linux.posix-x86_64-ldc_2078-9FDE475789CA2E324E9DAE6A959C2B7F/knetquery

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 21:11:12 UTC, jmh530 wrote: Is each optimization level `x` in `-Ox` defined in the same way for clang and ldc? If so, where's the best documentation for it? https://wiki.dlang.org/Using_LDC Thx!

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 16:02:30 UTC, Rene Zwanenburg wrote: On Sunday, 25 March 2018 at 22:09:43 UTC, Nordlöw wrote: eventhough I compile with -release -inline -nobounds flags. Just to make sure: are you passing -O as well? Yes I am, thanks, via the dub spec buildType

Re: Homebuilt dmd fails to link my dub application

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 10:57:28 UTC, Seb wrote: It doesn't add -noboundscheck by default. Typically the Makefiles allow passing an initial DFLAG variable, but that one doesn't seem to allow it, so I just submitted a PR to do so (https://github.com/dlang/dmd/pull/8089). With this PR you

Re: Homebuilt dmd fails to link my dub application

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 25 March 2018 at 20:35:01 UTC, Seb wrote: For building everything locally, it should be as easy as: --- git clone https://github.com/dlang/dmd git clone https://github.com/dlang/druntime git clone https://github.com/dlang/phobos cd phobos && make -f posix.mak -j10 How do I build a

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 25 March 2018 at 22:30:50 UTC, kinke wrote: void foo() { version(LDC) pragma(inline, true); // affects foo() ... } Wonderful, thanks!

Aggressive conditional inlining with ldc only, not dmd

2018-03-25 Thread Nordlöw via Digitalmars-d-learn
Is there a way to make ldc do more aggressive inlining other than pragma(inline, true) ? Reason for asking is that https://github.com/nordlow/phobos-next/blob/master/src/open_hashmap_or_hashset.d achieves much better performance when I qualify some inner loop functions with

Re: Homebuilt dmd fails to link my dub application

2018-03-25 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 25 March 2018 at 18:43:09 UTC, Seb wrote: Are you on a 32-bit system? (For 64-bit -fPIC is the default since 2.072.2 - though DMD's build scripts were only updated a few releases later) No, I have my own build script for dmd, though because I can't get Digger to work either.

Homebuilt dmd fails to link my dub application

2018-03-25 Thread Nordlöw via Digitalmars-d-learn
If my homebuilt dmd fails to build my dub project with message /usr/bin/ld: error: .dub/build/application-unittest-linux.posix-x86_64-dmd_2079-C9019ECA621321CC168B385F53D82831/knetquery.o: requires dynamic R_X86_64_32 reloc against '_D6object9Throwable7__ClassZ' which may overflow at runtime;

Re: Checking if a flag was passed to the compiler

2018-03-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 March 2018 at 14:58:56 UTC, Seb wrote: For reference and completeness, a simple example: ```d void main() { enum isDIP1000 = __traits(compiles, () @safe { int x; int* p; p = }); pragma(msg, isDIP1000); } ``` normal:

Re: D, Parasail, Pascal, and Rust vs The Steelman

2018-03-22 Thread Per Nordlöw via Digitalmars-d
On Thursday, 22 March 2018 at 11:16:37 UTC, Atila Neves wrote: I wonder how they concluded that. Atila I too.

Checking if a flag was passed to the compiler

2018-03-22 Thread Nordlöw via Digitalmars-d-learn
Is there a way to check in code whether a specific flag, -dip1000 in my case, was passed to the compiler?

Re: Do we need Mat, Vec, TMmat, Diag, Sym and other matrix types?

2018-03-20 Thread Nordlöw via Digitalmars-d
On Tuesday, 13 March 2018 at 03:37:36 UTC, 9il wrote: I have a lot of work for next months, but looking for a good opportunity to make Mat happen. Sounds great. In which repo will these changes happen?

When is copy assignment @safe to use when the left-hand-side is an undefined l-value?

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
Given an uninitialized (undefined content from, for instance, malloc) value `x` of type `T`, when is it @safe to initalize `x` with a simple assignment such as x = y in contrast to emplace(, y); ? My current guess is when hasElaborateCopyConstructor!T is `false`. Is this

Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 March 2018 at 20:39:33 UTC, Andrei Alexandrescu wrote: My knee-jerk reaction is that's a rather peculiar primitive to add to the standard library. -- Andrei I'm needing it for variadic equal...I'll put it as a private member in `equal`s template declaration for now.

Shouldn't pureMalloc be @system instead of @trusted?

2018-03-16 Thread Nordlöw via Digitalmars-d
Shouldn't `pureMalloc` at https://dlang.org/library/core/memory/pure_malloc.html be @system instead of @trusted? Because it returns uninitialized memory just like T x = void; does, which is not allowed in @safe code.

Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 10 March 2018 at 21:31:41 UTC, ag0aep6g wrote: auto forwardMap(alias fun, Ts ...)(Ts things) { import std.meta: aliasSeqOf, staticMap; import std.range: iota; import std.typecons: Tuple; alias NewType(size_t i) = typeof(fun(things[i])); alias NewTypes =

Re: Short-circuit range counting algorithm?

2018-03-16 Thread Nordlöw via Digitalmars-d
On Friday, 16 March 2018 at 17:41:22 UTC, H. S. Teoh wrote: Given a forward range r, I want to test whether it has exactly n elements that satisfy some given predicate pred. Is it possible to do this using current Phobos algorithms such that it does not traverse more members of the range than

Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 10 March 2018 at 21:31:41 UTC, ag0aep6g wrote: Not tested beyond `f(1, 2.3, "foo")`: auto forwardMap(alias fun, Ts ...)(Ts things) { import std.meta: aliasSeqOf, staticMap; import std.range: iota; import std.typecons: Tuple; alias NewType(size_t i) =

Re: List of language deprecations

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 March 2018 at 16:01:18 UTC, Steven Schveighoffer wrote: https://dlang.org/deprecate.html Thanks!

List of language deprecations

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
Is there a list of language deprecations? I want to show my codings fellows how strong and modern D's view on deprecations are.

Re: dmd -unittest= (same syntax as -i)

2018-03-15 Thread Nordlöw via Digitalmars-d
On Wednesday, 14 March 2018 at 21:22:01 UTC, Timothee Cour wrote: would a PR for `dmd -unittest= (same syntax as -i)` be welcome? wouldn't that avoid all the complicatiosn with version(StdUnittest) ? eg use case: # compile with unittests just for package foo (excluding subpackage foo.bar)

Re: Using Address Sanitizer in LDC

2018-03-13 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 15:12:02 UTC, Nordlöw wrote: Can I use address sanitizer (ASan) in LDC 1.8 to find use of uninitialized memory in, in my case, a set of containers, currently https://github.com/nordlow/phobos-next/blob/master/src/open_hashmap_or_hashset.d If so, what arguments

Using Address Sanitizer in LDC

2018-03-13 Thread Nordlöw via Digitalmars-d-learn
Can I use address sanitizer (ASan) in LDC 1.8 to find use of uninitialized memory in, in my case, a set of containers, currently https://github.com/nordlow/phobos-next/blob/master/src/open_hashmap_or_hashset.d If so, what arguments should I feed to ldc2's -fsanitize=

Forwarding arguments through a std.algorithm.map

2018-03-10 Thread Nordlöw via Digitalmars-d-learn
If I have a function bool f(Rs...)(Rs rs) is it somehow possible to map and forward all its arguments `rs` to another function bool g(Rs...)(Rs rs); through a call to some map-and-forward-like-function `forwardMap` in something like bool f(Rs...)(Rs rs) { alias

Re: Making recursively-defined traits iterative using `static foreach`

2018-03-10 Thread Nordlöw via Digitalmars-d
On Saturday, 10 March 2018 at 18:26:48 UTC, Simen Kjærås wrote: Is there a way to break the `static foreach` loop prematurely as quickly as `allSameTypeIterative` becomes false? Sure: @property bool allSameTypeIterative(V...)() //if (allSatisfy!(isType, V)) { foreach (Vi; V) if

Re: Making recursively-defined traits iterative using `static foreach`

2018-03-10 Thread Nordlöw via Digitalmars-d
On Saturday, 10 March 2018 at 13:30:18 UTC, Nordlöw wrote: On Saturday, 10 March 2018 at 09:47:55 UTC, Nordlöw wrote: Now that we have `static foreach` I just realized we can start... My recent definition now looks like template allSameTypeIterative(V...) // TODO restrict `V` to types only {

Re: Making recursively-defined traits iterative using `static foreach`

2018-03-10 Thread Nordlöw via Digitalmars-d
On Saturday, 10 March 2018 at 09:47:55 UTC, Nordlöw wrote: Now that we have `static foreach` I just realized we can start... My recent definition now looks like template allSameTypeIterative(V...) // TODO restrict `V` to types only { static if (V.length <= 1) { enum

Re: Compile-time variadic equality

2018-03-10 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 10 March 2018 at 08:49:19 UTC, Nordlöw wrote: How do I most conveniently merge these into one single `allSame` that can operate on mixtures of values and types? I found the privately defined `isSame` in std.meta that does this.

Re: dpldocs now has cross-package search (experimental)

2018-03-10 Thread Nordlöw via Digitalmars-d-announce
On Saturday, 10 March 2018 at 00:09:18 UTC, Adam D. Ruppe wrote: Looking for http libs? Behold: http://search.dpldocs.info/?q=http Nice!

Re: Making recursively-defined traits iterative using `static foreach`

2018-03-10 Thread Nordlöw via Digitalmars-d
On Saturday, 10 March 2018 at 09:47:55 UTC, Nordlöw wrote: static if (V[0] != Vi) { enum allSameIterative = false; } Perhaps even better to do static if (!is(typeof(allSameIterative) == bool) && // not yet defined

Making recursively-defined traits iterative using `static foreach`

2018-03-10 Thread Nordlöw via Digitalmars-d
Now that we have `static foreach` I just realized we can start making recursive implementations of traits such as template allSame(V...) if (isExpressions!V) { static if (V.length <= 1) { enum allSame = true; } else static if (V.length & 1) // odd count {

Re: Compile-time variadic equality

2018-03-10 Thread Nordlöw via Digitalmars-d-learn
On Friday, 9 March 2018 at 22:13:39 UTC, Simen Kjærås wrote: static if (allEqual!(staticMap!(ElementEncodingType, Rs))) { // compare Rs byCodeUnit } NoDuplicates!V.length == 1 BTW, `NoDuplicates` can handle both types and values (mixed) opposite to my `allSame` and `allSameType` defined

Re: Compile-time variadic equality

2018-03-09 Thread Nordlöw via Digitalmars-d-learn
On Friday, 9 March 2018 at 19:24:03 UTC, Nordlöw wrote: I'm looking for a function (that probably should be placed in std.meta) named something like `areEqual` that checks whether all it's arguments are equal or not. Is there such as function already in Phobos? My usage is static if

Compile-time variadic equality

2018-03-09 Thread Nordlöw via Digitalmars-d-learn
I'm looking for a function (that probably should be placed in std.meta) named something like `areEqual` that checks whether all it's arguments are equal or not. Is there such as function already in Phobos? My usage is static if (allEqual!(staticMap!(ElementEncodingType, Rs))) { //

Preffered way of writing variadic templated functions in 2.079

2018-03-08 Thread Nordlöw via Digitalmars-d-learn
Is using https://dlang.org/changelog/2.079.0.html#default_after_variadic for instance as void show(Args...)(Args args, string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__) if (Args.length >= 1) { ... }

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Nordlöw via Digitalmars-d-learn
On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer?

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Nordlöw via Digitalmars-d-learn
On Monday, 5 March 2018 at 12:41:06 UTC, Steven Schveighoffer wrote: pragma(inline, true) C lazyDeleted() pure nothrow @trusted { return cast(C)((cast(size_t*)null) + 1); } I still can't evaluate at compile-though... enum holeKeyOffset = 0x1; pragma(inline, true)

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Thanks, how do I store it as enum or static immutable struct member? In @trusted pure unittest { class C { int value; } C x; C y =

Fastest way to zero a slice of memory

2018-03-04 Thread Nordlöw via Digitalmars-d-learn
When zeroing a slice of memory (either stack or heap) such as enum n = 100; ubyte[n] chunk; should I use `memset` such as memset(chunk.ptr, 0, n/2); // zero first half or an array assignment such as chunk[0 .. n/2] = 0; // zero first half or are they equivalent in release

Re: Validity of cast(void*)size_t.max

2018-03-02 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Is this preferred performance-wise over `cast(void*)(size_t.max)`?

Re: Validity of cast(void*)size_t.max

2018-02-28 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 20:14:01 UTC, Ali Çehreli wrote: And to be sure, one can have an actual object that represents nullness and use its pointer. (Similar to "the null object pattern".) Ali Are there any pros to this pattern compared to just using `null` in D?

Re: Validity of cast(void*)size_t.max

2018-02-27 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? -Steve It's already used to indicate that a slot is free. :)

Validity of cast(void*)size_t.max

2018-02-27 Thread Nordlöw via Digitalmars-d-learn
Is `cast(void*)size_t.max` always an invalid address? Is so, could it be used to indicate removed/delete elements in hash tables with open addressing and a key type being either a pointer or class? And will it work correctly with the GC?

Size threshold replace complex probing with linear search for small hash tables

2018-02-19 Thread Nordlöw via Digitalmars-d-learn
I'm currently developing a combined HashMap and HashSet with open addressing at https://github.com/nordlow/phobos-next/blob/master/src/open_hashmap_or_hashset.d with probing using steps of triangular numbers when length is a power of two at

Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 17 February 2018 at 14:54:37 UTC, ag0aep6g wrote: Nordlöw's methods are only weakly pure. They have mutable indirections either in the return type or in a parameter type. So calls to them should not be optimized away. I found a solution at

Re: Faking a non-pure function as pure

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 February 2018 at 18:03:40 UTC, Ali Çehreli wrote: auto pureF = assumePure(); pureF(42); Ali Thanks!

Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 17 February 2018 at 12:35:00 UTC, rikki cattermole wrote: in pure functions? pure means no globals. As in none :) I guess one solution is to make the member functions in PureMallocator static and change how the template argument `Allocator` for a container is used to call

Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 17 February 2018 at 12:35:00 UTC, rikki cattermole wrote: in pure functions? pure means no globals. As in none :) I don't understand. I thought std.experimental.allocators API was designed to be able express these needs, @andralex?

Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
I'm struggling with making https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d callable in pure functions such as here https://github.com/nordlow/phobos-next/blob/master/src/pure_mallocator.d#L84 Shouldn't a shared static shared PureMallocator instance; make it

Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 17 February 2018 at 12:33:25 UTC, Nordlöw wrote: PureMallocator.instance.allocate(16); currently errors as pure_mallocator.d(84,16): Error: pure function 'pure_mallocator.__unittest_pure_mallocator_82_0' cannot access mutable static data 'instance'

Faking a non-pure function as pure

2018-02-16 Thread Nordlöw via Digitalmars-d-learn
I'm struggling with my definition of assumePure that should make a non-pure function `f` callable as pure `pureF`. I've copied the definition of assumePure from the Phobos docs at https://dlang.org/phobos/std_traits.html#SetFunctionAttributes and managed to define pureF using it but I cannot

Re: flycheck-dmd-dub v0.12 - Emacs on-the-fly syntax checking for D

2018-02-13 Thread Nordlöw via Digitalmars-d-announce
On Thursday, 8 February 2018 at 17:05:32 UTC, Atila Neves wrote: This new release fixes bugs and speeds up opening files by using `--nodeps --skip-registry=all` if the dependent packages have already been downloaded. Thanks!

Nightlies not being built so so how do I build dmd-master locally instead?

2018-02-11 Thread Nordlöw via Digitalmars-d
https://nightlies.dlang.org/ has not been built since 2018-02-01. What's wrong? Can I build dmd master with ldc (need compilation speed) myself? If so what's the preferred script?

Re: Class instance memory overhead lower than 3 words?

2018-01-24 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 24 January 2018 at 21:47:26 UTC, H. S. Teoh wrote: On Wed, Jan 24, 2018 at 09:48:21PM +, Nordlöw via Digitalmars-d-learn wrote: Why is the memory overhead for a class instance as high as 3 words (24 bytes on 64-bit systems? I find that annoyingly much for my knowledge

Class instance memory overhead lower than 3 words?

2018-01-24 Thread Nordlöw via Digitalmars-d-learn
Why is the memory overhead for a class instance as high as 3 words (24 bytes on 64-bit systems? I find that annoyingly much for my knowledge database application. I'm aware of extern(C++), having one word overhead, but such extern(C++)-classes cannot use all of D; I get compilation errors such

Re: @safe matching on subclass type

2018-01-17 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 13:19:42 UTC, Nordlöw wrote: Why isn't polymorphic down-casts such as in the following pattern matching on sub-class class Base {} class Sub : Base {} @safe unittest { auto base = new Base(); if (auto sub = cast(Sub)base) { // use sub }

@safe matching on subclass type

2018-01-17 Thread Nordlöw via Digitalmars-d-learn
Why isn't polymorphic down-casts such as in the following pattern matching on sub-class class Base {} class Sub : Base {} @safe unittest { auto base = new Base(); if (auto sub = cast(Sub)base) { // use sub } } allowed in safe D?

Re: Cannot use local lambda as parameter to non-global template

2018-01-15 Thread Nordlöw via Digitalmars-d-learn
On Monday, 15 January 2018 at 15:27:23 UTC, Meta wrote: void main() { auto arr = [1, 2, 3]; arr.remove!(_ => _ == 1); writeln(arr); } Or was that code meant as an example? The problem occurs when the templated function is a member of the struct `arr`. I've moved the algorithm

Cannot use local lambda as parameter to non-global template

2018-01-15 Thread Nordlöw via Digitalmars-d-learn
Why do I get errors like template instance remove!((_) => _ == 1) cannot use local '__lambda5' as parameter to non-global template remove()(in K key) for x.remove!(_ => _ == 1); but not for x.remove!"a == 11"; ? How are these two lambdas different? The function `remove` is a

Re: Range over a container r-value with disabled postblit

2018-01-14 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:57:37 UTC, Nordlöw wrote: Note that __trait(isLvalue, this) cannot be used to detect whether `this` is an l-value or an r-value, which I find strange. Shall be __traits(isRef, this)

Re: Range over a container r-value with disabled postblit

2018-01-14 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 14 January 2018 at 14:04:46 UTC, kinke wrote: That sounds reasonable. For something like `foreach (e; makeRange().wrapRangeByRef())`, referencing the makeRange() struct rvalue by pointer in the wrapped range won't work, as the underlying range lifetime ends with the foreach range

Range over a container r-value with disabled postblit

2018-01-13 Thread Nordlöw via Digitalmars-d-learn
Given my combined hashmap and hashset container `HashMapOrSet` defined at https://github.com/nordlow/phobos-next/blob/master/src/hashmap_or_hashset.d with deterministic memory management and disabled copy constructions and a member byElement() defined as @property auto byElement()()

Re: Tuple DIP

2018-01-13 Thread Nordlöw via Digitalmars-d
On Saturday, 13 January 2018 at 00:37:48 UTC, Chris M. wrote: On Friday, 12 January 2018 at 22:44:48 UTC, Timon Gehr wrote: As promised [1], I have started setting up a DIP to improve tuple ergonomics in D: [...] Yes please Very much agree.

Re: calloc for std.experimental.allocator

2018-01-12 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 11 January 2018 at 21:57:28 UTC, MrSmith wrote: http://dpldocs.info/experimental-docs/std.experimental.allocator.makeArray.4.html Thanks!

calloc for std.experimental.allocator

2018-01-11 Thread Nordlöw via Digitalmars-d-learn
Is there no equivalent of `calloc()` for `std.experimental.allocator`, something like Allocator.zeroAllocate(size_t numberOfElements) ?

Re: Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 11 January 2018 at 12:24:36 UTC, Nordlöw wrote: How do I check whether an aggregate member function (call for a specific argument) is @nogc or not? I want to check whether Allocator.allocate(1) (for a any Allocator) is @nogc or not? Is

Checking @nogc-ness of an Allocator.allocate()

2018-01-11 Thread Nordlöw via Digitalmars-d-learn
How do I check whether an aggregate member function (call for a specific argument) is @nogc or not? I want to check whether Allocator.allocate(1) (for a any Allocator) is @nogc or not? Is https://dlang.org/phobos/std_traits.html#hasFunctionAttributes the way to do it?

Upcasting slice of class elements

2018-01-05 Thread Nordlöw via Digitalmars-d-learn
Why isn't class X {} class Y : X {} X[] xs = cast(X[])(Y[].init); compilable in safe D? What's unsafe about such a cast?

Re: Tail-constness of class parameters

2017-12-25 Thread Nordlöw via Digitalmars-d-learn
On Monday, 25 December 2017 at 15:16:55 UTC, ag0aep6g wrote: https://dlang.org/phobos/std_typecons.html#Rebindable Thanks.

Tail-constness of class parameters

2017-12-25 Thread Nordlöw via Digitalmars-d-learn
In a graph library I'm working on I have the following algorithm bool hasContext(Node sub,// TODO in Node sup) nothrow // TODO in { Node curr = sub; while (true) { Node ctx = curr.context; if (!ctx) { break;} if (ctx is sup)

No line numbers in stack trace (again)

2017-12-05 Thread Nordlöw via Digitalmars-d-learn
If I get the following stack trace ___without line numbers___ (instead ??:?) what's missing? core.exception.AssertError@src/knet/linking.d(444): Assertion failure ??:? _d_assertp [0x5092ab19] ??:? pure @safe knet.storage.Edge

Re: Inference of Scoped Destruction

2017-12-04 Thread Nordlöw via Digitalmars-d
On Monday, 4 December 2017 at 16:03:50 UTC, Nick Treleaven wrote: On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote: How would this interact with explicit scope-qualification of `x`? That would allow the compiler to avoid GC allocation for x. It seems essentially the same case as

Re: Google alert for "dlang"

2017-12-04 Thread Per Nordlöw via Digitalmars-d
On Saturday, 2 December 2017 at 17:43:01 UTC, Andrei Alexandrescu wrote: Thanks, Andrei Done. Thanks.

Re: Inference of Scoped Destruction

2017-11-30 Thread Nordlöw via Digitalmars-d
On Thursday, 30 November 2017 at 16:50:02 UTC, Stefan Koch wrote: On Thursday, 30 November 2017 at 16:31:25 UTC, Nordlöw wrote: Are there any plans to D compilers to use recent DIP-1000 to infer scoped destruction of GC-allocated data such as in the following case: T sum(T)(in T[] x) // x

<    1   2   3   4   5   6   7   8   9   10   >