Simplest way to convert an array into a set

2023-02-13 Thread Matt via Digitalmars-d-learn
Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked through the documentation for std.array, std.algorithm AND std.range, and I've either missed it,

A potential use-case for template mixins?

2023-02-06 Thread Matt via Digitalmars-d-learn
I am (still) writing a 3D graphics engine, and was considering my choices for a scene graph. Originally, I was going to use classes derived from my base SceneNode class for the nodes of the graph, but would this instead be a better situation to use template mixins instead of potentially havin

How to write a library

2023-01-21 Thread Matt via Digitalmars-d-learn
I am trying to write a graphics engine for my university capstone project, and really wanted to give it a try in D, as both a talking point, and because I love the language. I'm using dub to build the library, and the demo application that'll use it. However, I've come across a problem. In C/C

Re: Why does choose not work here

2019-08-01 Thread Matt via Digitalmars-d-learn
On Thursday, 1 August 2019 at 21:12:51 UTC, ag0aep6g wrote: `choose`'s parameters aren't lazy. So the second argument is evaluated even when `previous is null`. That means `intervalRange` is called on a null `previous`. And that fails, of course, because `intervalRange` can't access `starts` or

Why does choose not work here

2019-08-01 Thread Matt via Digitalmars-d-learn
I'm having some trouble with a "Program exited with code -1073741819" error in some code I'm writing and I would appreciate any help/insight. The problem stems from some incompatibility between the Phobos function "choose" and the template function "myFilter" which returns a range. The code b

Re: Why in Phobos is empty() sometimes const and sometimes not

2019-07-30 Thread Matt via Digitalmars-d-learn
On Tuesday, 30 July 2019 at 05:30:30 UTC, Jonathan M Davis wrote: In principle, it's good to use const when you know that data isn't going to change, but that gets far more complicated when you're dealing with generic code or even with classes, since as soon as you use const, everything used wi

Re: Why in Phobos is empty() sometimes const and sometimes not

2019-07-29 Thread Matt via Digitalmars-d-learn
On Monday, 29 July 2019 at 19:38:34 UTC, Jonathan M Davis wrote: On Monday, July 29, 2019 11:32:58 AM MDT Matt via Digitalmars-d-learn wrote: Because const ranges are basically useless, there really isn't much point in putting const on any range functions even if it would work for

Why in Phobos is empty() sometimes const and sometimes not

2019-07-29 Thread Matt via Digitalmars-d-learn
I've noticed that for some ranges in Phobos empty is marked const (e.g. iota) but for other ranges (e.g. multiwayMerge) it is not const. Is there a reason why? Isn't empty guaranteed not to alter the data of the range and so should be const? This is causing me considerable headaches as I try t

Re: D generates large assembly for simple function

2018-01-27 Thread Matt via Digitalmars-d-learn
Godbolt link: https://godbolt.org/g/t5S976

D generates large assembly for simple function

2018-01-27 Thread Matt via Digitalmars-d-learn
Playing around with Godbolt, D seems to generate an embarassing amount of assembly for a simple function (50ish for squaring an int vs 4 for C++ and 7 for Rust). Even Go compiles to less assembly. Is there something I'm missing?

Re: Randomisation of array order

2015-08-02 Thread Matt via Digitalmars-d-learn
...And then I realised that I hadn't looked inside std.random. Question solved, because I am a dumbass.

Randomisation of array order

2015-08-02 Thread Matt via Digitalmars-d-learn
I was planning to use a dynamic array of indices to represent a deck of cards, and was wondering if there was any easy way to "shuffle" the arrays contents? I checked the library docs, but came to the conclusion that sorting arrays is a much more common operation :) If anyone has a suggestion

Removing structs from assoc array while iterating over it

2015-03-16 Thread Matt via Digitalmars-d-learn
I am creating a simple SDL_Texture manager, and was wondering if the following code would work: --- // 'list' is am assoc array of a struct containing a pointer and ref counter. // max_list_length is set to 20 if it's ever found to be 0 // compact list if(list.length == max_list_length){

Re: embedding Pyd in Windows program

2015-03-14 Thread Matt via Digitalmars-d-learn
On Saturday, 14 March 2015 at 00:28:59 UTC, Ellery Newcomer wrote: On Friday, 13 March 2015 at 19:05:59 UTC, Matt wrote: example code, see if I can figure it out, but if you can advise, that would be fantastic. Thank you for all the help so far, it's really been appreciated My penitence for

Re: OutputDebugString()

2015-03-13 Thread Matt via Digitalmars-d-learn
On Friday, 13 March 2015 at 21:12:52 UTC, Robert M. Münch wrote: Hi, I want to use the Windows OutputDebugString() which is not defined anywhere. How do I declare such missing Windows API functions myself? And with which libaries do I then need to link? Does DMD contain all necessary Windows

Re: embedding Pyd in Windows program

2015-03-13 Thread Matt via Digitalmars-d-learn
On Friday, 13 March 2015 at 16:30:07 UTC, Matt wrote: Thank you, adding the "subConfigurations" section to dub.json seems to allow the program to compile and run successfully. However, to test the code, I first tried in the main program: --- py_eval!string("import sys\nprint(sys.path)"); -

Re: embedding Pyd in Windows program

2015-03-13 Thread Matt via Digitalmars-d-learn
On Friday, 13 March 2015 at 14:21:15 UTC, Ellery Newcomer wrote: On Friday, 13 March 2015 at 09:38:45 UTC, Matt wrote: I used the "~>0.9.4" branch in dub, and I'm not sure how to change "configuration". Do you mean I should be using "~master" or "~develop"? nope. configurations are a differ

Re: embedding Pyd in Windows program

2015-03-13 Thread Matt via Digitalmars-d-learn
On Friday, 13 March 2015 at 01:40:34 UTC, Ellery Newcomer wrote: On 03/11/2015 07:59 PM, Matt wrote: Right, copying site.py into my program's working dir sorts out the missing module error, but I now get a syntax error: file=sys.stderr) ^ SyntaxError: invalid syntax Error executi

Re: embedding Pyd in Windows program

2015-03-11 Thread Matt via Digitalmars-d-learn
On Wednesday, 11 March 2015 at 21:45:20 UTC, Matt wrote: On Wednesday, 11 March 2015 at 19:32:05 UTC, Matt wrote: I'm trying to build a simple platformer using SDL2 and python to script entities, but I'm struggling to include Pyd. I'm using DMD v2.066.1, with dub as the package manager, and de

Re: embedding Pyd in Windows program

2015-03-11 Thread Matt via Digitalmars-d-learn
On Wednesday, 11 March 2015 at 19:32:05 UTC, Matt wrote: I'm trying to build a simple platformer using SDL2 and python to script entities, but I'm struggling to include Pyd. I'm using DMD v2.066.1, with dub as the package manager, and derelict for the SDL2 bindings. Now, when I add Pyd to my

embedding Pyd in Windows program

2015-03-11 Thread Matt via Digitalmars-d-learn
I'm trying to build a simple platformer using SDL2 and python to script entities, but I'm struggling to include Pyd. I'm using DMD v2.066.1, with dub as the package manager, and derelict for the SDL2 bindings. Now, when I add Pyd to my dub.json everything works fine, but as soon as I add py_i

Re: Example usage of the core.sync classes

2015-01-03 Thread Matt via Digitalmars-d-learn
On Saturday, 3 January 2015 at 22:10:49 UTC, Vlad Levenfeld wrote: On Saturday, 3 January 2015 at 15:44:16 UTC, Matt wrote: Right, I've been looking at core.atomic, but it has very little documentation, and it's territory I haven't explored, yet. Any chance of some pointers along the way? Cou

Re: Example usage of the core.sync classes

2015-01-03 Thread Matt via Digitalmars-d-learn
On Friday, 2 January 2015 at 18:52:11 UTC, Benjamin Thaut wrote: Am 02.01.2015 um 19:45 schrieb Vlad Levenfeld: My personal favorite method is to use the primitives in core.atomic with a double or triple buffer. To double buffer, keep two buffers in an array (data[][] or something) and an int

Example usage of the core.sync classes

2015-01-02 Thread Matt via Digitalmars-d-learn
I'm trying to write a small 3D engine, and wanted to place the physics in a separate thread to the graphics, using events, possibly std.concurrency, to communicate between them. How, then, do I pass large amounts of data between threads? I'm thinking the physics world state (matrix for each ob

Re: Exception thrown while trying to read file

2014-10-03 Thread Matt via Digitalmars-d-learn
On Friday, 3 October 2014 at 13:48:41 UTC, thedeemon wrote: On Friday, 3 October 2014 at 11:30:02 UTC, Matt wrote: I am building a PE-COFF file reader file.seek(0x3c, SEEK_SET); file.readf("%d", &offs); // this is the problem line Does anyone else see whatever it is that I'm doing wrong? rea

Exception thrown while trying to read file

2014-10-03 Thread Matt via Digitalmars-d-learn
I am building a PE-COFF file reader, just for education purposes, and I keep getting a ConvException come up, stating: --- Unexpected ' --- Now, I have no idea how I'm getting this. The code at that point looks like the following: --- // look for the identifier // this gives us the

Loading Symbols from Loaded Libraries

2014-09-01 Thread Matt via Digitalmars-d-learn
If I were to use Runtime.loadLibrary(), it claims to merge any D GC in the shared lib with the current process' GC. Do I need to version away symbol loading code for each platform? Or is there already code in Phobos that allows us to do this independent of platform?

mismatched function return type inference of string and double

2014-08-03 Thread matt via Digitalmars-d-learn
So I just started learning D this weekend, and I'm trying to understand why the following example will not work... Essentially what I am trying to do is cast the templated child stored in the parent container as the correct form, return some T value, and use auto to return the correct value typ

Re: Source File and Position of User Defined Type

2014-06-11 Thread Matt via Digitalmars-d-learn
On Tuesday, 10 June 2014 at 20:58:41 UTC, Nordlöw wrote: Is there a way to, programatically (trait), lookup the source file and position of a user defined type either dynamically or, even better, statically? I don't know about the source file, per se, but std.traits has the fullQualifiedName!

Re: problem with Access Violation, and I'm not sure where

2014-06-10 Thread Matt via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 02:59:40 UTC, Matt wrote: I previously asked this over in the DigitalMars.D board(http://forum.dlang.org/thread/huftyrtbomaimuqkm...@forum.dlang.org#post-hrqvqlzzbkgafvjdtjnb:40forum.dlang.org), but it was suggested I ask it over here instead. I have the following

Re: Basic dynamic array question. Use of new versus no new.

2014-06-10 Thread Matt via Digitalmars-d-learn
On Wednesday, 11 June 2014 at 02:30:01 UTC, WhatMeWorry wrote: In Mr. Cehreli's book it says Additionally, the length of dynamic arrays can be changed by assigning a value to this property: int[] array; // initially empty array.length = 5; // now has 5 elements while in Mr. Alexandrescu's bo

Re: storing pointers in Variants

2014-04-27 Thread Matt via Digitalmars-d-learn
On Sunday, 27 April 2014 at 00:48:53 UTC, Ali Çehreli wrote: I think the following is a start: import std.variant; class MyClass { Variant[string] store; void attach(T)(string key, ref T var) { store[key] = &var; } void set(T)(string key, T value) { *s

storing pointers in Variants

2014-04-26 Thread Matt via Digitalmars-d-learn
I am trying to create a class that can do the following: --- int sample = 42; // myObj is an instance of the class I'm writing myObj.attach ("othername", sample); myObj.set ("othername", 69); writeln (myObj.get ("othername"), "\t", sample); // should produce '69 69' --- Currently, my cla