Default Argument Improvements?

Brian Byrne bdbyrne at wisc.edu
Thu Feb 1 16:51:21 PST 2007


Whyn Oop Wrote:
> The reason might be as trivial as run time complexity: I assume that such
> improvements would bring the compiler at least much closer to the class
> of problems, which are believed to not be solvable in polynomial runtime.

I can't imagine there being much added complexity considering the programmer is explicitly stating when he wants a default argument to be used. All the compiler has to do is perform a function lookup, being wary of any ambiguity, and inserting that default argument's value in the function call.

Another [trivial] example could be for some given Vector4f class,

Vector4f set( float in_x = float.nan, float in_y = float.nan, float in_z = float.nan, float in_w = float.nan ) {
    x = ( in_x == float.nan ) ? x : in_x;
    y = ( in_y == float.nan ) ? y : in_y;
    z = ( in_z == float.nan ) ? z : in_z;
    w = ( in_w == float.nan ) ? w : in_w;
}

Vector4f vec = Vector4f( 1.0, 2.0, 3.0, 4.0 );
vec.set( 100.0, , 300.0, 400.0 ); // vec == Vector4f( 100.0, 2.0, 300.0, 400.0 )

Handy, no?

Brian Byrne



More information about the Digitalmars-d-learn mailing list