Re: local variable naming convention

2013-12-20 Thread kdmult

On Friday, 20 December 2013 at 09:15:26 UTC, Boyd wrote:

this(int x, int y)
{
   X = x;
   Y = y;
}

So now my question is, how do you distinguish between member 
and local vars in such cases?


this(int x, int y)
{
   this.x = x;
   this.y = y;
}


Re: Compilation depends on class methods order

2013-12-20 Thread kdmult
On Friday, 20 December 2013 at 08:42:34 UTC, Andrej Mitrovic 
wrote:

On 12/20/13, kdmult  wrote:

But why the order of the
declarations has an effect on the compilation result.


I think you should file this as a bug.


Done.
https://d.puremagic.com/issues/show_bug.cgi?id=11785


Re: Compilation depends on class methods order

2013-12-20 Thread kdmult

On Friday, 20 December 2013 at 08:03:26 UTC, FreeSlave wrote:

Make first read function templated too like this:

long read()( ubyte* bytes, long len )


In fact, there are workarouns. But why the order of the 
declarations has an effect on the compilation result.


Namely, if the templated overloaded function goes after the 
non-templated one then the compilation fails.

FAILED:
long read( ubyte* bytes, long len ) { return 0; }
void read(T)( ref T val ) { read(cast(ubyte*)&val, 
cast(long)val.sizeof); }


Otherwise, if the templated overloaded function goes before the 
non-templated one then the compilation is successful.

SUCCEEDED:
void read(T)( ref T val ) { read(cast(ubyte*)&val, 
cast(long)val.sizeof); }

long read( ubyte* bytes, long len ) { return 0; }

Why?


Compilation depends on class methods order

2013-12-19 Thread kdmult

Hi,

Why compilation depends on order of method declarations?

The following test case does not compile.

However, if we change the order of the 'read' methods in class 
InputStream below then  compilation will not fail.


Is it a bug?

---
module test;

import std.traits : isBasicType;
import std.typetuple : TypeTuple;

class InputStream {

long read( ubyte* bytes, long len )
{
return 0;
}

void read(T)( ref T val ) if (isBasicType!T)
{
read(cast(ubyte*)&val, cast(long)val.sizeof);
}

}

void main()
{
auto input = new InputStream;

foreach (T; TypeTuple!(long, int, short, byte))
{
T v;
input.read(v);
}
}
---

Thanks.


Re: tuple parameter fwd

2013-08-06 Thread kdmult

On Tuesday, 6 August 2013 at 09:53:33 UTC, Ali Çehreli wrote:
Do you mean that when P[0] is already an instance of A, then R 
should be P[0]. Otherwise, R should be A!P? If so, the 
following works:


class A(P...)
{
pragma(msg, "\nA: " ~ P.stringof);
}

class BImpl(R, P...)
{
pragma(msg, "R: " ~ R.stringof ~ ", P: " ~ P.stringof);
}

template B(P...)
{
static if (is (P[0] == A!U, U)) {
/* The first type is already an A instance. Accept the 
types as is. */

alias B = BImpl!P;

} else {
/* The first type is not an A instance. Inject one. */
alias B = BImpl!(A!P, P);
}
}

void main()
{
auto b0 = new B!(int, double, char);
auto b1 = new B!(A!long, int, double);
}

Ali


Great! Thanks Ali.


Re: tuple parameter fwd

2013-08-05 Thread kdmult

On Tuesday, 6 August 2013 at 05:07:51 UTC, Ali Çehreli wrote:

On 08/05/2013 09:51 PM, kdmult wrote:

On Monday, 5 August 2013 at 18:45:49 UTC, kdmult wrote:

class A(P...) {}

class B(R = A!P, P...) {}

P... should be rightmost, so how can I use it in the 
preceding parameter?


The default parameter value doesn't make sense as it's shown 
above.

Actually I want to port C++ code which looks like below.

template 
class A1 {};
template  >
class B1 {}

template 
class A2 {};
template  >
class B2 {}

and so on.

I would use the variadic template parameters. However, I have 
no idea

how it can be done. Please advise.

Thanks.


Direct translation seems to work:

class A1(P1) {}
class B1(P1, R = A1!P1) {}

class A2(P1, P2) {}
class B2(P1, P2, R = A2!(P1, P2)) {}

void main()
{
auto a1 = new A1!int;
auto b1d = new B1!int;
auto b1 = new B1!(int, A1!double);
auto a2 = new A2!(int, double);
auto b2d = new B2!(int, double);
auto b2 = new B2!(int, double, A2!(char, short));
}

Ali


Is there a way to use variadic template/class parameter instead
of P1, P2, ..., PN ? If it is I could create 2 templated classes
instead of all that copy/pasted classes with P1, P2, etc
parameters.

Thanks.


Re: tuple parameter fwd

2013-08-05 Thread kdmult

On Monday, 5 August 2013 at 18:45:49 UTC, kdmult wrote:

class A(P...) {}

class B(R = A!P, P...) {}

P... should be rightmost, so how can I use it in the preceding 
parameter?


The default parameter value doesn't make sense as it's shown 
above.

Actually I want to port C++ code which looks like below.

template 
class A1 {};
template  >
class B1 {}

template 
class A2 {};
template  >
class B2 {}

and so on.

I would use the variadic template parameters. However, I have no 
idea how it can be done. Please advise.


Thanks.


tuple parameter fwd

2013-08-05 Thread kdmult

Hi,

I would like to use a tuple template parameter in the default 
value of another template parameter in the same class declaration 
as follows.


class A(P...) {}

class B(R = A!P, P...) {}

P... should be rightmost, so how can I use it in the preceding 
parameter?


Thanks.