named arguments (C++) - Something D could learn from
Steven Schveighoffer
schveiguy at gmail.com
Fri Dec 14 21:03:23 UTC 2018
On 12/14/18 3:13 PM, bauss wrote:
> In C++ you can achieve named arguments using templates and operator
> overload:
>
> It's sad that D is still against having named arguments, but it's
> possible in something that D thrives to be better than.
>
> https://www.fluentcpp.com/2018/12/14/named-arguments-cpp/
>
> I assume this is not possible to port to D because D doesn't do operator
> overload in the same way C++ does, correct?
Bleh, C++ is so ugly. I can't see how D can't do better.
operator overloading works fine in D, just like it does in the given
example.
What C++ allows is:
1. operator overloading of arbitrary operators. D has certain
requirements for certain operators.
2. extracting the operator overloading to a module-level function. D
requires operator overloading inside a type.
But neither of those problems are in play here. You could practically
port the solution exactly to D.
HOWEVER, I don't think the mechanics make this solution worthwhile.
Carrying around extra structs and wrapping things in this complicated
way doesn't seem very attractive to me.
-Steve
More information about the Digitalmars-d
mailing list