Lines Matching refs:fun
74 private template needOpCallAlias(alias fun) in needOpCallAlias() argument
91 static if (is(typeof(fun.opCall) == function)) in needOpCallAlias()
93 enum needOpCallAlias = !is(typeof(fun)) && __traits(compiles, () { in needOpCallAlias()
94 return fun(Parameters!fun.init); in needOpCallAlias()
115 template unaryFun(alias fun, string parmName = "a")
117 static if (is(typeof(fun) : string))
119 static if (!fun._ctfeMatchUnary(parmName))
127 return mixin(fun); in unaryFun()
130 else static if (needOpCallAlias!fun)
133 alias unaryFun = fun.opCall;
137 alias unaryFun = fun;
206 template binaryFun(alias fun, string parm1Name = "a",
209 static if (is(typeof(fun) : string))
211 static if (!fun._ctfeMatchBinary(parm1Name, parm2Name))
221 return mixin(fun); in binaryFun()
224 else static if (needOpCallAlias!fun)
227 alias binaryFun = fun.opCall;
231 alias binaryFun = fun;
325 private uint _ctfeMatchUnary(string fun, string name) in _ctfeMatchUnary() argument
328 fun._ctfeSkipOp(); in _ctfeMatchUnary()
331 immutable h = fun._ctfeSkipName(name) + fun._ctfeSkipInteger(); in _ctfeMatchUnary()
334 fun._ctfeSkipOp(); in _ctfeMatchUnary()
339 if (!fun._ctfeSkipOp()) in _ctfeMatchUnary()
345 return fun.length == 0; in _ctfeMatchUnary()
372 private uint _ctfeMatchBinary(string fun, string name1, string name2) in _ctfeMatchBinary() argument
375 fun._ctfeSkipOp(); in _ctfeMatchBinary()
378 immutable h = fun._ctfeSkipName(name1) + fun._ctfeSkipName(name2) + fun._ctfeSkipInteger(); in _ctfeMatchBinary()
381 fun._ctfeSkipOp(); in _ctfeMatchBinary()
386 if (!fun._ctfeSkipOp()) in _ctfeMatchBinary()
392 return fun.length == 0; in _ctfeMatchBinary()
680 template partial(alias fun, alias arg) in partial() argument
685 …enum isSomeFunctor = (is(typeof(fun) == struct) || is(typeof(fun) == class)) && __traits(hasMember… in partial()
686 static if (isSomeFunctor || __traits(isTemplate, fun)) in partial()
690 static if (is(typeof(fun(arg, args2)))) in partial()
692 return fun(arg, args2); in partial()
698 string msg = "Cannot call '" ~ fun.stringof ~ "' with arguments " ~ in partial()
709 else static if (!isCallable!fun) in partial()
711 static assert(false, "Cannot apply partial to a non-callable '" ~ fun.stringof ~ "'."); in partial()
718 __traits(parent, fun), __traits(identifier, fun)))) in partial()
719 alias overloads = __traits(getOverloads, __traits(parent, fun), in partial()
720 __traits(identifier, fun)); in partial()
722 alias overloads = AliasSeq!(fun); in partial()
724 enum isCallableWithArg(alias fun) = Parameters!fun.length > 0 && in partial()
725 is(typeof(arg) : Parameters!fun[0]); in partial()
728 static if (overloads.length == 1 && Parameters!fun.length == 0) in partial()
730 static assert(0, "Cannot partially apply '" ~ fun.stringof ~ "'." ~ in partial()
731 "'" ~ fun.stringof ~ "' has 0 arguments."); in partial()
737 enum hasParameters(alias fun) = Parameters!fun.length > 0; in partial()
738 alias firstParameter(alias fun) = Parameters!fun[0]; in partial()
744 string msg = "Argument mismatch for '" ~ fun.stringof ~ in partial()
769 int fun(int a, int b) { return a + b; } in fun() function
770 alias fun5 = partial!(fun, 5);
785 static char fun(int i, string s) { return s[i]; } in fun() function
786 static int fun(int a, int b) { return a * b; } in fun() function
788 alias fun3 = partial!(S.fun, 3);
976 static auto fun(ref T inst, ref Parameters!T args)
981 return curry!fun()(t);
1151 int fun() { return 42 + store(5); }
1155 auto x4 = s.fun();
1204 template compose(fun...)
1205 if (fun.length > 0)
1207 static if (fun.length == 1)
1209 alias compose = unaryFun!(fun[0]);
1213 alias fun0 = unaryFun!(fun[0]);
1214 alias rest = compose!(fun[1 .. $]);
1269 alias pipe(fun...) = compose!(Reverse!(fun));
1322 template memoize(alias fun)
1328 ReturnType!fun memoize(Parameters!fun args)
1330 alias Args = Parameters!fun;
1334 static Unqual!(ReturnType!fun)[Tuple!Args] memo;
1338 auto r = fun(args);
1345 template memoize(alias fun, uint maxSize)
1350 ReturnType!fun memoize(Parameters!fun args)
1355 … static struct Value { staticMap!(Unqual, Parameters!fun) args; Unqual!(ReturnType!fun) res; }
1383 emplace(&memo[idx1], args, fun(args));
1403 memo[idx1] = Value(args, fun(args));
1616 static foreach (fun; AliasSeq!(fun000, fun001, fun010, fun011, fun100, fun101, fun110, fun111))
1618 alias mfun = memoize!fun;
1621 alias mfun2 = memoize!(fun, 42);
1866 template bind(alias fun)
1971 static auto fun(NoCopy a, NoCopy b)
1976 auto expected = fun(NoCopy(1), NoCopy(2));
1977 assert(Pair(NoCopy(1), NoCopy(2)).bind!fun == expected);