Re: Template specialisation for range of types

2017-03-12 Thread Meta via Digitalmars-d-learn
On Sunday, 12 March 2017 at 21:12:13 UTC, data pulverizer wrote: On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote: auto max(T: const U, U)(T* x, T* y) <- Changed `ConstOf!U` to `const U` { writeln("Const template"); return *x > *y ? x : y; } How detailed can I be about

Re: Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote: auto max(T: const U, U)(T* x, T* y) <- Changed `ConstOf!U` to `const U` { writeln("Const template"); return *x > *y ? x : y; } How detailed can I be about the template specialisation? From example in the book "C++ the

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
Meta wrote: On Sunday, 12 March 2017 at 20:22:33 UTC, ketmar wrote: Meta wrote: The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not... no, not a bug. this is the way type

Re: Template specialisation for range of types

2017-03-12 Thread Meta via Digitalmars-d-learn
On Sunday, 12 March 2017 at 20:22:33 UTC, ketmar wrote: Meta wrote: The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not... no, not a bug. this is the way type deconstruction

Re: Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 12 March 2017 at 20:15:43 UTC, Meta wrote: import std.stdio : writeln; import std.traits : ConstOf; auto max(T)(T x, T y) { writeln("General template"); return x > y ? x : y; } auto max(T: const U, U)(T* x, T* y) <- Changed `ConstOf!U` to `const U` {

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
Meta wrote: The reason this doesn't work is when you use ConstOf!U, it's not looking for a `const U`, it's looking for the type `ConstOf!U`. I'm not sure if this is a bug or not... no, not a bug. this is the way type deconstruction works: it checks if your type was constructed with a given

Re: Template specialisation for range of types

2017-03-12 Thread Meta via Digitalmars-d-learn
On Sunday, 12 March 2017 at 18:49:22 UTC, data pulverizer wrote: Hello all, I am attempting to write templates for differently qualified types using specialisations. Below is an example for const and non-const outlining my approach: `` import std.stdio : writeln;

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
data pulverizer wrote: I need at least those two implementation for the different cases, a general "default", and for specified types and type qualifications. p.s.: if you want that to work with both pointers and non-pointers, you have to add more constraints, to remove further conflicts.

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
data pulverizer wrote: If I change the implementation of the second template to your above declaration, I get the error: max.max called with argument types (const(double)*, const(double)*) matches both: max.d(34): max.max!(const(double)*).max(const(double)* x, const(double)* y) and:

Re: Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 12 March 2017 at 19:32:37 UTC, ketmar wrote: data pulverizer wrote: In this case would like to use the ConstOf specialisation instead of the default implementation for the inputs which are const. actually, second template is uninstantiable at all. you want to do type

Re: Template specialisation for range of types

2017-03-12 Thread ketmar via Digitalmars-d-learn
data pulverizer wrote: In this case would like to use the ConstOf specialisation instead of the default implementation for the inputs which are const. actually, second template is uninstantiable at all. you want to do type deconstruction at instantiation, and that doesn't work. i.e. what

Re: Template specialisation for range of types

2017-03-12 Thread Jerry via Digitalmars-d-learn
On Sunday, 12 March 2017 at 18:49:22 UTC, data pulverizer wrote: Hello all, I am attempting to write templates for differently qualified types using specialisations. Below is an example for const and non-const outlining my approach: `` import std.stdio : writeln;

Template specialisation for range of types

2017-03-12 Thread data pulverizer via Digitalmars-d-learn
Hello all, I am attempting to write templates for differently qualified types using specialisations. Below is an example for const and non-const outlining my approach: `` import std.stdio : writeln; import std.traits : ConstOf; auto max(T)(T x, T y) {