This page about C#:
http://msdn.microsoft.com/en-us/library/ms173174%28VS.80%29.aspx
contains this C# code:
class Mammals {}
class Dogs : Mammals {}
class Program {
public delegate Mammals HandlerMethod();
public static Mammals FirstHandler() { return null; }
public static Dogs Secon
On 21/03/10 00:18, bearophile wrote:
Robert Clipsham:
Why is this?
It's not a hard question. This code compiles:
class Foo {
const(Foo) myFoo() const {
return this;
}
}
void main() {
auto f = new Foo;
}
It's just in a const function the "this" is const, so if you want
Robert Clipsham:
> Why is this?
It's not a hard question. This code compiles:
class Foo {
const(Foo) myFoo() const {
return this;
}
}
void main() {
auto f = new Foo;
}
It's just in a const function the "this" is const, so if you want to return it,
then you have to use a "con
According to http://digitalmars.com/d/2.0/const3.html:
Const member functions are functions that are not allowed to change any
part of the object through the member function's this reference.
With the following code:
class Foo
{
Foo myFoo() const
{
On 2010-03-20 00.29, bearophile wrote:
(I am looking for rough corners in D, or in my knowledge of D.)
In this page:
http://www.digitalmars.com/d/2.0/templates-revisited.html
In the section "Template Parameters" there is written:
P:P*, // P must be a pointer type
-
So
bearophile Wrote:
> Paul D. Anderson:
>
> > After further review, I now realize that the right way (for me) to do this
> > is to add a .dup property.<
>
> Steven Schveighoffer has given you quite good answers.
> A dup is generally not enough, because what you dup can have other immutable
> ref
Jesse Phillips Wrote:
> Spacen Jasset wrote:
>
> > then presumably the syntax you are using is a bashism?. You could also
> > say something like:
> >
> >
> > system("bash mkdir -p " ~ path);
> >
> >
> > Messing with your sh symlink may have some undesired consequences.
>
> Actually, not messing
On 03/20/2010 01:58 AM, Paul D. Anderson wrote:
I created a struct, call it "S", and some functions that operate on S. But I'm
confused about when const is useful.
Being an old Java programmer, I use 'const' the same as I used 'final' in Java.
So most of my functions look like this:
S for(con
Daniel Keep:
> You do realise that "Template Parameters" are a completely different
> thing to "is expressions", right?
Nope. And from the other answers by Moritz and Ellery it seems I am not alone
:-)
You are right, this works:
template IsPointer1(T:T*) {
enum bool IsPointer1 = true;
}
tem
Don:
> I think the problem is really that it's still very buggy. In particular,
> opAssign seems pretty defective. More importantly, struct constructors,
> post blit, and struct destructors are still quite badly broken.
You are right, but in my opinion it's not just a matter of bugs. To solve re
bearophile wrote:
Operator overloading in D2 is not an easy thing, it needs training.
>(That's why I have recently asked for the compiler to be strict to
avoid wrong usages of the operator overloading.)
I think the problem is really that it's still very buggy. In particular,
opAssign seems pr
Paul D. Anderson:
> After further review, I now realize that the right way (for me) to do this is
> to add a .dup property.<
Steven Schveighoffer has given you quite good answers.
A dup is generally not enough, because what you dup can have other immutable
references nested inside. Dup is not a
After further review, I now realize that the right way (for me) to do this is
to add a .dup property. So instead of
S foo(const S s) {
S other;
other = s;
}
or
S foo(const S s) {
S other = S(s);
return other;
}
which didn't look right to me, I can write
S foo(const S s) {
On Fri, 19 Mar 2010 20:58:21 -0400, Paul D. Anderson
wrote:
I created a struct, call it "S", and some functions that operate on S.
But I'm confused about when const is useful.
Being an old Java programmer, I use 'const' the same as I used 'final'
in Java. So most of my functions look lik
Spacen Jasset wrote:
> then presumably the syntax you are using is a bashism?. You could also
> say something like:
>
>
> system("bash mkdir -p " ~ path);
>
>
> Messing with your sh symlink may have some undesired consequences.
Actually, not messing with it will have undesired consequences. Lots
Paul D. Anderson:
> My struct has a dynamic array as a member -- that seems to be the problem.
> This code doesn't compile:
>
> struct S {
> int x;
> int[] a;
> }
>
> S foo(const S b) {
> S other = b;
> return other;
> }
> void main() {}
This compiles, oh joy:
struct S {
int x;
bearophile Wrote:
> Paul D. Anderson:
> > My struct has a dynamic array as a member -- that seems to be the problem.
> > This code doesn't compile:
> >
> > struct S {
> > int x;
> > int[] a;
> > }
> >
> > S foo(const S b) {
> > S other = b;
> > return other;
> > }
> > void main() {}
>
bearophile wrote:
> (I am looking for rough corners in D, or in my knowledge of D.)
>
> In this page:
> http://www.digitalmars.com/d/2.0/templates-revisited.html
>
> In the section "Template Parameters" there is written:
>
> P:P*, // P must be a pointer type
>
> -
>
>
So the question here is: do you know if there are important use cases for a
shallow_const attribute?
Bye,
bearophile
> Transitive const requires transitive copy, it's easy :-)
Or when possible, you don't copy it, just return it.
Bye,
bearophile
biozic:
> I'm not sure if this is completely right nor if I'm completely clear,
> though... :)
I think you are right.
In practice to copy something const to something that's not const you need a
deep copy function, because inside the array there can be other arrays that are
const, etc. Transiti
My guess is that:
struct S {
int x;
int[] a;
}
S foo(const S b) {
foo makes the promise that b's members won't change: so 'b.x' is
implicitely const(int) and 'b.a' is implicitely const(int[]).
S other = b;
Here you assign 'b.x', which is const(int), to 'other.x', which is int.
Moritz Warning:
>I think the problem is that is(T : T*) becomes is(int* : int**) and that's
>false.<
Thank you, you can be right.
So D docs are wrong, or that syntax has a semantic bug, or I have not
understood the situation yet.
If someone else has ideas I'm all ears.
-
Ellery New
On 03/19/2010 07:53 PM, Moritz Warning wrote:
On Fri, 19 Mar 2010 19:29:24 -0400, bearophile wrote:
(I am looking for rough corners in D, or in my knowledge of D.)
[..]
template IsPointer1(T) {
enum bool IsPointer1 = is(T : T*);
}
void main() {
int* ptr;
static assert(IsPointe
bearophile Wrote:
> Paul D. Anderson:
> > S x = cast(S) a;
> > S y = cast(S) b;
>
> In Java (especially old Java) casts may be common, but in D they are
> something that has to be used with care, don't cast away things carelessly :-)
>
> Bye,
> bearophile
I realize that casting is a la
bearophile Wrote:
> Paul D. Anderson:
>
> > I created a struct, call it "S", and some functions that operate on S. But
> > I'm confused about when const is useful.
> >
> > Being an old Java programmer, I use 'const' the same as I used 'final' in
> > Java. So most of my functions look like this
Paul D. Anderson:
> S x = cast(S) a;
> S y = cast(S) b;
In Java (especially old Java) casts may be common, but in D they are something
that has to be used with care, don't cast away things carelessly :-)
Bye,
bearophile
Paul D. Anderson:
> I created a struct, call it "S", and some functions that operate on S. But
> I'm confused about when const is useful.
>
> Being an old Java programmer, I use 'const' the same as I used 'final' in
> Java. So most of my functions look like this:
>
> S for(const S a, const S b
I created a struct, call it "S", and some functions that operate on S. But I'm
confused about when const is useful.
Being an old Java programmer, I use 'const' the same as I used 'final' in Java.
So most of my functions look like this:
S for(const S a, const S b) {
S x = a;
S y = b;
On Fri, 19 Mar 2010 19:29:24 -0400, bearophile wrote:
> (I am looking for rough corners in D, or in my knowledge of D.)
[..]
>
> template IsPointer1(T) {
> enum bool IsPointer1 = is(T : T*);
> }
> void main() {
> int* ptr;
> static assert(IsPointer1!(typeof(ptr))); // Err
> }
>
>
>
noboy wrote:
There was a soft link /bin/sh -> dash
I have change this to bash, and now all went fine.
Thank you
Steven Schveighoffer Wrote:
On Thu, 18 Mar 2010 09:28:06 -0400, noboy wrote:
I was little bit surprise because
mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man
do the right thin
(I am looking for rough corners in D, or in my knowledge of D.)
In this page:
http://www.digitalmars.com/d/2.0/templates-revisited.html
In the section "Template Parameters" there is written:
P:P*, // P must be a pointer type
-
So I have written this D2 program:
templa
� wrote:
this(this) is the copy constructor, I think.
this(this) is not the copy constructor. It is post-blit, which is useful
for when corrections need to be done after the automatic blitting:
http://digitalmars.com/d/2.0/struct.html#StructPostblit
Ali
33 matches
Mail list logo