1
0
forked from Alepha/Alepha

Add some compile time checking for abuse of error.

This commit is contained in:
2023-12-27 16:19:25 -05:00
parent fbc731dec9
commit 9424fbd193

View File

@ -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 * 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. * 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. // Not threadsafe. Set in or before main, before starting any threads.
void setErrorStream( std::ostream &os ); 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. // The default is `std::cerr`, but any `std::ostream` will do.
inline std::ostream *errorStream= &std::cerr; inline std::ostream *errorStream= &std::cerr;
template< typename ... Args >
requires( sizeof...( Args ) == 0 )
inline std::ostream & 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; return *errorStream;
} }