Parametric attributes

Manu turkeyman at gmail.com
Wed Oct 2 00:43:44 UTC 2024


I feel like we really need parametric attributes...

I constantly have situations like this:
  void f(CallbackFun cb) { cb(); }
Where the attribute-ness of a function depends on the attribute-ness of the
callback.

I want my function to be @nogc, but I don't want to require the user supply
a @nogc callback to use my API.

If we're going to have all these attributes, then we really need something
like this:
  void f(CallbackFun cb) @nogc(is(cb : @nogc))

This applies to the classic suite of attributes.

The trouble with this, obviously, is; how do you mangle this function? It's
not a template... so...?

That problem feels loosely related to `inout`, which is an innovative
hack... I wonder if some generalisation of that concept could be satisfying
here, while also satisfying the actual input case (allowing to delete
`inout` from the language)...?

It's a whole category of problem that needs some expression... where the
attribute-ness of a declaration is dependent on the attribute-ness of some
facet of the declaration; and where the declaration is not a template.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20241002/16ec8ad5/attachment.htm>


More information about the Digitalmars-d mailing list