mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 04:07:10 +01:00 
			
		
		
		
	Deducing return type of map generator helper (#1576)
* Deduce map return type implicitly Giving the first template argument to map generator function to deduce return type is now optional even if the return type is different from the type generated by mapped generator.
This commit is contained in:
		 Omer Ozarslan
					Omer Ozarslan
				
			
				
					committed by
					
						 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
			
				
	
			
			
			 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
						parent
						
							296d447452
						
					
				
				
					commit
					54089c4c8c
				
			| @@ -169,16 +169,28 @@ namespace Generators { | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     template <typename T, typename U, typename Func> | ||||
| #if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 | ||||
|     // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is | ||||
|     // replaced with std::invoke_result here. Also *_t format is preferred over | ||||
|     // typename *::type format. | ||||
|     template <typename Func, typename U> | ||||
|     using MapFunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>; | ||||
| #else | ||||
|     template <typename Func, typename U> | ||||
|     using MapFunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type; | ||||
| #endif | ||||
|  | ||||
|     template <typename Func, typename U, typename T = MapFunctionReturnType<Func, U>> | ||||
|     GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { | ||||
|         return GeneratorWrapper<T>( | ||||
|             pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) | ||||
|         ); | ||||
|     } | ||||
|     template <typename T, typename Func> | ||||
|     GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<T>&& generator) { | ||||
|  | ||||
|     template <typename T, typename U, typename Func> | ||||
|     GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { | ||||
|         return GeneratorWrapper<T>( | ||||
|             pf::make_unique<MapGenerator<T, T, Func>>(std::forward<Func>(function), std::move(generator)) | ||||
|             pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user