add some return type deduction test (c++14)

master
neingeist 11 years ago
parent af963758f4
commit e14177b097

1
.gitignore vendored

@ -19,3 +19,4 @@ lvalues
bad_alloc bad_alloc
rtti rtti
future future
return-type-deduction

@ -21,3 +21,9 @@ add_executable(rtti rtti.cpp)
add_executable(future future.cpp) add_executable(future future.cpp)
set_target_properties(future PROPERTIES LINK_FLAGS "-pthread") set_target_properties(future PROPERTIES LINK_FLAGS "-pthread")
# those are c++14:
add_executable(return-type-deduction return-type-deduction.cpp)
#XXX a bit ugly, as the -std=c++1y gets appended to the other flags, which say -std=c++11
set_source_files_properties(return-type-deduction.cpp PROPERTIES COMPILE_FLAGS "-std=c++1y")

@ -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…
Cancel
Save