Tuples, CTFE, and Sliding Template Arguments
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Jan 12 23:10:08 UTC 2024
I started working on an alternative mechanism to templates for 1036e
yesterday. Which I alluded to.
Being able to pass a UDA at a call site and be able to get access to it
via ``__traits(getAttributes, parameter)`` within the (templated) function.
``i"$ident$(expr)$(ident:format)${1:format}"``
becomes
```d
@IExpression("ident")
ident,
@IExpression("expr")
expr,
@IExpression("ident")
@IFormat("format")
ident,
@IFormat("format")
@IPosition(1)
IPosition.init
```
This would be a general purpose language feature.
```d
string username, password;
getopt(
@description("My program")
@description("Second line")
commandsInfo,
@description("My programs help info")
@flag("help") @flag("h") helpInfo,
@description("The username to connect with")
@flag("username") @flag("u") username,
@description("The password to connect with")
@flag("password") @flag("p") password
);
```
I have already mocked up the getopt, the only additional template usage
is for formattedRead. This is a general purpose feature, that string
interpolation could tie into.
https://gist.github.com/rikkimax/812de12e600a070fe267f3bdc1bb3928
More information about the Digitalmars-d
mailing list