Template Parameters in Struct Member Functions

2015-08-22 Thread DarthCthulhu via Digitalmars-d-learn
I'm having difficulty understanding how templates operate as function parameters. Say I have this: struct ArrayTest { void arrayTest(T) (T arrayT) { writeln(arrayT); } } unittest { ArrayTest test; float farray[] = [ 0.5f, 0.5f,

Re: Template Collections of Different Types

2015-08-15 Thread DarthCthulhu via Digitalmars-d-learn
On Sunday, 16 August 2015 at 01:51:36 UTC, Adam D. Ruppe wrote: On Sunday, 16 August 2015 at 01:39:54 UTC, DarthCthulhu wrote: How would one store the Property objects in the PropertyCollection? You don't, not like that anyway. The attach call is the ruin of it. If it was all one definition,

Template Collections of Different Types

2015-08-15 Thread DarthCthulhu via Digitalmars-d-learn
Say I want to do something like: Propertery!int pi = 42; PropertyCollection pc; pc.attach(Life_and_Everything, pi); assert(pc.Life_and_Everything == 42); Property!string ps = Hello World; pc.attach(text, ps); assert(pc.text == Hello World); How would one store the Property objects in the

Theoretical Best Practices

2015-08-14 Thread DarthCthulhu via Digitalmars-d-learn
This is more a theoretical exercise than specific code nitty gritty, but... Let's say I have some code like this: class World { // Bunch of members and other functions void happyDay () { if (bCthulhuRises) { debug(logging) {

Re: Theoretical Best Practices

2015-08-14 Thread DarthCthulhu via Digitalmars-d-learn
On Friday, 14 August 2015 at 12:40:08 UTC, Steven Schveighoffer wrote: I would do it this way: // at module level debug(logging) { Logger logger; static this() { logger = new Logger;} } If you want to have the logger be global, add 'shared' to both the logger and the static this.

Re: Theoretical Best Practices

2015-08-14 Thread DarthCthulhu via Digitalmars-d-learn
On Friday, 14 August 2015 at 23:17:44 UTC, Tofu Ninja wrote: On Friday, 14 August 2015 at 22:25:15 UTC, DarthCthulhu wrote: Ahh, that is a much cleaner way to do it rather than using a singleton. By 'module level', I assume you mean in the module that defines the Logger class? An 'import

Re: Derelict, SDL, and OpenGL3: Triangle Tribulations

2015-08-12 Thread DarthCthulhu via Digitalmars-d-learn
On Wednesday, 12 August 2015 at 05:26:33 UTC, JN wrote: You need a vertex and a fragment shader. You can't render anything in OGL3 without shaders. I thought that was the case, but the tutorial I was looking at didn't have any shaders at that point. I added a shader program. Also, you

Derelict, SDL, and OpenGL3: Triangle Tribulations

2015-08-11 Thread DarthCthulhu via Digitalmars-d-learn
So I decided to try some OGL3 stuff in D utilizing the Derelict bindings and SDL. Creating an SDL-OGL window worked fine, but I'm having trouble with doing the most basic thing of rendering a triangle. I get the window just fine and the screen is being properly cleared and buffered, but no

Re: Dynamic array and foreach loop

2015-08-08 Thread DarthCthulhu via Digitalmars-d-learn
On Saturday, 8 August 2015 at 15:57:15 UTC, Binarydepth wrote: Here's what happens : How many elements need to be used? 5 Input the element : 1 1 Input the element : 1 2 Input the element : 1 3 Input the element : 1 4 Input the element : 1 5 How many positions do you wish to rotate ? 3 The

Re: Creating a Priority Queue: An Adventure

2015-08-07 Thread DarthCthulhu via Digitalmars-d-learn
Okay, so, I decided to scrap the BinaryHeap version of the priority queue, going back to basics and utilizing a simple array. It works, huzzah! Code: module data_structures.priority_queue; import std.array; import std.range: assumeSorted; import std.typecons: Tuple; /* Templated

Re: Creating a Priority Queue: An Adventure

2015-08-05 Thread DarthCthulhu via Digitalmars-d-learn
On Wednesday, 5 August 2015 at 09:04:54 UTC, Nordlöw wrote: On Wednesday, 5 August 2015 at 01:02:56 UTC, DarthCthulhu wrote: I must be doing something really stupid here, but I have no clue what it is. Anyone know? For functional behaviour I prefer a postblit that duplicates the underlying

Creating a Priority Queue: An Adventure

2015-08-04 Thread DarthCthulhu via Digitalmars-d-learn
So I've just gotten into D and decided to have a go at creating something relatively simple to get my feet wet: a priority queue. Seemed like a simple enough thing, right? It's a pretty basic data structure, it can't possibly be THAT difficult, right? First, I tried using associative arrays

Re: Creating a Priority Queue: An Adventure

2015-08-04 Thread DarthCthulhu via Digitalmars-d-learn
On Wednesday, 5 August 2015 at 01:27:53 UTC, Steven Schveighoffer wrote: On 8/4/15 9:02 PM, DarthCthulhu wrote: writefln(PQ: %s, pq.queue); - prints PQ: [Tuple!(int, string)(3, HELLO3), Tuple!(int, string)(10, HELLO10), Tuple!(int, string)(11, HELLO11)] This is probably consuming your

Re: Creating a Priority Queue: An Adventure

2015-08-04 Thread DarthCthulhu via Digitalmars-d-learn
On Wednesday, 5 August 2015 at 02:26:48 UTC, Meta wrote: On Wednesday, 5 August 2015 at 01:27:53 UTC, Steven Schveighoffer wrote: On 8/4/15 9:02 PM, DarthCthulhu wrote: writefln(PQ: %s, pq.queue); - prints PQ: [Tuple!(int, string)(3, HELLO3), Tuple!(int, string)(10, HELLO10), Tuple!(int,