Skip to content

Commit 3e50ddb

Browse files
authored
Add isDelegate, isFunction, isFunctionPointer, and isReturn. (#10820)
All of them only accept types, avoiding any issues with @Property functions. SymbolType and PropertyType can then be used by programmers to get the type in the fashion that makes sense for their code, and that makes it so that these traits don't have to worry about that choice (which is bound to be wrong some of the time if the programmer isn't the one making the choice). isDelegate is just a wrapper around is(T == delegate) for use as a template predicate. Naturally, this says whether the given type is a delegate or not. isFunction is just a wrapper around is(T == function) for use as a template predicate. Naturally, this says whether the given type is a function or not. isFunctionPointer is more complex in that it requires two is expressions, so most code is likely to use isFunctionPointer rather than using the is expressions directly, but obviously, that's up to the programmer. As the name indicates, it says whether the given type is a function pointer. These traits do exist in std.traits, but there, they accept both types and symbols, whereas the phobos.sys.traits versions only accept types. isReturn is just a wrapper around is(T == return) for use as a template predicate. This says whether the given type is a function, function pointer, or delegate (so a type which can return a value when called). std.traits has isSomeFunction which does roughly the same thing, but it operates on both types and symbols, whereas the phobos.sys.traits version only operates on types. isReturn isn't exactly a fantastic name, but because it's simply a wrapper around is(T == return) and does no extra work, it seemed like the most appropriate name (and it avoids having "Some" in the name, which Walter dislikes). Either way, like with isDelegate and isFunction, most code should just use the is expression unless it needs a template predicate.
1 parent aef5fca commit 3e50ddb

File tree

1 file changed

+498
-1
lines changed

1 file changed

+498
-1
lines changed

0 commit comments

Comments
 (0)