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
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
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
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
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`
{
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
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;
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.
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:
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
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
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;
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)
{
13 matches
Mail list logo