Re: How to specify an exact template?

2021-01-16 Thread Tove via Digitalmars-d-learn
On Saturday, 16 January 2021 at 15:41:38 UTC, solidstate1991 
wrote:

On Saturday, 16 January 2021 at 14:18:55 UTC, Tove wrote:
probably you can use 
https://dlang.org/spec/traits.html#getOverloads


I don't know how to use it with functions outside of 
structs/classes.


void foo() {}
void foo(string i) {}

static foreach(overload; __traits(getOverloads, 
mixin(__MODULE__), "foo"))

pragma(msg, typeof(overload));


Re: How to specify an exact template?

2021-01-16 Thread Tove via Digitalmars-d-learn
On Saturday, 16 January 2021 at 14:14:57 UTC, solidstate1991 
wrote:
On Saturday, 16 January 2021 at 14:13:29 UTC, solidstate1991 
wrote:

Here's the following line, among many others:

return &alphaBlend32bitMV!(ubyte);

This generates an error, as this function template matches two 
instances, but currently I don't know how to choose the one I 
need, other than write a local function, that looks a bit ugly.


Forgot to link the code example: 
https://github.com/ZILtoid1991/pixelperfectengine/blob/master/pixeperfectengine/src/PixelPerfectEngine/graphics/layers/base.d#L143


probably you can use 
https://dlang.org/spec/traits.html#getOverloads




reference counting resources but NOT memory

2021-01-16 Thread Tove via Digitalmars-d-learn
Is there any elegant/smart solution to reference counting 
resources without ever freeing any objects?


When the ref hits 0 it should free some other resource that isn't 
memory...


Resource[10] resources;

resources[3].inc; // 1 ref - 0->1 transition enable  some feature
resources[3].dec; // 0 ref - 1->0 transition disable some feature
resources[3].inc; // 1 ref - instantly ready to be used again 
without any alloc/free


Maybe it's best to use normal constructor/destructor with some 
arena memory allocator that never actually frees anything? Must 
be a common problem, anyone got experience with a good design?




Store multiple identical objects in a key:ed datastructure?

2019-11-01 Thread Tove via Digitalmars-d-learn
Consider a complex key that is a combination of multiple 
variables.


struct key
{
  intfoo = 1;
  string bar = "joy";
  string baz = "huzza";
}

The value is a very large object.

struct value
{
  int[4096] payload;
}

There are 10.000s of different keys.
But typically only ~10 different values.

My first idea was to have an array/set of unique value instances 
and store only the index to the array in the key:ed data 
structure, this way it's possible to reallocate and extend the 
array.


Is there an idiomatic way to solve this in D? Or should I just 
get my hands dirty and do the brute force implementation of the 
above idea?