Checking @nogc-ness of an Allocator.allocate()
Simen Kjærås
simen.kjaras at gmail.com
Thu Jan 11 13:18:47 UTC 2018
On Thursday, 11 January 2018 at 12:32:54 UTC, Per Nordlöw wrote:
> Is this an ok implementation:
>
> enum bool isNogc(alias fun) = (isCallable!fun &&
> (functionAttributes!fun &
> FunctionAttribute.nogc));
>
> @safe pure nothrow @nogc unittest
> {
> static int foo(int x) @nogc pure nothrow;
> static int goo(int x) pure nothrow;
> static assert(isNogc!foo);
> static assert(!isNogc!goo);
> }
Seems to be working fine. I'd go with this version for perhaps a
bit more brevity and clarity:
enum bool isNogc(alias fun) = hasFunctionAttributes!(fun,
"@nogc");
Both functionAttributes and hasFunctionAttributes already check
that the argument is a callable (which function attributes should
"foo" have?), so that's unnecessary.
--
Simen
More information about the Digitalmars-d-learn
mailing list