Enum member isFunctionOver

Returns true if the passed in function is an n-ary function over the next n parameter arguments

enum isFunctionOver(T...) = true;

Parameter arguments can be any compile time entity that can be typed.


T The first argument is the function to check, the second are the types it should be called over


int i;
float f;
void f0() {}
void f1(int a) {}
void f2(int a, string b) {}
void f3(int a, string b, float c) {}

static assert( isFunctionOver!(f0));
static assert(!isFunctionOver!(f0, int));

static assert(!isFunctionOver!(f1, string));
static assert( isFunctionOver!(f1, int));
static assert( isFunctionOver!(f1, i));
static assert(!isFunctionOver!(f1, f));

static assert(!isFunctionOver!(f2, int));
static assert( isFunctionOver!(f2, int, string));
static assert(!isFunctionOver!(f2, int, float));
static assert(!isFunctionOver!(f2, int, float, string));

static assert( isFunctionOver!(f3, int, string, float));
static assert(!isFunctionOver!(f3, int, float, string));
static assert(!isFunctionOver!(f3, int, float));
static assert(!isFunctionOver!(f3, int));
static assert(!isFunctionOver!(f3));

static assert( isFunctionOver!(() => 3));
static assert(!isFunctionOver!(() => 3, int));
static assert(!isFunctionOver!(a => a, float, int));
static assert( isFunctionOver!(a => a, float));
static assert( isFunctionOver!(a => a, int));
static assert( isFunctionOver!((int a) => a, short));
static assert(!isFunctionOver!((int a) => a, float));
static assert(!isFunctionOver!(a => a));
static assert( isFunctionOver!((a, b) => a + b, float, int));

struct A {}
static assert(!isFunctionOver!((a, b) => a + b, A, int));
static assert( isFunctionOver!((a, b, c, d) => a+b+c+d, int, int, int ,int));

import std.functional: unaryFun;
static assert( isFunctionOver!(unaryFun!"a", int));
static assert(!isFunctionOver!(unaryFun!"a", int, int));

import std.functional: binaryFun;
static assert(!isFunctionOver!(binaryFun!"a", int));
static assert( isFunctionOver!(binaryFun!"a", int, int));
static assert( isFunctionOver!(binaryFun!"a > b", int, int));
static assert(!isFunctionOver!(binaryFun!"a > b", int, int, int));

class C {}
class D : C {}
void fc(C) {}
void fd(D) {}
static assert( isFunctionOver!(fc, C));
static assert( isFunctionOver!(fc, D));
static assert(!isFunctionOver!(fd, C));
static assert( isFunctionOver!(fd, D));

import std.math: ceil;
static assert( isFunctionOver!(ceil, double));
static assert(!isFunctionOver!(ceil, double, double));

static assert(!isFunctionOver!(i));
static assert(!isFunctionOver!(i, int));