1
0
forked from Alepha/Alepha

Negation support for binary Enum

This commit is contained in:
2024-07-13 05:32:57 -04:00
parent 6a89b18c11
commit ad053e9175
2 changed files with 36 additions and 0 deletions

9
Enum.h
View File

@ -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
{
template< auto ... values >

View File

@ -9,6 +9,16 @@ static_assert( __cplusplus > 2020'99 );
#include <Alepha/IOStreams/String.h>
namespace
{
template< typename T >
concept CanNegate=
requires( const T &t )
{
{ not t };
};
}
static auto init= Alepha::Utility::enroll <=[]
{
using namespace Alepha::literals::enum_literals;
@ -58,4 +68,21 @@ static auto init= Alepha::Utility::enroll <=[]
{
{ "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 },
};
};