add some return type deduction test (c++14)
parent
af963758f4
commit
e14177b097
@ -0,0 +1,16 @@
|
|||||||
|
/* http://en.wikipedia.org/wiki/C++14 */
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
auto sum(int i) {
|
||||||
|
if (i == 1)
|
||||||
|
return i; // return type deduced as int
|
||||||
|
else
|
||||||
|
return sum (i-1) + i; // ok to call it now
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
assert(sum(3) == 6);
|
||||||
|
assert(sum(10) == 55);
|
||||||
|
}
|
Loading…
Reference in New Issue