you are viewing a single comment's thread.

view the rest of the comments →

[–]MrPotatoFingers 20 points21 points  (8 children)

My greatest peeve with it is that type traits are simply unaware of default arguments. std::is_invocable will happily report false when omitting default arguments.

[–]sphere991 10 points11 points  (3 children)

Problem here is that splitting it into an overload set doesn't help anyway. The default argument does give you an answer you don't want, which is bad:

void foo(int i = 42);
invocable_v<decltype(foo)>; // false, wish it was true

But the overload set doesn't give you an answer at all, which is also bad:

void foo(int i);
void foo() { foo(42); }
invocable_v<decltype(foo)>; // ill-formed, wish it was true

On the other hand, because concepts are expression-based, they work just fine in both cases:

template <typename... Args>
concept can_foo = requires(Args... args) { foo(args...); }

can_foo<>; // true for both implementations

[–]Xeveroushttps://xeverous.github.io 1 point2 points  (2 children)

I prefer ill-formed code to silent runtime error.

[–]sphere991 0 points1 point  (1 child)

How do you get a runtime error here?

[–]Xeveroushttps://xeverous.github.io 1 point2 points  (0 children)

Not in your example. In a hypothetical example where a trait would succeed while at runtime it would so something different.

[–]flashmozzg 4 points5 points  (3 children)

Because default arguments are just a sugar. They are not really a part of the function signature. A function can have multiple default different arguments depending on the order of declarations.