"Concepts" should not be part of function headers
Paul Backus
snarwin at gmail.com
Thu Oct 23 00:07:51 UTC 2025
On Wednesday, 22 October 2025 at 14:40:58 UTC, H. S. Teoh wrote:
> The user-facing function signature should describe the
> *logical* API, rather than implementation details such as "if
> input is a float, if input is an enum, ..." ad nauseaum.
> Logically, std.conv.to is supposed to accept *all* types (even
> if the current implementation may or may not accept
> *everything*), so the function signature should be:
>
> T to(T,U)(U data) { ... }
>
> *without* any signature constraints. All the stuff like "if U
> is floating-point, if U is enum, if U is struct, ...", etc.,
> are implementation details, that should be left to static if's
> inside the function body rather than clutter the API with an
> incomprehensibly large overload set.
In the specific case of `std.conv.to`, the user-facing template
*is* unconstrained. Its signature is:
template to(T)
However, the internal function that `to` forwards to, `toImpl`,
does use template constraints to create an incomprehensible
overload set.
More information about the Digitalmars-d-learn
mailing list