diff --git a/.gitignore b/.gitignore index 4bf4815..505d4f3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ lvalues bad_alloc rtti future +return-type-deduction diff --git a/CMakeLists.txt b/CMakeLists.txt index be37d00..de5ffa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,3 +21,9 @@ add_executable(rtti rtti.cpp) add_executable(future future.cpp) 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") diff --git a/return-type-deduction.cpp b/return-type-deduction.cpp new file mode 100644 index 0000000..14715bf --- /dev/null +++ b/return-type-deduction.cpp @@ -0,0 +1,16 @@ +/* http://en.wikipedia.org/wiki/C++14 */ + +#include +#include + +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); +}