fallback.h
Go to the documentation of this file.
#include <wibble/exception.h>
#ifndef WIBBLE_FALLBACK_H
#define WIBBLE_FALLBACK_H
namespace wibble {
struct Error {};
template< typename T >
struct Fallback {
const T *value;
Fallback( const T &v ) : value( &v ) {}
Fallback( Error = Error() ) : value( 0 ) {}
template< typename E > const T &get( const E &e ) {
if ( !value ) throw e;
return *value;
}
const T &get() {
if ( !value ) throw exception::Consistency( "tried to use undefined fallback value" );
return *value;
}
};
}
#endif
wibble::Fallback::Fallback
Fallback(const T &v)
Definition: fallback.h:18
wibble::Fallback::Fallback
Fallback(Error=Error())
Definition: fallback.h:19
wibble::Fallback
Definition: fallback.h:16
wibble::Fallback::value
const T * value
Definition: fallback.h:17
wibble::exception::Consistency
Exception thrown when some consistency check fails.
Definition: exception.h:254
exception.h
wibble::Error
Definition: fallback.h:13
wibble
Definition: amorph.h:17