forked from Alepha/Alepha
Negation support for binary Enum
This commit is contained in:
9
Enum.h
9
Enum.h
@ -224,6 +224,15 @@ namespace Alepha::Hydrogen ::detail:: Enum_m
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template< EnumValueString no, EnumValueString yes >
|
||||||
|
constexpr Enum< no, yes >
|
||||||
|
operator not ( Enum< no, yes > enumeration )
|
||||||
|
{
|
||||||
|
enumeration.set_index( 1 - enumeration.get_index() );
|
||||||
|
|
||||||
|
return enumeration;
|
||||||
|
}
|
||||||
|
|
||||||
namespace exports
|
namespace exports
|
||||||
{
|
{
|
||||||
template< auto ... values >
|
template< auto ... values >
|
||||||
|
@ -9,6 +9,16 @@ static_assert( __cplusplus > 2020'99 );
|
|||||||
|
|
||||||
#include <Alepha/IOStreams/String.h>
|
#include <Alepha/IOStreams/String.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
template< typename T >
|
||||||
|
concept CanNegate=
|
||||||
|
requires( const T &t )
|
||||||
|
{
|
||||||
|
{ not t };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static auto init= Alepha::Utility::enroll <=[]
|
static auto init= Alepha::Utility::enroll <=[]
|
||||||
{
|
{
|
||||||
using namespace Alepha::literals::enum_literals;
|
using namespace Alepha::literals::enum_literals;
|
||||||
@ -58,4 +68,21 @@ static auto init= Alepha::Utility::enroll <=[]
|
|||||||
{
|
{
|
||||||
{ "Wrong", { "Wrong" }, { "Adam", "Baker", "Charlie", "David" } },
|
{ "Wrong", { "Wrong" }, { "Adam", "Baker", "Charlie", "David" } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static_assert( not CanNegate< Alepha::Enum< "one"_value > > );
|
||||||
|
static_assert( CanNegate< Alepha::Enum< "one"_value, "two"_value > > );
|
||||||
|
static_assert( not CanNegate< Alepha::Enum< "one"_value, "two"_value, "three"_value > > );
|
||||||
|
|
||||||
|
"Does negation of a two form enum work?"_test <=TableTest
|
||||||
|
<
|
||||||
|
[]( const Alepha::Enum< "No"_value, "Yes"_value > e )
|
||||||
|
{
|
||||||
|
return not e;
|
||||||
|
}
|
||||||
|
>
|
||||||
|
::Cases
|
||||||
|
{
|
||||||
|
{ "No -> Yes", { "No"_value }, "Yes"_value },
|
||||||
|
{ "Yes -> No", { "Yes"_value }, "No"_value },
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user