A better way to deal with overloading?

Profile Anaysis via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 27 17:46:51 PST 2017


On Friday, 27 January 2017 at 19:32:29 UTC, Jesse Phillips wrote:
> On Thursday, 26 January 2017 at 00:02:03 UTC, Profile Anaysis 
> wrote:
>> Many times we pass compound types(non-primitives) as arguments 
>> to functions.
>
> I don't understand what issue you are solving. I see an 
> undefined syntax:
>
> foo(|a,b,|c1,c2,3||,|e|,|f,g,c|)
>
> To replace an existing syntax:
>
> foo(T1(a,b,new X(c1,c2,c3)),T2(e),T3(f,g,c));
>
> The primary difference I'm seeing is that the undefined syntax 
> doesn't specify what type is being created. To this end the one 
> time I recall desiring this is when using std.variant:
>

The type is deduced from the function call. There is no need to 
specify it or specify new. This is why the syntax reduces the 
complexity(of course, at the cost of increase terseness) and 
lines.


e.g., for your foo to be valid, it must have a declaration of 
foo(T1,T2,T3).

So why should we have to specify that when the compiler can do it 
for us?

The special syntax informs the compiler that we are initializing 
the types with the given arguments and it simply rewrites it in 
the long hand form.

It can only be used when the type can be deduced.






More information about the Digitalmars-d mailing list