add some return type deduction test (c++14)
This commit is contained in:
		
							parent
							
								
									af963758f4
								
							
						
					
					
						commit
						e14177b097
					
				
					 3 changed files with 23 additions and 0 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										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")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								return-type-deduction.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								return-type-deduction.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue