r/cpp • • Apr 19 '20

Default function arguments are the devil

https://quuxplusone.github.io/blog/2020/04/18/default-function-arguments-are-the-devil/
90 Upvotes

149 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Apr 19 '20

[deleted] — view deleted comment

5

u/Ameisen vemips, avr, rendering, systems Apr 19 '20

I have a proposal sitting around to allow you to use default as a keyword for using the default type value (like {}) or using the declared default value of a parameter if it exists. Could extend it to support default... or such for a case like that.

Couple this with optional argument compile time detection... you can have very powerful functions or constructors.

3

u/flashmozzg Apr 19 '20

"is this thing invocable with the given arguments?"

Not exactly? At least as far as I see it you can only ask "if thing of this type is callable with args of these types". Default arguments obviously are not part of the type.

I think with C++20 you can just use requires as a way to SFINAE test whether some thing makes sense, i.e. https://godbolt.org/z/wdPrgi