Re: const references in C++ and D

2010-05-30 Thread BCS
Hello bearophile, BCS: Thats' what I'd do. But wasn't "auto ref" invented for such situations? That would work too, assuming that the internals of the function allow it. Bye and thank you, bearophile -- ... <

Re: const references in C++ and D

2010-05-30 Thread bearophile
BCS: > Thats' what I'd do. But wasn't "auto ref" invented for such situations? Bye and thank you, bearophile

Re: const references in C++ and D

2010-05-30 Thread BCS
Hello bearophile, I am translating a small C++ program to D2 and I am having problems. I am learning, but my mind is not large enough for all the subtleties of both C++ and D2 yet :-) This C++ program compiles: struct Vec { void operator+(const Vec& other) {} }; Vec bar(Vec x) { return x; } in

Re: What does 'scope' mean for non-class types?

2010-05-30 Thread div0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Stewart Gordon wrote: > div0 wrote: >> -BEGIN PGP SIGNED MESSAGE- >> Hash: SHA1 >> >> Lars T. Kyllingstad wrote: >>> In D2, what is the effect (if any) of 'scope' in the following >>> situations? >>> >>> scope int a; >> >> Nothing > > http:/

const references in C++ and D

2010-05-30 Thread bearophile
I am translating a small C++ program to D2 and I am having problems. I am learning, but my mind is not large enough for all the subtleties of both C++ and D2 yet :-) This C++ program compiles: struct Vec { void operator+(const Vec& other) {} }; Vec bar(Vec x) { return x; } int main() {

Re: Parallel ranges, how?

2010-05-30 Thread Simen kjaeraas
Philippe Sigaud wrote: I don't know if that'd help you, but did you have a look at David Simcha's parallelFuture module? http://cis.jhu.edu/~dsimcha/parallelFuture.html Looked at it now. It's not exactly what I was thinking. parallelFuture foes the foreach in one thread, and work in others,

Re: What does 'scope' mean for non-class types?

2010-05-30 Thread Stewart Gordon
div0 wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Lars T. Kyllingstad wrote: In D2, what is the effect (if any) of 'scope' in the following situations? scope int a; Nothing http://www.digitalmars.com/d/2.0/attribute.html#scope "This means that the destructor for an object is auto

Re: dynamic type casting in D

2010-05-30 Thread Michal Minich
On Sun, 30 May 2010 19:40:27 +, dave wrote: > if(implements(typeof(something).classinfo, A.classinfo)) in simpler way: In order to determine if an object o is an instance of a class B use a cast: if (cast(B) o) { // o is an instance of B } else { // o is not an instance of B } or

Re: Parallel ranges, how?

2010-05-30 Thread Simen kjaeraas
Philippe Sigaud wrote: I don't know if that'd help you, but did you have a look at David Simcha's parallelFuture module? http://cis.jhu.edu/~dsimcha/parallelFuture.html Gosh, dsimcha just made a post on it in the Phobos mailing list.Th

Re: Parallel ranges, how?

2010-05-30 Thread Philippe Sigaud
I don't know if that'd help you, but did you have a look at David Simcha's parallelFuture module? > > http://cis.jhu.edu/~dsimcha/parallelFuture.html > > Gosh, dsimcha just made a post on it in the Phobos mailing list.That's what I'd call paralle

Re: Parallel ranges, how?

2010-05-30 Thread Philippe Sigaud
On Sun, May 30, 2010 at 22:59, Simen kjaeraas wrote: > Simen kjaeraas wrote: > > How does the current range system accommodate parallel iteration? >> >> As far as I can see, a context switch could happen between calls to >> popFront and front, thus popping a value off the range before we're >> a

Re: Parallel ranges, how?

2010-05-30 Thread Simen kjaeraas
Simen kjaeraas wrote: How does the current range system accommodate parallel iteration? As far as I can see, a context switch could happen between calls to popFront and front, thus popping a value off the range before we're able to get its value. Anyone? It seems to me the system is not thre

Re: dynamic type casting in D

2010-05-30 Thread dave
Awesome! I just tried it out, the cast expression is exactly what I was looking for. I'm currently using Tango and tried out its runtime traits api, this works as expected: if(implements(typeof(something).classinfo, A.classinfo)) Thanks for the info!

Re: noob Q: declaring string variables

2010-05-30 Thread Jesse Phillips
Duke Normandin wrote: > Back again... > > As an introductory tutorial, I'm now using: > > http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample > > BTW, somebody fix that page - the `writefln' statements are missing > the %d and %s. > > char[] password = "sesame"; > > didn't

Re: dynamic type casting in D

2010-05-30 Thread Robert Clipsham
On 30/05/10 19:46, dave wrote: Hi, sort of new to D programming, coming from C++. Basically the question is if there is some sort of a way to dynamically cast a variable in D much like you do in C++? ex: interface A {...} class B {...} class C : B {...} class D : B, A {...} function(B somethi

Re: dynamic type casting in D

2010-05-30 Thread bearophile
dave: > sort of new to D programming, coming from C++. Basically the question is if > there is some sort of a way to dynamically cast a variable in D much like you > do in C++? D conflated all kinds of casts into the cast() syntax. So dynamic_cast can be done with a cast(). > I can't seem to fi

dynamic type casting in D

2010-05-30 Thread dave
Hi, sort of new to D programming, coming from C++. Basically the question is if there is some sort of a way to dynamically cast a variable in D much like you do in C++? ex: interface A {...} class B {...} class C : B {...} class D : B, A {...} function(B something) { A a = dynamic_cast(some

Re: Small opCall problem

2010-05-30 Thread Philippe Sigaud
On Sun, May 30, 2010 at 18:31, bearophile wrote: > BCS: > > FWIW, The struct being a template is extraneous. > > You are right, thank you. I have added the simplified example: > http://d.puremagic.com/issues/show_bug.cgi?id=4253 > > This one had me gnashing my teeth. I voted it up. Philippe

Re: Small opCall problem

2010-05-30 Thread bearophile
BCS: > FWIW, The struct being a template is extraneous. You are right, thank you. I have added the simplified example: http://d.puremagic.com/issues/show_bug.cgi?id=4253 Bye, bearophile

Re: Small opCall problem

2010-05-30 Thread BCS
Hello bearophile, struct Foo(T) { this(T x) {} void opCall(U)(U y) {} } void main() { auto foo = Foo!int(1); foo(1.5); } FWIW, The struct being a template is extraneous. temp.d(7): Error: constructor temp.Foo!(int).Foo.this (int x) is not callable using argument types (double) The lookup s

Re: Small opCall problem

2010-05-30 Thread Philippe Sigaud
On Sun, May 30, 2010 at 17:04, bearophile wrote: > struct Foo(T) { >this(T x) {} >void opCall(U)(U y) {} > } > void main() { >auto foo = Foo!int(1); >foo(1.5); > } > I've had this one too. I think it's a bug, because foo is already constructed when foo(1.5) is used. So the compil

Re: noob Q: declaring string variables

2010-05-30 Thread BCS
Hello Duke, On Sun, 30 May 2010, Philippe Sigaud wrote: On Sun, May 30, 2010 at 08:54, Simen kjaeraas wrote: Duke Normandin wrote: [sidebar] Why is every D tutorial I've touched upon so far, been frigged up? This is NOT good advocacy, people! Bad advertising! Where is the good stuff hidi

Re: noob Q: declaring string variables

2010-05-30 Thread Duke Normandin
On Sun, 30 May 2010, Philippe Sigaud wrote: > On Sun, May 30, 2010 at 08:54, Simen kjaeraas wrote: > > > Duke Normandin wrote: > > > > [sidebar] > >> Why is every D tutorial I've touched upon so far, been frigged up? > >> This is NOT good advocacy, people! Bad advertising! Where is the good > >>

Small opCall problem

2010-05-30 Thread bearophile
This is a small C++ program that compiles: template struct Foo { Foo(T x) {} template void operator()(U y) {} }; int main() { Foo foo(1); foo(1.5); } I think this is an equivalent D2 program: struct Foo(T) { this(T x) {} void opCall(U)(U y) {} } void main() { auto fo

Re: noob Q: declaring string variables

2010-05-30 Thread Philippe Sigaud
On Sun, May 30, 2010 at 08:54, Simen kjaeraas wrote: > Duke Normandin wrote: > > [sidebar] >> Why is every D tutorial I've touched upon so far, been frigged up? >> This is NOT good advocacy, people! Bad advertising! Where is the good >> stuff hiding? L8r... >> > > One of the reasons probably is t

Re: What does 'scope' mean for non-class types?

2010-05-30 Thread bearophile
Lars T. Kyllingstad: > So in the context of function arguments, 'in' is just a synonym for > 'const'? It seems to me like it should be removed from the language, > then. http://d.puremagic.com/issues/show_bug.cgi?id=3943. Bye, bearophile

Re: What does 'scope' mean for non-class types?

2010-05-30 Thread Lars T. Kyllingstad
On Sun, 30 May 2010 08:15:50 +0200, Don wrote: > div0 wrote: >> -BEGIN PGP SIGNED MESSAGE- >> Hash: SHA1 >> >> Lars T. Kyllingstad wrote: [...] >>> // According to the spec, 'in' is shorthand for 'const scope'. void >>> foo(in char[] d) { ... } >> >> d is const (read only). >> I've