Skip to content

Commit ff896d0

Browse files
authored
[std/traits] Improve isCallable docs (#10917)
Fix renamed T parameter. Replace *lambdas* with 'non-template function literals'. Show delegate is true. Show function template with non-default parameter is false.
1 parent 4985f5e commit ff896d0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

std/traits.d

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7602,18 +7602,18 @@ enum bool isSomeFunction(alias T) =
76027602
}
76037603

76047604
/**
7605-
Detect whether `T` is a callable object, which can be called with the
7605+
Detect whether `callable` is a callable object, which can be called with the
76067606
function call operator `$(LPAREN)...$(RPAREN)`.
76077607
76087608
$(NOTE Implicit Function Template Instantiation is *not* attempted - see below.)
76097609
*/
76107610
template isCallable(alias callable)
76117611
{
76127612
static if (is(typeof(&callable.opCall) == delegate))
7613-
// T is a object which has a member function opCall().
7613+
// callable is a object which has a member function opCall().
76147614
enum bool isCallable = true;
76157615
else static if (is(typeof(&callable.opCall) V : V*) && is(V == function))
7616-
// T is a type which has a static member function opCall().
7616+
// callable is a type which has a static member function opCall().
76177617
enum bool isCallable = true;
76187618
else static if (is(typeof(&callable.opCall!()) TemplateInstanceType))
76197619
{
@@ -7629,7 +7629,7 @@ template isCallable(alias callable)
76297629
}
76307630
}
76317631

7632-
/// Functions, function pointers, delegates, lambdas.
7632+
/// Functions, function pointers, delegates, non-template function literals.
76337633
@safe unittest
76347634
{
76357635
void f() { }
@@ -7644,6 +7644,8 @@ template isCallable(alias callable)
76447644

76457645
int x;
76467646
static assert(!isCallable!x);
7647+
auto d = () => x;
7648+
static assert( isCallable!d);
76477649
}
76487650

76497651
/// Aggregate types with (static) opCall.
@@ -7658,7 +7660,6 @@ template isCallable(alias callable)
76587660
static assert( isCallable!(c.opCall));
76597661
static assert( isCallable!S);
76607662
static assert( isCallable!(I.value));
7661-
static assert( isCallable!((int a) { return a; }));
76627663

76637664
static assert(!isCallable!I);
76647665
}
@@ -7668,11 +7669,13 @@ template isCallable(alias callable)
76687669
{
76697670
void f()() { }
76707671
T g(T = int)(T x) { return x; }
7672+
int h(T)();
76717673
struct S1 { static void opCall()() { } }
76727674
struct S2 { static T opCall(T = int)(T x) {return x; } }
76737675

76747676
static assert( isCallable!f);
76757677
static assert( isCallable!g);
7678+
static assert(!isCallable!h);
76767679
static assert( isCallable!S1);
76777680
static assert( isCallable!S2);
76787681

0 commit comments

Comments
 (0)