From 9424fbd193518f0f2e01288075b64dcea128027f Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 27 Dec 2023 16:19:25 -0500 Subject: [PATCH] Add some compile time checking for abuse of `error`. --- error.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/error.h b/error.h index 60111aa..5889e65 100644 --- a/error.h +++ b/error.h @@ -41,7 +41,8 @@ namespace Alepha::Hydrogen ::detail:: error_m * local named variable is going to cause the lock to be released. While this is not * a fatal problem, it can result in torn error lines, once again. */ - std::ostream &error( const std::lock_guard< SecretMutex > & ); + template< typename ... Args > + std::ostream &error( Args..., const std::lock_guard< SecretMutex > & ); // Not threadsafe. Set in or before main, before starting any threads. void setErrorStream( std::ostream &os ); @@ -52,8 +53,10 @@ namespace Alepha::Hydrogen ::detail:: error_m // The default is `std::cerr`, but any `std::ostream` will do. inline std::ostream *errorStream= &std::cerr; + template< typename ... Args > + requires( sizeof...( Args ) == 0 ) inline std::ostream & - exports::error( const std::lock_guard< SecretMutex > & = std::lock_guard{ access } ) + exports::error( Args..., const std::lock_guard< SecretMutex > & = std::lock_guard{ access } ) { return *errorStream; }