Re: Using in as a parameter qualifier

2014-10-23 Thread via Digitalmars-d-learn
On Thursday, 23 October 2014 at 05:17:14 UTC, Shriramana Sharma via Digitalmars-d-learn wrote: Hi Jonathan and thanks again for your kind replies. On 10/23/14, Jonathan M Davis via Digitalmars-d-learn wrote: That will result in a move operation. No copying will take place. And it technically,

Re: Using in as a parameter qualifier

2014-10-23 Thread via Digitalmars-d-learn
On Wednesday, 22 October 2014 at 19:44:49 UTC, Jonathan M Davis wrote: The only exception would be if the compiler determines that the lvalue in question is never used after that call, in which case, it might just move the object rather than copy it. There's an additional restriction: local va

Re: Using in as a parameter qualifier

2014-10-22 Thread Shriramana Sharma via Digitalmars-d-learn
Hi Jonathan and thanks again for your kind replies. On 10/23/14, Jonathan M Davis via Digitalmars-d-learn wrote: > That will result in a move operation. No copying will take place. > And it technically, it may not actually move anything it all and > just use the object where it's initially constr

Re: Using in as a parameter qualifier

2014-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 22 October 2014 at 19:13:58 UTC, Shriramana Sharma via Digitalmars-d-learn wrote: Hello people. I'm once more looking at D since I participated here a bit last year. Since I'm still not 100% sure about committing myself to using D i.o. C++ for my work, I'd really like to resurrect

Re: Using in as a parameter qualifier

2014-10-22 Thread Shriramana Sharma via Digitalmars-d-learn
Hello people. I'm once more looking at D since I participated here a bit last year. Since I'm still not 100% sure about committing myself to using D i.o. C++ for my work, I'd really like to resurrect this thread to clear my lingering doubts (the full thread is at http://forum.dlang.org/post/mailman

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
Thanks Jonathan and Ali for all those clarifications. -- Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा

Re: Using in as a parameter qualifier

2013-05-31 Thread Ali Çehreli
On 05/31/2013 04:45 PM, Shriramana Sharma wrote: > And again, sorry if I'm being dumb, but is the proposed inout syntax > intended to fix this problem or some other problem? Think of 'inout' as a placeholder for one of the following three: - const - immutable - (no const, nor immutable) inout

Re: Using in as a parameter qualifier

2013-05-31 Thread Jonathan M Davis
On Saturday, June 01, 2013 05:15:22 Shriramana Sharma wrote: > On Sat, Jun 1, 2013 at 5:11 AM, Shriramana Sharma wrote: > > So what is the syntax that accepts rvalues and yet does not make a > > copy of the input object? I mean, as Ali says OK profiling is > > preferable to find out where exactly

Re: Using in as a parameter qualifier

2013-05-31 Thread Jonathan M Davis
On Saturday, June 01, 2013 05:11:44 Shriramana Sharma wrote: > On Fri, May 31, 2013 at 8:55 PM, Jonathan M Davis wrote: > > In D, const ref does not accept rvalues (unlike C++'s const &). > > So what is the syntax that accepts rvalues and yet does not make a > copy of the input object? If you h

Re: Using in as a parameter qualifier

2013-05-31 Thread Jonathan M Davis
On Saturday, June 01, 2013 04:39:07 Shriramana Sharma wrote: > On Sat, Jun 1, 2013 at 1:13 AM, Jonathan M Davis wrote: > > Certainly, > > for anything that's small enough to fit in a register, it's likely to be > > faster to pass by value. > > So pardon my ignorance, but a pair which only contai

Re: Using in as a parameter qualifier

2013-05-31 Thread Ali Çehreli
On 05/31/2013 04:41 PM, Shriramana Sharma wrote: > On Fri, May 31, 2013 at 8:55 PM, Jonathan M Davis wrote: >> In D, const ref does not accept rvalues (unlike C++'s const &). > > So what is the syntax that accepts rvalues and yet does not make a > copy of the input object? I think there has b

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
On Sat, Jun 1, 2013 at 5:11 AM, Shriramana Sharma wrote: > So what is the syntax that accepts rvalues and yet does not make a > copy of the input object? I mean, as Ali says OK profiling is > preferable to find out where exactly passing by value is more > efficient than passing by const ref, but I

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
On Fri, May 31, 2013 at 8:55 PM, Jonathan M Davis wrote: > In D, const ref does not accept rvalues (unlike C++'s const &). So what is the syntax that accepts rvalues and yet does not make a copy of the input object? I mean, as Ali says OK profiling is preferable to find out where exactly passing

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
On Sat, Jun 1, 2013 at 1:13 AM, Jonathan M Davis wrote: > Certainly, > for anything that's small enough to fit in a register, it's likely to be > faster > to pass by value. So pardon my ignorance, but a pair which only contains two doubles -- it would fit in a CPU register? How about a bezier cl

Re: Using in as a parameter qualifier

2013-05-31 Thread Jonathan M Davis
On Friday, May 31, 2013 23:25:02 Jesse Phillips wrote: > On Friday, 31 May 2013 at 17:50:33 UTC, Shriramana Sharma wrote: > > Sorry but I still don't get it -- if a default constructor is > > disallowed for struct-s by the language itself, why should I > > have to > > *tell* the compiler to disable

Re: Using in as a parameter qualifier

2013-05-31 Thread Jesse Phillips
On Friday, 31 May 2013 at 17:50:33 UTC, Shriramana Sharma wrote: Sorry but I still don't get it -- if a default constructor is disallowed for struct-s by the language itself, why should I have to *tell* the compiler to disable it? The compiler always provides a default constructor (maybe not

Re: Using in as a parameter qualifier

2013-05-31 Thread Jonathan M Davis
On Friday, May 31, 2013 23:19:57 Shriramana Sharma wrote: > > However, :) if you are going to make a copy of the argument anyway, always > > take a struct by-value. That works with both lvalue and rvalue arguments > > and in the case of rvalues, you will get the automatic move semantics. > > > > M

Re: Using in as a parameter qualifier

2013-05-31 Thread Ali Çehreli
On 05/31/2013 10:49 AM, Shriramana Sharma wrote: >> struct Pair { >> double x = 10.75; >> double y = 20.25; >> >> // Default constructor disabled >> @disable this(); >> >> // Users must use another constructor: >> this(double x, double y) { this.x = x; this.y = y; }

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
Thanks to all who explained the various issues. Some more questions: On Fri, May 31, 2013 at 9:28 PM, Ali Çehreli wrote: > What the error message is saying is that you can declare it just to disable > its use: > > struct Pair { > double x = 10.75; > double y = 20.25; > > // Default co

Re: Using in as a parameter qualifier

2013-05-31 Thread Ali Çehreli
On 05/31/2013 02:40 AM, Shriramana Sharma wrote: > On Fri, May 31, 2013 at 12:12 PM, Ali Çehreli wrote: >>> double x,y ; >>> this () {} >> >> That is not allowed. In D, every type has the .init property, which is its >> default value. > > Hm can you clarify that a bit? If I actually tr

Re: Using in as a parameter qualifier

2013-05-31 Thread Jonathan M Davis
On Friday, May 31, 2013 15:10:01 Shriramana Sharma wrote: > On Fri, May 31, 2013 at 12:12 PM, Ali Çehreli wrote: > >> Consider a function that operates on a pair: > >> double abs2 ( pair a ) { return a.x * a.x + a.y * a.y ; } > >> In C++ the function signature would be: double abs2 ( const pair &

Re: Using in as a parameter qualifier

2013-05-31 Thread bearophile
Shriramana Sharma: Wouldn't p1.y actually be NaN and not 0? Right. You can verify it with a writeln. Bye, bearophile

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
On Fri, May 31, 2013 at 12:12 PM, Ali Çehreli wrote: > struct Pair { > double x, y; > } > > void main() > { > auto p0 = Pair(); > auto p1 = Pair(1.5);// only p1.y is 0 Wouldn't p1.y actually be NaN and not 0? -- Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा

Re: Using in as a parameter qualifier

2013-05-31 Thread Shriramana Sharma
On Fri, May 31, 2013 at 12:12 PM, Ali Çehreli wrote: >>double x,y ; >>this () {} > > That is not allowed. In D, every type has the .init property, which is its > default value. Hm can you clarify that a bit? If I actually try it I get: pair.d(14): Error: constructor pair.pair.this defaul

Re: Using in as a parameter qualifier

2013-05-30 Thread Ali Çehreli
On 05/30/2013 10:36 PM, Shriramana Sharma wrote: > struct pair { It is more common to start type names with a capital letter: Pair. >double x,y ; >this () {} That is not allowed. In D, every type has the .init property, which is its default value. >this (double x, double y) { th

Using in as a parameter qualifier

2013-05-30 Thread Shriramana Sharma
Hello people. I have a pair type defined as : struct pair { double x,y ; this () {} this (double x, double y) { this.x = x ; this.y = y ; } } Consider a function that operates on a pair: double abs2 ( pair a ) { return a.x * a.x + a.y * a.y ; } In C++ the function signature would be: dou