Adding pure to a function type
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Oct 26 19:08:56 UTC 2017
On 10/26/2017 12:14 PM, jmh530 wrote:
> On Thursday, 26 October 2017 at 16:06:28 UTC, jmh530 wrote:
>> On Thursday, 26 October 2017 at 15:47:03 UTC, Andrei Alexandrescu wrote:
>>>
>>> s/less hideous/even more awesome/
>>>
>>> No need to be testy :o).
>>>
>>> I noticed there's no way to say "just leave linkage as is". I tried
>>> SetFunctionAttributes!(typeof(&impl), null, FunctionAttribute.pure_)
>>> and SetFunctionAttributes!(typeof(&impl), "",
>>> FunctionAttribute.pure_) but neither worked. Should I file a bug?
>>>
>>>
>>> Andrei
>>
>> How about:
>>
>> SetFunctionAttributes!(typeof(&impl), functionLinkage!(&impl),
>> FunctionAttribute.pure_)
>
> Or we can just add in additional overloads like:
>
> template SetFunctionAttributes(T, uint attrs)
> if (isFunctionPointer!T || isDelegate!T)
> {
> alias SetFunctionAttributes =
> FunctionTypeOf!(SetFunctionAttributes!(T, functionLinkage!T, attrs));
> }
>
> template SetFunctionAttributes(T, uint attrs)
> if (is(T == function))
> {
> alias SetFunctionAttributes =
> FunctionTypeOf!(SetFunctionAttributes!(T*, attrs));
> }
>
> template SetFunctionAttributes(T, string linkage)
> if (isFunctionPointer!T || isDelegate!T)
> {
> alias SetFunctionAttributes =
> FunctionTypeOf!(SetFunctionAttributes!(T, linkage, functionAttributes!T));
> }
>
> template SetFunctionAttributes(T, string linkage)
> if (is(T == function))
> {
> alias SetFunctionAttributes =
> FunctionTypeOf!(SetFunctionAttributes!(T*, linkage));
> }
One additional thing I noted is that I wanted to add attributes, not set
them. I'd like some simpler primitives like AddPure, RemovePure etc. BTW
the PR is https://github.com/dlang/phobos/pull/5470. -- Andrei
More information about the Digitalmars-d
mailing list