Re: How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn
Well, it's quite complicated to do. I have to manually unwrap each and all function template, then pray for the compile-time optimization gods that they'll be inlined. This is so annoying, that I might issue a DIP...

Re: How define accepted types in a template parameter?

2021-01-16 Thread Basile B. via Digitalmars-d-learn
On Saturday, 16 January 2021 at 18:39:03 UTC, Marcone wrote: For example, I want my function template to only accept integer or string; You can do that with either - `static if` inside the body [1] import std.traits; void foo(T)(T t) { static if (isIntegral!T) {} else static

Re: How define accepted types in a template parameter?

2021-01-16 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 16 January 2021 at 18:39:03 UTC, Marcone wrote: For example, I want my function template to only accept integer or string; There are different ways of doing that. I'd say this one is easy to follow: import std.stdio; void print(T)(T entry) if(is(T==string) || is(T==int)) {

How define accepted types in a template parameter?

2021-01-16 Thread Marcone via Digitalmars-d-learn
For example, I want my function template to only accept integer or string;

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

Re: How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn
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.

Re: reference counting resources but NOT memory

2021-01-16 Thread rikki cattermole via Digitalmars-d-learn
What you are describing sounds like regular reference counting. All resources (i.e. windows) are pinned somewhere in memory. Its just that you have to use special API's to destroy them rather than free.

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 !(ubyte); This generates an error, as this function template matches two instances, but currently I

Re: How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn
On Saturday, 16 January 2021 at 14:13:29 UTC, solidstate1991 wrote: Here's the following line, among many others: return !(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

How to specify an exact template?

2021-01-16 Thread solidstate1991 via Digitalmars-d-learn
Here's the following line, among many others: return !(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.

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