Default value of class

Daniel Keep daniel.keep.lists at gmail.com
Sun May 20 16:47:16 PDT 2007



Jarrett Billingsley wrote:
> "Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
> news:f2qgao$3176$1 at digitalmars.com...
>> Doesn't C++ have those ... && reference arguments?  Like int&& ?  You can 
>> pass temps to those.  Well I guess those are in C++09, so they're not part 
>> of the language yet.
> 
> Though D can do this:
> 
> struct S
> {
>     int x;
> 
>     static S opCall(int x)
>     {
>         S s;
>         s.x = x;
>         return s;
>     }
> }
> 
> void foo(ref S s)
> {
>     writefln(s.x);
> }
> 
> void main()
> {
>     foo(S(4));
> }
> 
> Which I guess is pretty close. 

That's interesting; could that be NVRO?  That said, this still doesn't
work...

> import std.stdio;
>
> void foo(ref int a)
> {
>     writefln("a: %s", a);
> }
>
> void main()
> {
>     foo(42);
> }

H:\WINDOWS\system32\cmd.exe /c bud -clean -exec refargs
refargs.d(11): Error: constant 42 is not an lvalue

:(

This is a pain because I discovered that using ref arguments for my
vector library can net me a *big* speed increase, even more so once I
put in SSE optimisations.

The problem is that if I can't pass literals or temporaries, then it'll
render the library much harder to use.  Then again, maybe since the
vectors are structs, the above will work... need to give that a shot
when I'm not so busy.

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list