forked from Alepha/Alepha
Invariant gadget.
This commit is contained in:
44
Invariant.h
Normal file
44
Invariant.h
Normal file
@ -0,0 +1,44 @@
|
||||
static_assert( __cplusplus > 2023'00 );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace Alepha::Hydrogen ::detail:: Invariant_m
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
template< typename T >
|
||||
class Invariant
|
||||
{
|
||||
private:
|
||||
const T *this_;
|
||||
|
||||
void
|
||||
check() const
|
||||
{
|
||||
assert( this_->invariant() );
|
||||
}
|
||||
|
||||
public:
|
||||
~Invariant()
|
||||
{
|
||||
check();
|
||||
}
|
||||
|
||||
explicit
|
||||
Invariant( const T *const this_ )
|
||||
: this_( this_ )
|
||||
{
|
||||
check();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace Alepha::Hydrogen::inline exports::inline Invariant_m
|
||||
{
|
||||
using namespace detail::Invariant_m::exports;
|
||||
}
|
Reference in New Issue
Block a user