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
what the downsides would be. - Jonathan M Davis That was a great article you wrote. Const has been one of the more difficult concepts for me to grasp when I moved from python to C++ and then to D. I also never understood immutable and the difference with const. Your article makes that really clear. Thanks for sharing. Matt

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: Can't Compile Global Semaphores?

2018-10-08 Thread Matt Richardson via Digitalmars-d-learn
On Monday, 27 July 2015 at 20:57:00 UTC, Jack Stouffer wrote: On Monday, 27 July 2015 at 20:12:10 UTC, John Colvin wrote: Yes, but then core.sync.semaphore doesn't support being shared, so... Ok, so I made the code run by using __gshared instead of shared. It seems really odd that a semaphore

Re: Out of memory during compilation

2018-05-02 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 14:31:16 UTC, rikki cattermole wrote: On 03/05/2018 2:25 AM, Matt Gamble wrote: [...] Let me start by saying shared library support doesn't work (some people will say it does work partially, but it doesn't). The problem for you (I think) is that dmd i

Re: Out of memory during compilation

2018-05-02 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 14:30:19 UTC, Joakim wrote: On Wednesday, 2 May 2018 at 14:25:35 UTC, Matt Gamble wrote: I have a large program (for me) with several thousand lines of code. Recently when I've tried to compile under debug (-g -unittest) with VS2017, dmd2.076.1, windows 10, 8G

Out of memory during compilation

2018-05-02 Thread Matt Gamble via Digitalmars-d-learn
x64\Debug\SKaTERoptimizerD.exe failed! When compiled under release (-O -release -inline -boundscheck=off) mode it works fine. Any advice on how to combat this? Do I need to start compiling DLLs? Does that change how the linking would be done? Would that affect the debugger? Any help is appreciated, Matt

Re: issue with each specifically for x86

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 21:39:58 UTC, ketmar wrote: Matt Gamble wrote: On Wednesday, 7 March 2018 at 21:02:30 UTC, ag0aep6g wrote: On 03/07/2018 09:09 PM, ag0aep6g wrote: [...] With `real` instead of `double` x86_64 is also affected. Wow. Good to know I'm not crazy. I was afk

Re: issue with each specifically for x86

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 21:02:30 UTC, ag0aep6g wrote: On 03/07/2018 09:09 PM, ag0aep6g wrote: double f() { return 1; } void main() {     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();   

issue with each specifically for x86

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
This is a record for me with two 32bit vs 64bit issues in one day. Seems to be a problem with using "each" under 32bit which can be fixed by using foreach or switching to x64. Am I doing something wrong or is this the second bug I've found today? Below is a silly case, that replicates an error

Re: issue with inf from exp function

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:40:04 UTC, Steven Schveighoffer wrote: On 3/7/18 11:19 AM, Matt Gamble wrote: On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote: On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote: On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote

Re: issue with inf from exp function

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote: On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote: On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote: On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: [...] works for me as expected. ln(largest double

Re: issue with inf from exp function

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote: On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote: On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: [...] works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e

Re: issue with inf from exp function

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote: On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: I don't understand why I'm getting an 'inf' by raising E to a real number, e^^710.0L. See below. import std.stdio; import std.math; unittest { writefl

issue with inf from exp function

2018-03-07 Thread Matt Gamble via Digitalmars-d-learn
I don't understand why I'm getting an 'inf' by raising E to a real number, e^^710.0L. See below. import std.stdio; import std.math; unittest { writefln("ln(largest double) = %s", log(double.max)); // 709.783 writefln("e^710 = %s", exp(710.0));// inf, makes sense writefl

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: Having trouble porting basic GLFW C++ example to D

2017-10-06 Thread Matt Jones via Digitalmars-d-learn
On Saturday, 7 October 2017 at 04:24:07 UTC, Matt Jones wrote: On Saturday, 7 October 2017 at 03:47:27 UTC, Joakim wrote: On Saturday, 7 October 2017 at 03:12:09 UTC, Matt Jones wrote: [...] Heh, that's the problem. [...] I ran into this myself, took me awhile to track it down. I

Re: Having trouble porting basic GLFW C++ example to D

2017-10-06 Thread Matt Jones via Digitalmars-d-learn
On Saturday, 7 October 2017 at 03:47:27 UTC, Joakim wrote: On Saturday, 7 October 2017 at 03:12:09 UTC, Matt Jones wrote: [...] Heh, that's the problem. [...] I ran into this myself, took me awhile to track it down. I too took the size of dynamic arrays this way: [...] Ah. I s

Having trouble porting basic GLFW C++ example to D

2017-10-06 Thread Matt Jones via Digitalmars-d-learn
I've been trying to port a basic GLFW C++ example to D. The C++ version shows the textures correctly. But the D version shows nothing. The code is almost identical. Does anyone know why the D version does not work? https://github.com/workhorsy/d_glfw

Re: Problems with function as parameter

2017-09-21 Thread Matt Jones via Digitalmars-d-learn
On Thursday, 21 September 2017 at 20:21:58 UTC, Josh wrote: I'm trying to write a callback function for SDL_mixer through Derelict, but this is the first time I've tried to use a function as a parameter, and so I think I'm just making a minor mistake somewhere. [...] Make it a C function, n

Re: How to list all process directories under /proc/

2017-09-19 Thread Matt Jones via Digitalmars-d-learn
On Tuesday, 19 September 2017 at 13:32:29 UTC, Ky-Anh Huynh wrote: Btw, is that a bit weird that range is not supported in glob pattern :) Is there a design reason for this? That is strange. But then again, every glob library I've seen works a little bit differently.

Re: How to list all process directories under /proc/

2017-09-18 Thread Matt Jones via Digitalmars-d-learn
On Sunday, 17 September 2017 at 08:37:33 UTC, Ky-Anh Huynh wrote: The official documentation here https://dlang.org/phobos/std_path.html#.globMatch refers to the wiki page https://en.wikipedia.org/wiki/Glob_%28programming%29 . However I think the popular glob rules (man 7 glob) are not suppor

Re: Looking for instructions on how to make a Derelict library

2017-09-18 Thread Matt Jones via Digitalmars-d-learn
On Monday, 18 September 2017 at 11:27:01 UTC, jmh530 wrote: On Monday, 18 September 2017 at 00:33:25 UTC, Matt Jones wrote: I've been reading the DerelictSDL2 source code. I think I have a handle on it. I'll have to look more at the wiki too. Thanks. Might be interesting t

Re: Looking for instructions on how to make a Derelict library

2017-09-17 Thread Matt Jones via Digitalmars-d-learn
On Monday, 18 September 2017 at 00:21:23 UTC, Mike Parker wrote: See the D wiki for links to articles that show how to translate C headers. I've been reading the DerelictSDL2 source code. I think I have a handle on it. I'll have to look more at the wiki too. Thanks.

Looking for instructions on how to make a Derelict library

2017-09-17 Thread Matt Jones via Digitalmars-d-learn
Hey everyone, I wanted to make a version of SQlite3 that uses Derelict to load the sqlite3 DLL when I'm ready. I can't find any instructions for how to make a basic Derelict style library. I looked around at http://derelictorg.github.io/, but could not find anything. Does anyone have any? T

Re: warning: pointer not aligned at address

2017-04-11 Thread Matt Whisenhunt via Digitalmars-d-learn
ld: warning: pointer not aligned at address 0x100050C7D Are you running macOS and recently installed an update to Xcode? I ran into this today as well. Looks like other have too: https://issues.dlang.org/show_bug.cgi?id=17289

Re: Handling arbitrary char ranges

2016-04-20 Thread Matt Kline via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 20:00:58 UTC, ag0aep6g wrote: Maybe I've missed it, but you didn't say where the HTTP type comes from, did you? std.net.curl: https://dlang.org/phobos/std_net_curl.html#.HTTP (Sorry, I assumed that was a given since it's a standard library type. Poor assumption,

Re: Handling arbitrary char ranges

2016-04-20 Thread Matt Kline via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 19:29:22 UTC, ag0aep6g wrote: Maybe use ubyte[] for the buffer type instead. I don't have an option here, do I? I assume HTTP.onSend doesn't take a `delegate size_t(ubyte[])` insetad of a `delegate size_t(void[])`, and that the former isn't implicitly convertibl

Handling arbitrary char ranges

2016-04-20 Thread Matt Kline via Digitalmars-d-learn
I'm doing some work with a REST API, and I wrote a simple utility function that sets an HTTP's onSend callback to send a string: @property outgoingString(ref HTTP request, const(void)[] sendData) { import std.algorithm : min; request.contentLength = sendData.length; auto

Re: Cannot link using DMD nightly

2016-02-28 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 28 February 2016 at 22:16:39 UTC, Rene Zwanenburg wrote: On Sunday, 28 February 2016 at 19:02:21 UTC, Matt Elkins wrote: Any suggestions? I don't know how to fix that error, but 2.070.1 has been released and contains a fix for your issue: http://dlang.org/changelog/2.070.1

Cannot link using DMD nightly

2016-02-28 Thread Matt Elkins via Digitalmars-d-learn
I'm attempting to use the DMD nightly build (because this fix matters a lot to my project: https://issues.dlang.org/show_bug.cgi?id=15661), but the build fails at the link step. Here is my full output: [output] "C:\Program Files (x86)\dub\dub.exe" run --force --build debug --build-mode separa

Re: Arrays of noncopyables/Invalid memory operation

2016-02-19 Thread Matt Elkins via Digitalmars-d-learn
On Thursday, 18 February 2016 at 01:14:00 UTC, ZombineDev wrote: https://issues.dlang.org/show_bug.cgi?id=15661. I suggest testing this code again with a newer compiler (see my answer in the other thread - http://forum.dlang.org/post/omfyqfulgyzbrxlzr...@forum.dlang.org). Thanks -- I might ge

Re: Arrays of noncopyables/Invalid memory operation

2016-02-19 Thread Matt Elkins via Digitalmars-d-learn
On Friday, 19 February 2016 at 01:30:13 UTC, H. S. Teoh wrote: Suppose the array gets moved sometime after i=500 because it ran out of space in the current memory location. Since there is another slice middleSlice pointing at the old data, it's not just a matter of *moving* the elements over t

Arrays of noncopyables/Invalid memory operation

2016-02-17 Thread Matt Elkins via Digitalmars-d-learn
So in a different thread someone mentioned that when arrays are grown an implicit copy could be called on all the elements, as they might need to be copied over to a new, larger block of memory. This makes sense, and is expected. However, it got me concerned: what if the post-blit was disabled

Re: Confusion regarding struct lifecycle

2016-02-17 Thread Matt Elkins via Digitalmars-d-learn
On Wednesday, 17 February 2016 at 07:10:15 UTC, ZombineDev wrote: The downside is that it really indicates that I didn't reduce my buggy program properly. I'll hold out for the live-object-destructor-call fix to see whether that corrects my problem; I can just leak resources until then :). So

Re: Confusion regarding struct lifecycle

2016-02-16 Thread Matt Elkins via Digitalmars-d-learn
On Wednesday, 17 February 2016 at 02:23:52 UTC, Ali Çehreli wrote: Since a static array must consist of .init values to begin with, every move into its members must also trigger its destructor if the type has elaborate destructor. Oof. This strikes me as a "gotcha", that this happens even with

Re: Confusion regarding struct lifecycle

2016-02-16 Thread Matt Elkins via Digitalmars-d-learn
After some more time spent on (the non-reduced version of) this, I think there is a decent chance I am really just experiencing another manifestation of a bug I reported a little bit ago: https://issues.dlang.org/show_bug.cgi?id=15661 The good news is that this is now marked as resolved, so h

Re: Confusion regarding struct lifecycle

2016-02-16 Thread Matt Elkins via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 10:45:09 UTC, Marc Schütz wrote: On Tuesday, 16 February 2016 at 04:00:27 UTC, Mike Parker wrote: On Tuesday, 16 February 2016 at 03:39:00 UTC, Matt Elkins wrote: On Tuesday, 16 February 2016 at 03:31:51 UTC, maik klein wrote: In D you can always call Foo.init

Re: Confusion regarding struct lifecycle

2016-02-16 Thread Matt Elkins via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 08:18:51 UTC, Ali Çehreli wrote: When a temporary Foo object is moved into the array, the temporary object is set to Foo.init. This temporary object lives on the stack. In fact, all temporary Foo objects of Foo.this(int) live at the same location. After Foo(8)

Re: Confusion regarding struct lifecycle

2016-02-15 Thread Matt Elkins via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 03:31:51 UTC, maik klein wrote: In D you can always call Foo.init even with @disable this(), Foo.init can be called implicitly (not just explicitly)? If so, why even have @disable this(), if it offers no guarantees? The first 3 destructor calls are from the 3

Confusion regarding struct lifecycle

2016-02-15 Thread Matt Elkins via Digitalmars-d-learn
I've been bitten again by my lack of understanding of the D struct lifecycle :-/. I managed to reduce my buggy program to the following example: [code] import std.stdio; struct Foo { @disable this(); @disable this(this); this(int valueIn) {value = valueIn;} ~this() {writeln("F

Re: Things that keep D from evolving?

2016-02-12 Thread Matt Elkins via Digitalmars-d-learn
On Friday, 12 February 2016 at 17:20:23 UTC, rsw0x wrote: On Friday, 12 February 2016 at 15:12:19 UTC, Steven Schveighoffer wrote: On 2/12/16 9:37 AM, Matt Elkins wrote: [...] Pass by reference and pass by value means different treatment inside the function itself, so it can't differ

Re: Things that keep D from evolving?

2016-02-12 Thread Matt Elkins via Digitalmars-d-learn
On Friday, 12 February 2016 at 15:12:19 UTC, Steven Schveighoffer wrote: It could potentially differ based on the type being passed, Yes, that's what I meant. but I'm unaware of such an optimization, Hm. Unfortunate. and it definitely isn't triggered specifically by 'in'. 'in' is literall

Re: Things that keep D from evolving?

2016-02-12 Thread Matt Elkins via Digitalmars-d-learn
On Friday, 12 February 2016 at 14:03:05 UTC, Steven Schveighoffer wrote: On 2/10/16 11:51 PM, Matt Elkins wrote: * The in keyword. This is nice syntactic sugar over having a special trait in C++ which deduces whether to pass by value or const-reference. "foo(in bar)" is way mor

Re: Things that keep D from evolving?

2016-02-10 Thread Matt Elkins via Digitalmars-d-learn
On Thursday, 11 February 2016 at 05:05:22 UTC, tsbockman wrote: On Thursday, 11 February 2016 at 04:51:39 UTC, Matt Elkins wrote: - Syntactic sugars (associtive arrays, powerful foreach, slices...) I'm still adjusting to the idea of AAs as part of the language rather than library. Not s

Re: Things that keep D from evolving?

2016-02-10 Thread Matt Elkins via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 13:41:30 UTC, NX wrote: There are several reasons I want to use D rather than C# / Go / something else: I will focus on comparing against C++, because that has been my favorite general purpose language for a long time. While I often have to use C, Java, C#, etc.

Re: Odd Associative Array Reference Behavior

2016-02-10 Thread Matt Elkins via Digitalmars-d-learn
On Thursday, 11 February 2016 at 03:47:09 UTC, Steven Schveighoffer wrote: Misunderstanding. An AA under the hood is simply a pointer. Initialized to null. When you pass it around, you are passing a pointer. AA assign checks for null and allocates a new AA impl to hold the data. But this does

Odd Associative Array Reference Behavior

2016-02-10 Thread Matt Elkins via Digitalmars-d-learn
Consider the following definition of Foo and an accompanying unittest: [code] struct Foo { @property int[int] aa() {return m_aa;} @property ref int[int] aaRef() {return m_aa;} int[int] m_aa; } unittest { Foo foo; assert(5 !in foo.m_aa); // Sanity-check to start off foo.a

Re: Odd Destructor Behavior

2016-02-08 Thread Matt Elkins via Digitalmars-d-learn
On Monday, 8 February 2016 at 07:31:07 UTC, Daniel Kozak wrote: Seems to me too, please report it on issues.dlang.org Reported: https://issues.dlang.org/show_bug.cgi?id=15661

Re: Odd Destructor Behavior

2016-02-07 Thread Matt Elkins via Digitalmars-d-learn
Some environment information: DMD 2.070 32-bit Windows 7 (64-bit)

Re: Odd Destructor Behavior

2016-02-07 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 7 February 2016 at 23:11:34 UTC, anonymous wrote: On 07.02.2016 23:49, Matt Elkins wrote: Oi. Yes, I can, but it is quite a lot of code even if you don't count that it is dependent on OpenGL, GLFW, and gl3n to run to this point. This is why I was disappointed that si

Re: Odd Destructor Behavior

2016-02-07 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 7 February 2016 at 22:04:27 UTC, anonymous wrote: On 07.02.2016 22:49, Matt Elkins wrote: From this non-reduced situation, does anything jump out? Am I missing something about struct lifetimes? This is the only place I instantiate a TileView. Looks weird. I presume this doesn&#

Re: Odd Destructor Behavior

2016-02-07 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 7 February 2016 at 22:35:57 UTC, anonymous wrote: On 07.02.2016 23:07, Márcio Martins wrote: The destructor you are seeing is from the assignment: m_tileView = TileView(...); This creates a temporary TileView, copies it to m_tileView, and then destroys it. I suppose you want to mov

Odd Destructor Behavior

2016-02-07 Thread Matt Elkins via Digitalmars-d-learn
I've been experiencing some odd behavior, where it would appear that a struct's destructor is being called before the object's lifetime expires. More likely I am misunderstanding something about the lifetime rules for structs. I haven't been able to reproduce with a particularly minimal example

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:20:52 UTC, Steven Schveighoffer wrote: Oh, nevermind. This is actually simpler. You can't do memory operations inside a destructor during collection. I forgot about that. But the rule I stated is still in force. -Steve So this implies that the UniquePtr imp

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:11:07 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already collected, and you are invalidly attempting to

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:10:03 UTC, Matt Elkins wrote: On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already collected, and you are invalidly attempting to re-free it. The GC can collect this memory even though there is

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 20:07:26 UTC, Steven Schveighoffer wrote: What is likely happening is that ptr is already collected, and you are invalidly attempting to re-free it. The GC can collect this memory even though there is still an outstanding root-reachable pointer to it?

Re: Ownership semantics

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 19:34:43 UTC, maik klein wrote: I recently asked a question about ownership semantics in D https://stackoverflow.com/questions/35115702/how-do-i-express-ownership-semantics-in-d But a few minutes ago I found an answer on SO that could potentially explain a lot.

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 18:02:19 UTC, Matt Elkins wrote: Here is the one I am using right now: Actually, here is the whole module in case you are interested in the unittests/usage: [code] import std.algorithm; import std.traits; struct ResourceHandle(T, alias Deleter, T Default

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:55:53 UTC, Matt Elkins wrote: Errr, ignore the makeFoo() line. Left that in by accident, has no bearing on the issue. Ok, I think I understand why this doesn't work, at least. The Foo passed into bar() is, of course, an lvalue itself. So I can achieve

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:48:53 UTC, maik klein wrote: The problem is that x will be copied afaik which is not what you want if you want to deal with ownership. I think that can be solved by wrapping the resource in a struct that deals with passing the ownership. Here is the one I am us

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
Errr, ignore the makeFoo() line. Left that in by accident, has no bearing on the issue.

Re: Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
On Sunday, 31 January 2016 at 17:42:19 UTC, anonymous wrote: I don't know if this works in all cases, but it passes that simple test: @disable void foo(ref int x); void foo(int x) {} void main() { foo(5); /* works */ int y = 5; foo(y); /* error */ } My fault, I should h

Declaring rvalue function arguments

2016-01-31 Thread Matt Elkins via Digitalmars-d-learn
I know I can mark an argument ref to require lvalues, so I'm wondering whether there is an equivalent for rvalues; that is, is there a way to specify that an argument to a function MUST be an rvalue? For example, in C++ I can do this: [code] void foo(int && x) {...} foo(5); // Works fine int

Re: Access Violation in @safe Code

2016-01-30 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 13:37:43 UTC, Kagamin wrote: Alias templates require stack pointer, init probably has it set to null. Try this: FooType foo = FooType(); Yes, that fixed it. Interesting.

Re: Conditional nothrow/safe/nogc/etc?

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 05:57:34 UTC, H. S. Teoh wrote: A common idiom that we use is to write an attributed unittest to verify that the function itself is @safe/etc.. This way, if instantiated with safe/etc. types, the template will also be safe/etc., but if instantiated with an unsafe

Re: Access Violation in @safe Code

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 05:18:08 UTC, Steven Schveighoffer wrote: https://issues.dlang.org/enter_bug.cgi -Steve Added! https://issues.dlang.org/show_bug.cgi?id=15627 Thanks for the help.

Re: Conditional nothrow/safe/nogc/etc?

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 05:25:49 UTC, Rikki Cattermole wrote: On 30/01/16 6:17 PM, Matt Elkins wrote: [...] templated functions have attribute inference. Meaning if it can be nothrow it will be. Regarding your real use case, again struct if templated so it should be inferred

Conditional nothrow/safe/nogc/etc?

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
Is there any way to specify that a generic function is conditionally nothrow (or other function decorators), based on whether the template instantiation is nothrow? I'm looking for something akin to C++'s noexcept(noexcept()), e.g.: template void foo() noexcept(noexcept(T())) {} I don't see

Access Violation in @safe Code

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
Title says it; I get an access violation in code marked @safe. Here's a minimal example: [code] @safe: struct Foo(alias Callback) { ~this() {Callback();} } unittest { uint stackVar; alias FooType = Foo!((){++stackVar;}); FooType[1] foos; foos[0] = FooType.init; } [/code]

Re: Relocatable objects and internal pointers

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 03:00:11 UTC, Steven Schveighoffer wrote: There are some really smart people who frequent these forums, if you post your actual use case, you may get an answer that you hadn't thought of. Yeah, I tried that first (on the general forum, since at the time I didn'

Re: Relocatable objects and internal pointers

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 02:09:55 UTC, Steven Schveighoffer wrote: I figured out a way to have them. You just have to guarantee you don't copy the actual "pointer" out of the struct: https://forum.dlang.org/post/mk5k4l$s5r$1...@digitalmars.com Unfortunately, that won't work for what I

Re: d plugin for Intelij Idea debuging support

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Friday, 29 January 2016 at 12:00:25 UTC, Pavel wrote: Hello! Is there any debuging support for Intelij Idea's D plugin? Thanks! I can't say for certain, but the website (https://github.com/kingsleyh/DLanguage) lists this as an upcoming feature by the end of 2016, so I think there probabl

Re: Relocatable objects and internal pointers

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 01:28:54 UTC, H. S. Teoh wrote: On Sat, Jan 30, 2016 at 01:21:27AM +, Matt Elkins via Digitalmars-d-learn wrote: On Saturday, 30 January 2016 at 01:18:33 UTC, Ali Çehreli wrote: >Definitely so. Rvalues are moved around all the time. The >following p

Re: Relocatable objects and internal pointers

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
On Saturday, 30 January 2016 at 01:18:33 UTC, Ali Çehreli wrote: Definitely so. Rvalues are moved around all the time. The following program has two rvalue moves without calling post-blits or destructors. Oi, that makes life tough. Ok, I'll figure something else out, then... Thanks for the

Relocatable objects and internal pointers

2016-01-29 Thread Matt Elkins via Digitalmars-d-learn
Hi all, I'm a C++ programmer trying to decide whether to switch my main focus to D, and so I'm working on a pet project using it. So far I really like some of the practical aspects of the language (built-in contracts are great, the metaprogramming is very accessible, and I can't enough of these

Re: Detecting premature end of spawned threads with std.concurrency

2015-09-04 Thread Matt Kline via Digitalmars-d-learn
On Friday, 4 September 2015 at 08:33:08 UTC, Marc Schütz wrote: They're called `OwnerTerminated` and `OwnerFailed` with an "r". No, that's received by the child if the owning thread exits. I'm talking about the "parent" thread attempting to send to a child thread that has exited. Relevant p

Detecting premature end of spawned threads with std.concurrency

2015-09-03 Thread Matt Kline via Digitalmars-d-learn
TDPL suggests that calls to std.concurrency.send will fail with an "OwnedTerminated" or "OwnedFailed" exception if the destination thread has exited, but neither the docs nor the current Phobos implementation make any mention of such exceptions. Thinking the information was just outdated, I se

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

Re: Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
As it turns out, inputRangeObject does an excellent job at this task. The solution then becomes something like: InputRange!string getEntries(string[] paths, bool recursive) { auto files = paths.filter!(p => p.isFile); if (recursive) { auto expandedDirs = paths .filte

Re: Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
On Monday, 6 July 2015 at 21:35:53 UTC, Alex Parrill wrote: They aren't actually the same types I understand the problem - I was just wondering if there was a standard library solution to this or if I would have to roll my own. use a class wrapper in std.range.interface [1]. [1]: http://

Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
Say I'm trying to expand an array of file and directory paths (such as ones given as command line args) into a range of file paths I can iterate over. A simplified example might be: auto getEntries(string[] paths, bool recursive) { auto files = paths.filter!(p => p.isFile); if (recursi

Re: Distinguish recursive Templates

2015-05-22 Thread Matt Kline via Digitalmars-d-learn
On Friday, 22 May 2015 at 21:13:50 UTC, Manfred Nowak wrote: How can one determine the recursion depth for templated types? Example code: import std.stdio; class Set(T){ override string toString(){ return "Set"; } } void main(){ auto s0= new Set!uint; writeln( s0); // writes Set

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 penitenc

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\

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 &q

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

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 packa

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

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

  1   2   >