Tuples, CTFE, and Sliding Template Arguments
Steven Schveighoffer
schveiguy at gmail.com
Sat Jan 13 04:35:20 UTC 2024
On Saturday, 13 January 2024 at 02:16:06 UTC, Walter Bright wrote:
> On 1/12/2024 4:15 PM, Steven Schveighoffer wrote:
>> I don't view this as simpler than DIP1036e or DIP1027 -- a
>> simple transformation is a simple transformation.
>
> Adding extra hidden templates isn't that simple. If a user is
> not using a canned version, he'd have to be pretty familiar
> with D to be able to write his own handler.
Yes, that is intentional. You should not be able to call
functions with new syntax because the parameters happen to match.
We have a type system for a reason.
> 1027 is simpler in that if the generated tuple is examined, it
> matches just what one would have written using a format.
> Nothing much to learn there.
In other words: "it matches just what one wouldn't have written,
unless one is calling `writef`".
>> Certainly a hybrid DIP1027 with a format string passed at
>> compile time is still not viable, due to reasons already
>> stated.
>
> The other reasons:
>
> 1. preventing calls to functions passing an ordinary string as
> opposed to an istring tuple
I don't see how this proposal fixes that. I'm assuming a function
like `void foo(string s, int x)` will match `foo(i"something:
$(1)")`
> 2. preventing nested istrings
Why do we want to prevent nested istrings? That's not a goal.
> have already been addressed. The compile time thing was the
> only one left.
A compile time format string still needs parsing. Why would we
want to throw away all the work the compiler already did?
If you want to call `writef`, you can construct a format string
easily at compile time. Or just... call `writef` the normal way.
Compile-time string parsing is way more costly than compile-time
string concatenation.
> > This does seem like it has the potential to break code:
>
> The shifted one would be a more costly match, and so the legacy
> others would be favored first.
Ok. This does mean, for *intentional* overloading of a function
to accept a compile-time first parameter, you will have to rename
the function.
Possibly, if you have an opt-in syntax like Timon mentioned, then
you can make the sliding template parameter more preferable.
-Steve
More information about the Digitalmars-d
mailing list