mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 04:07:10 +01:00 
			
		
		
		
	Add to string for std::optional
This commit is contained in:
		 Robin Moussu
					Robin Moussu
				
			
				
					committed by
					
						 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
			
				
	
			
			
			 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
						parent
						
							63d1a96908
						
					
				
				
					commit
					16dc219704
				
			| @@ -183,6 +183,14 @@ | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| //////////////////////////////////////////////////////////////////////////////// | ||||
| // Check if optional is available and usable | ||||
| #if defined(__has_include) | ||||
| #  if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) | ||||
| #    define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL | ||||
| #  endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER) | ||||
| #endif // __has_include | ||||
|  | ||||
| //////////////////////////////////////////////////////////////////////////////// | ||||
| // Check if variant is available and usable | ||||
| #if defined(__has_include) | ||||
| @@ -222,6 +230,10 @@ | ||||
| #    define CATCH_CONFIG_CPP11_TO_STRING | ||||
| #endif | ||||
|  | ||||
| #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) | ||||
| #  define CATCH_CONFIG_CPP17_OPTIONAL | ||||
| #endif | ||||
|  | ||||
| #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) | ||||
| #  define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS | ||||
| #endif | ||||
|   | ||||
| @@ -348,6 +348,7 @@ namespace Catch { | ||||
| #  define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER | ||||
| #  define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER | ||||
| #  define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER | ||||
| #  define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER | ||||
| #endif | ||||
|  | ||||
| // Separate std::pair specialization | ||||
| @@ -369,6 +370,24 @@ namespace Catch { | ||||
| } | ||||
| #endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER | ||||
|  | ||||
| #if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL) | ||||
| #include <optional> | ||||
| namespace Catch { | ||||
|     template<typename T> | ||||
|     struct StringMaker<std::optional<T> > { | ||||
|         static std::string convert(const std::optional<T>& optional) { | ||||
|             ReusableStringStream rss; | ||||
|             if (optional.has_value()) { | ||||
|                 rss << ::Catch::Detail::stringify(*optional); | ||||
|             } else { | ||||
|                 rss << "{ }"; | ||||
|             } | ||||
|             return rss.str(); | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| #endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER | ||||
|  | ||||
| // Separate std::tuple specialization | ||||
| #if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER) | ||||
| #include <tuple> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user