In CL we can do this:
$ SBCL
* (+ 1 2 3)
6
* (< 1 2 3)
T
* (< 2 3 1)
NIL
*
From a simple perspective, CL's + and < is a function that receives multiple parameters, somewhat similar to the 1,2,3 and less (1,2,3) of CPP.
So when the c++11 begins to have the variable parameter template, you can play multiple parameter addition and multiple parameter comparisons.
#include <functional>
template<typename o, typename a,typename b>
bool cmp (o, A a,b B) {
Return O (A, b);
}
Template<typename O, TypeName a,typename b,typename ... c>
BOOL CMP (O o,a a,b b,c ... C) {return
O (A, B) and CMP (O,b,c ...);
}
Template<typename O, TypeName a,typename b>
a reduce (o, a a,b B) {return
O (A, b);
}
Template<typename O, TypeName a,typename b,typename ... c>
A Reduce (O o,a a,b b,c ... c) {return
reduce (O,o (A, B), C ...);
}
BOOL Foo (int a,int b,int c,int d) {return
cmp (std::less<int> (), a,b,c,d);
int bar (int a,int b,int c,int d) {return
reduce (std::p lus<int> (), a,b,c,d);
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/
Some people may say, this is not a pit dad, regardless of the wording than CL ugly, you also recursive call, simply weak burst ...
Let's take a look at the Truth (clang):
foo (int, int, int, int): # @foo (int, int, int, int)
Cmpl %esi,%edi
jge . Lbb0_1
Cmpl %edx,%esi
setl %sil
cmpl ,%ecx, %edx setl%al andb% SIL,%al
ret
. Lbb0_1:
xorl %eax,%eax
ret
bar (int, int, int, int): # @bar (int, int, int, int)
ADDL %esi,%edi
Leal (%RDI,%RDX),%eax
addl ,%ecx
ret
and handwriting is absolutely not bad oh, a little bit ugly, but you see the assembly of CL, is certainly slower than C + + .... (Escape
Finally, what's the use?
Multi-parameter addition seems to be of no use to write A+b+c+d.
Multiple parameter comparisons are OK
A < b and B < C and C < D