Bug 4991 – Make 'nothrow', other function attributes, accessible (via traits?)

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-10-04T12:15:00Z
Last change time
2012-12-20T12:56:09Z
Assigned to
nobody
Creator
ah08010-d

Comments

Comment #0 by ah08010-d — 2010-10-04T12:15:45Z
In a template, I'd like to declare a mathematical function as pure/nothrow. The problem is that I am using a traits template to specify behavior for some edge conditions, and the caller may reasonably want the edge case to throw an exception. So I would like to be able to statically detect the nothrow status of the trait class' behavior handler, and reflect that in the declaration of the template function. At the very least, this means providing a boolean query for nothrow. But in fact, propagating the attribute would benefit from additional capabilities. Declaring a function "conditionally nothrow" presently seems to require a conditional re-declaration of the entire function either with or without the nothrow added. There seems to be no way to mixin("nothrow") or { alias nothrow NT } to add in the attribute. Perhaps this kind of "attribute propagation" needs some kind of special tuple? Or is this a reason to support prototypes?
Comment #1 by andrej.mitrovich — 2012-12-20T12:56:09Z
Please see std.traits.functionAttributes.