isReturn

Evaluates to $(K_TRUE) if the given type is a function, function pointer, or delegate (and to $(K_FALSE) otherwise).

This is equivalent to is(T == return), so most code shouldn't use it. It's intended to be used in conjunction with templates that take a template predicate - such as those in phobos.sys.meta.

Note that this does not include implicit conversions or enum types. The type itself must be a function, function pointer, or delegate.

See the documentation for SymbolType and PropertyType to see the quirks involving $(K_PROPERTY) and why either SymbolType or PropertyType should be used rather than $(K_TYPEOF) to get the type of a symbol.

enum isReturn (
T
)

Examples

1 int var;
2 static assert(!isReturn!(SymbolType!var));
3 static assert(!isReturn!(PropertyType!var));
4 static assert(!isReturn!(typeof(&var)));
5 static assert(!is(SymbolType!var == return));
6 static assert(!is(PropertType!var == return));
7 static assert(!is(typeof(&var) == return));
8 
9 static void func() {}
10 static assert( isReturn!(SymbolType!func));
11 static assert( isReturn!(typeof(&func)));
12 static assert( is(SymbolType!func == return));
13 static assert( is(typeof(&func) == return));
14 
15 void funcWithContext() { ++var; }
16 static assert( isReturn!(SymbolType!funcWithContext));
17 static assert( isReturn!(typeof(&funcWithContext)));
18 static assert( is(SymbolType!funcWithContext == return));
19 static assert( is(typeof(&funcWithContext) == return));
20 
21 int function() funcPtr;
22 static assert( isReturn!(SymbolType!funcPtr));
23 static assert( isReturn!(PropertyType!funcPtr));
24 static assert(!isReturn!(typeof(&funcPtr)));
25 static assert( is(SymbolType!funcPtr == return));
26 static assert( is(PropertyType!funcPtr == return));
27 static assert(!is(typeof(&funcPtr) == return));
28 
29 int delegate() del;
30 static assert( isReturn!(SymbolType!del));
31 static assert( isReturn!(PropertyType!del));
32 static assert(!isReturn!(typeof(&del)));
33 static assert( is(SymbolType!del == return));
34 static assert( is(PropertyType!del == return));
35 static assert(!is(typeof(&del) == return));
36 
37 // It's possible to get the pointers to the function and the context from a
38 // delegate in @system code.
39 static assert( isFunctionPointer!(typeof(SymbolType!del.funcptr)));
40 static assert( is(typeof(SymbolType!del.ptr) == void*));
41 
42 @property static int prop() { return 0; }
43 static assert( isReturn!(SymbolType!prop));
44 static assert(!isReturn!(PropertyType!prop));
45 static assert( isReturn!(typeof(&prop)));
46 static assert( is(SymbolType!prop == return));
47 static assert(!is(PropertyType!prop == return));
48 static assert( is(typeof(&prop) == return));
49 
50 @property int propWithContext() { return var; }
51 static assert( isReturn!(SymbolType!propWithContext));
52 static assert(!isReturn!(PropertyType!propWithContext));
53 static assert( isReturn!(typeof(&propWithContext)));
54 static assert( is(SymbolType!propWithContext == return));
55 static assert(!is(PropertyType!propWithContext == return));
56 static assert( is(typeof(&propWithContext) == return));
57 
58 static int function() propFuncPtr() @property { return null; }
59 static assert( isReturn!(SymbolType!propFuncPtr));
60 static assert( isReturn!(PropertyType!propFuncPtr));
61 static assert( isReturn!(typeof(&propFuncPtr)));
62 static assert( is(SymbolType!propFuncPtr == return));
63 static assert( is(PropertyType!propFuncPtr == return));
64 static assert( is(typeof(&propFuncPtr) == return));
65 
66 static int delegate() propDel() @property { return null; }
67 static assert( isReturn!(SymbolType!propDel));
68 static assert( isReturn!(PropertyType!propDel));
69 static assert( isReturn!(typeof(&propDel)));
70 static assert( is(SymbolType!propDel == return));
71 static assert( is(PropertyType!propDel == return));
72 static assert( is(typeof(&propDel) == return));
73 
74 static struct S
75 {
76     void foo() {}
77 }
78 static assert( isReturn!(SymbolType!(S.foo)));
79 static assert( isReturn!(typeof(&S.foo)));
80 static assert( isReturn!(typeof(&S.init.foo)));
81 static assert( is(SymbolType!(S.foo) == return));
82 static assert( is(typeof(&S.foo) == return));
83 static assert( is(typeof(&S.init.foo) == return));
84 
85 struct HasContext
86 {
87     void foo() { ++var; }
88 }
89 static assert( isReturn!(SymbolType!(S.foo)));
90 static assert( isReturn!(typeof(&S.foo)));
91 static assert( isReturn!(typeof(&S.init.foo)));
92 static assert( is(SymbolType!(S.foo) == return));
93 static assert( is(typeof(&S.foo) == return));
94 static assert( is(typeof(&S.init.foo) == return));

See Also

Meta