Re: Show dialog box for uncaught exception (Windows, lld-link)

2024-05-05 Thread SimonN via Digitalmars-d-learn
On Sunday, 5 May 2024 at 18:28:29 UTC, SimonN wrote: My implementation for the message box is now: According to [UTF-8 Everywhere](https://utf8everywhere.org/#windows), I shouldn't use `MessageBoxA` at all. The `A` means ANSI codepages, _not_ UTF-8. My above code _will_ show garbage output

Re: Show dialog box for uncaught exception (Windows, lld-link)

2024-05-05 Thread SimonN via Digitalmars-d-learn
On Sunday, 5 May 2024 at 17:15:10 UTC, Steven Schveighoffer wrote: } catch(Exception e) { visualDisplayOfException(e); throw e; } Thanks! That's practically the same pattern that I already use for logging: Try-catch near the entry point, show the

Show dialog box for uncaught exception (Windows, lld-link)

2024-05-05 Thread SimonN via Digitalmars-d-learn
Hi, for Windows, I link my executables with `lld-link`, whether for 32-bit and 64-bit and whether I've built with LDC or DMD. How can I generate a dialog box for uncaught exceptions that fly out of my executable's `main()`? When I linked with Optlink years ago for Windows 32-bit, it

Re: Annotating SortedRange.empty const: Best way to auto-deduce annotations?

2020-09-02 Thread SimonN via Digitalmars-d-learn
On Wednesday, 2 September 2020 at 21:40:59 UTC, Steven Schveighoffer wrote: What they can do is template the `this` parameter. Then if the underlying range supports calling that way, it will work, otherwise it won't. using `template this` should be compatible with the existing code I would

Annotating SortedRange.empty const: Best way to auto-deduce annotations?

2020-09-02 Thread SimonN via Digitalmars-d-learn
Hi, About this issue in Phobos: https://issues.dlang.org/show_bug.cgi?id=21216 SortedRange.empty should be const, .front should be inout Just adding const/inout to SortedRange's methods won't be enough; if we add const/inout here, then many other Phobos ranges need to become

Re: Mergesort not working

2019-12-29 Thread SimonN via Digitalmars-d-learn
On Sunday, 29 December 2019 at 11:02:34 UTC, Adnan wrote: while (arr1_idx < arr1.length && arr2_idx < arr2.length) result ~= arr1[arr1_idx] < arr2[arr2_idx] ? arr1[arr1_idx++] : arr2[arr2_idx++]; Given an array, it just returns a 1 length array. What's causing this? This loop

Re: How does Rebindable suppress the compiler's optimizations for immutable?

2019-02-15 Thread SimonN via Digitalmars-d-learn
Thanks for the detailed answers! Yes, I accept that immutable guarantees should be implemented only during @safe that doesn't call into @trusted. On Friday, 15 February 2019 at 18:59:36 UTC, H. S. Teoh wrote: At the very least, such [union] code should be automatically @system. Sensible.

How does Rebindable suppress the compiler's optimizations for immutable?

2019-02-14 Thread SimonN via Digitalmars-d-learn
std.typecons.Rebindable!(immutable A) is implemented as: private union { immutable(A) original; A stripped; } ...@trusted assignment operators... @property inout(immutable(A)) get() @trusted pure nothrow @nogc inout { return original; }

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-29 Thread SimonN via Digitalmars-d-learn
On Monday, 19 November 2018 at 21:23:31 UTC, Jordi Gutiérrez Hermoso wrote: When I was first playing with D, I managed to create a segfault What's the reasoning for allowing this? 100 % agree that there should be non-nullable class references, they're my main missing feature in D.

Re: merkle reverse

2018-04-05 Thread SimonN via Digitalmars-d-learn
On Thursday, 5 April 2018 at 09:49:58 UTC, Seb wrote: Strings are bi-directional ranges, but they aren't random-access nor have a length chunks requires hasSlicing + hasLength: Okay, thanks for the great references. chunks/slide certainly need the length to decide which, and how many,

Re: merkle reverse

2018-04-05 Thread SimonN via Digitalmars-d-learn
On Thursday, 5 April 2018 at 09:07:52 UTC, Seb wrote: FYI: The problem isn't chunks, but that strings aren't bi-directional ranges (hello ugly auto-decoding!). "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b".byCodeUnit Thanks! Very appropriate because it's all hex digits

Re: merkle reverse

2018-04-05 Thread SimonN via Digitalmars-d-learn
On Thursday, 5 April 2018 at 08:12:38 UTC, aerto wrote: This is the bitcoin genesis block merkle root 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b how i can get it at this format 3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a ?? i try it using string

Re: Fixing 18615, how to handle @safe/pure/nothrow test breakage due to object.opEquals?

2018-03-28 Thread SimonN via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 15:04:27 UTC, Kagamin wrote: See line 1957, attributes are not inferred. Wow, that hit my blind spot. :-O Thanks. I've moved the RebindableCommon.opEquals outside of the attributes and all tests pass, as expected. -- Simon

Fixing 18615, how to handle @safe/pure/nothrow test breakage due to object.opEquals?

2018-03-28 Thread SimonN via Digitalmars-d-learn
Hi, I'm trying to fix Bugzilla 18615, Rebindable!A doesn't use class A's opEquals (returns a is b instead) [1]. The fix looks reasonably obvious, my code is at [2]. Most of the added lines is the unittest; the essence of the fix is: struct RebindableCommon(/* ... */) { //

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread SimonN via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 15:28:40 UTC, jmh530 wrote: static if (isMutable!T) bag[0] = rhs; else bag = [rhs]; I like this idea. I'd even take it a step futher: When T is a pointer or class reference, then we can put the reference on the stack

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-27 Thread SimonN via Digitalmars-d-learn
On Monday, 26 March 2018 at 14:17:03 UTC, Jonathan M Davis wrote: Rebindable does is pretty questionable as far as the type system goes, but it does what it does by forcing pointer semantics on a class reference, so the point is arguable. Yeah, I've always assumed that Rebindable cannot be

Re: String Type Usage. String vs DString vs WString

2018-01-15 Thread SimonN via Digitalmars-d-learn
On Monday, 15 January 2018 at 14:44:46 UTC, Adam D. Ruppe wrote: On Monday, 15 January 2018 at 06:18:27 UTC, SimonN wrote: D's foreach [...] will autodecode and silently iterate over dchar, not char, even when the input is string That's not true. foreach will only decode on demand: foreach(c;

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread SimonN via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:05:32 UTC, Chris P wrote: Is usage of one type over the others encouraged? I would use string (UTF-8) throughout the program, but there seems to be no style guideline for this. Keep in mind two gotchas: D's foreach and D's ranges will autodecode and silently

Re: Pass D const pointer to opaque C library: Guarantees? Optimization-safe?

2017-12-16 Thread SimonN via Digitalmars-d-learn
On Saturday, 16 December 2017 at 11:19:36 UTC, Mike Parker wrote: that's a binding, not a wrapper. Right! Not sure what you mean by "safe" you only want to prevent changes on the D side and don't care if they happen on the C side, then that's fine. This, yes. I'd like const-annotated D

Pass D const pointer to opaque C library: Guarantees? Optimization-safe?

2017-12-16 Thread SimonN via Digitalmars-d-learn
Hi, I'm calling a C library through a D wrapper. The situation is like this: C library has: struct A { ... }; A* create_a() { ... } void foo(A*) { ... } D wrapper declares: extern (C) { struct A {} A* create_a(); void foo(A*); } My D

Re: Sort in return statement

2017-12-08 Thread SimonN via Digitalmars-d-learn
On Saturday, 9 December 2017 at 03:24:52 UTC, codephantom wrote: On Saturday, 9 December 2017 at 02:45:35 UTC, rjframe wrote: `sort` returns a SortedRange of ushorts, not an array of ushorts. Make it: ``` import std.array : array; return sort(numbers.take(8)).array; ``` --Ryan That's it!

Re: Always std.utf.validate, or rely on exceptions?

2017-03-02 Thread SimonN via Digitalmars-d-learn
ketmar wrote: i'd say: "ALWAYS validate before ANY further processing". On Thursday, 2 March 2017 at 17:03:01 UTC, Kagamin wrote: If you expect file with malformed utf that can cause you trouble and want to handle it gracefully, pass its content through validator and catch exception from

Always std.utf.validate, or rely on exceptions?

2017-03-02 Thread SimonN via Digitalmars-d-learn
Many functions in std.utf throw UTFException when we pass them malformed UTF, and many functions in std.string throw StringException. From this, I developed a habit of reading user files like so, hoping that it traps all malformed UTF: try { // call D standard lib on string from

Re: Bug after update to 2.072?

2016-11-06 Thread SimonN via Digitalmars-d-learn
I'm not sure how to pass arbitrary dustmite arguments through dub to dustmite. `dub dustmite -h' lists arguments. When dustmite reduces your project to the empty project, maybe try this from the dustmite website: "You can also surround code that is not to be removed around the magic words

Re: immutable class can't override opEquals, workaround?

2016-02-21 Thread SimonN via Digitalmars-d-learn
On Sunday, 21 February 2016 at 07:58:42 UTC, Jonathan M Davis wrote: opEquals still works with const and immutable if it's legal to use a class as the key in an AA, it's a bug have a working version of the PR hasn't even been looked at yet from what I can tell, and it's the simplest of the

immutable class can't override opEquals, workaround?

2016-02-20 Thread SimonN via Digitalmars-d-learn
Hi, immutable class A { int i; this(int arg) { i = arg; } override bool opEquals(Object rhsObj) { auto rhs = cast (immutable(A)) rhsObj; return rhs && i == rhs.i; } } Error by dmd 2.070: ./immutclass.d(4): Error:

Re: chain(const(array of class)) fails

2016-02-02 Thread SimonN via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 10:58:35 UTC, Marc Schütz wrote: The constraint that fails is the one with `CommonType`: `CommonType` uses the `?:` operator to derive the common type: I filed a bug report: https://issues.dlang.org/show_bug.cgi?id=15638 Interesting reduced case, so it wasn't

Re: chain(const(array of class)) fails

2016-02-01 Thread SimonN via Digitalmars-d-learn
Sorry for late reply -- but I got around to test a couple more cases! On Monday, 1 February 2016 at 00:19:44 UTC, Nicholas Wilson wrote: Unqaul means remove any const or immutable torn the type Okay, that sounds like our 'const' shouldn't matter. 'const' is the outermost qualifier, and

chain(const(array of class)) fails

2016-01-31 Thread SimonN via Digitalmars-d-learn
Hi, we start with the following code snippet, which works. import std.algorithm; import std.range; import std.stdio; class A { int val; } class B : A { this() { val = 3; } } class C : A { this() { val = 4; } } B[] b = [new B(), new B()]; C[] c = [new C(),

Re: @property not available for classes?

2016-01-01 Thread SimonN via Digitalmars-d-learn
On Friday, 1 January 2016 at 10:14:58 UTC, Shriramana Sharma wrote: auto p = TimeSpan(1, 2); Error: no property 'opCall' for type '.TimeSpan' The error should be in 'auto p = ...', not in the line using the property. Instantiate with 'new TimeSpan(1, 2)' instead of 'TimeSpan(1, 2)'.

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:41:10 UTC, TheDGuy wrote: It looks like the debugger is not working correctly because i changed the code to this: [...] and the same problem appears. I can't watch youtube here. What numbers does your input generate? Which 'if' doesn't fire? What results

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote: Sry: if((x1 < 0) & (x2 >= 0)){ This looks like a bug, with & instead of &&. -- Simon

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:52:39 UTC, TheDGuy wrote: I don't understand why my program goes into the if statement if the debugger shows, that the variable "discriminant" is below zero even though: "if(discriminant > 0)"? I have a hard time believing this. Does the problem persist if

Re: segfault in invariant { assert(super); }

2015-12-22 Thread SimonN via Digitalmars-d-learn
On Monday, 21 December 2015 at 20:29:14 UTC, Steven Schveighoffer wrote: 1) Is this recursion expected? Yes. assert calls the virtual invariant function, which in the case of super is equivalent to this. So you are essentially calling assert(this). 2) The example is a dustmite'd version of

segfault in invariant { assert(super); }

2015-12-19 Thread SimonN via Digitalmars-d-learn
Hi, the following code compiles fine, then segfaults upon running. class Base { this(int) { } } class Derived : Base { this(int a) { super(a); } invariant() { assert (super); } } void main() { new Derived(5); } Tested both with dmd

alias butAtLeast = max; 5.butAtLeast(6);

2015-12-12 Thread SimonN via Digitalmars-d-learn
DMD v2.069.2-b1 on Linux. import std.algorithm; int a = max(5, 6);// works, a == 6 int b = max!(int, int)(5, 6); // works, manual instantiation int c = 5.max(6); // works, UFCS call I would like to use the last syntax, but with an alias. alias

Re: alias butAtLeast = max; 5.butAtLeast(6);

2015-12-12 Thread SimonN via Digitalmars-d-learn
By putting it in the top level. I believe this is intentional but I don't remember the reasoning. On Saturday, 12 December 2015 at 13:34:09 UTC, ZombineDev wrote: This is due to limitation of function-local aliases. If you put the alias outside it will work:

Range violation instead of empty slice on a[3 .. 2]

2015-11-21 Thread SimonN via Digitalmars-d-learn
string a = "hello"; string b = a[3 .. 2]; I expect b to become an empty slice, because 3 is >= 2 already after 0 increments, making the slice length 0. Instead, the code throws a range violation. Expressions of this kind come up, e.g., when taking slices near the end of arrays, like

Re: Range violation instead of empty slice on a[3 .. 2]

2015-11-21 Thread SimonN via Digitalmars-d-learn
On Saturday, 21 November 2015 at 18:28:51 UTC, BBaz wrote: this is only an error if bounds checking is not turned on. If you compile your example with DMD option "-boundscheck=off", nothing happens, and the slice will be equal (here) to a[3..$]; Thanks for the hint, I tested this with

Re: Range violation instead of empty slice on a[3 .. 2]

2015-11-21 Thread SimonN via Digitalmars-d-learn
On Sunday, 22 November 2015 at 00:24:43 UTC, Jonathan M Davis wrote: this is only an error if bounds checking is not turned on. It's a logic error regardless. you're going to have to create a wrapper. Right, I am using a wrapper, and I'm not relying on any behavior of a[3..2] during

Mixin template, "no identifier for declarator"

2015-10-27 Thread SimonN via Digitalmars-d-learn
Hi, I'd like to generate several very similar class methods with a mixin template. The mixin template shall take alias parameters, so that different methods can bind it to different fields. Reduced problem case: class A { int myField; mixin template fieldSetter(alias

Re: Mixin template, "no identifier for declarator"

2015-10-27 Thread SimonN via Digitalmars-d-learn
On Tuesday, 27 October 2015 at 08:41:24 UTC, Andrea Fontana wrote: Template mixins can be used only for declaration. Thanks for the quick reply! I didn't know that. Now the error message makes sense. Probably what you need is a (non-template) mixin. Yes, it's gonna be a string mixin, or

Re: Arrays of structs

2015-08-27 Thread SimonN via Digitalmars-d-learn
Hi, On Thursday, 27 August 2015 at 10:05:31 UTC, John Burton wrote: understanding is that structs have deterministic destructors - they are called when the struct goes out of scope Yes, when they are declared right at the scope, and not contained in something that might live past the current

Re: Empty struct, any runtime cost?

2015-08-19 Thread SimonN via Digitalmars-d-learn
On Wednesday, 19 August 2015 at 09:54:33 UTC, SimonN wrote: Hi, I've found this thread (Theoretical best practises): http://forum.dlang.org/thread/codmadrwuyqxbklmu...@forum.dlang.org My goal is the same; I'm only more wary of putting debug/version everywhere. If the empty struct isn't

Empty struct, any runtime cost?

2015-08-19 Thread SimonN via Digitalmars-d-learn
Hi, in a release-like build, I'm using the tharsis profiler, which is a frame-based profiler. Zone is a RAII struct that measures how long its own lifetime is. with (Zone(my_profiler, zone name to appear in output)) { do_expensive_work(); do_some_more_work(); } //

Re: Template mixin can not introduce overloads

2015-06-30 Thread SimonN via Digitalmars-d-learn
On Thursday, 25 June 2015 at 03:49:04 UTC, Tofu Ninja wrote: Is this intended or is it a bug? On Thursday, 25 June 2015 at 03:53:58 UTC, Adam D. Ruppe wrote: Intended, the mixin template works on the basis of names. This The extra step is easy though: alias the name in: I would like to to

Re: How to realize copyable/postblit class

2015-06-13 Thread SimonN via Digitalmars-d-learn
On Saturday, 13 June 2015 at 08:52:59 UTC, John Colvin wrote: perhaps: class A { struct S { // ... } S s; alias s this; this(A rhs) { s = rhs.s; } } I'm using this now, and it doesn't feel like a workaround too much. For something with 5

How to realize copyable/postblit class

2015-06-12 Thread SimonN via Digitalmars-d-learn
Hi, I have a few classes with need for deeper copying. I don't want a bitwise copy necessarily. Ideally, I'd implement this(this). I've thought about changing them to struct. However, the type feels much more like a D class than a D struct. It's often passed by reference, and it's not plain