forked from Alepha/Alepha
Auto-generation of comparisons as a capability.
This commit is contained in:
@ -7,16 +7,17 @@ static_assert( __cplusplus > 2020'00 );
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <Alepha/auto_comparable.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template< typename= Alepha::Capabilities< Alepha::IOStreams::IStreamable > >
|
template< typename= Alepha::Capabilities< Alepha::auto_comparable, Alepha::IOStreams::IStreamable > >
|
||||||
struct Agg_core
|
struct Agg_core
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int z;
|
int z;
|
||||||
|
|
||||||
friend bool operator == ( const Agg_core &lhs, const Agg_core &rhs )= default;
|
|
||||||
friend std::ostream &
|
friend std::ostream &
|
||||||
operator << ( std::ostream &os, const Agg_core &agg )
|
operator << ( std::ostream &os, const Agg_core &agg )
|
||||||
{
|
{
|
||||||
|
|||||||
35
auto_comparable.h
Normal file
35
auto_comparable.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
static_assert( __cplusplus > 2020'00 );
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
|
#include <Alepha/Capabilities.h>
|
||||||
|
#include <Alepha/comparisons.h>
|
||||||
|
|
||||||
|
#include <Alepha/Reflection/tuplizeAggregate.h>
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen ::detail:: auto_comparable_module
|
||||||
|
{
|
||||||
|
inline namespace exports
|
||||||
|
{
|
||||||
|
struct auto_comparable : comparable {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
concept AutoComparableAggregate=
|
||||||
|
Capability< T, auto_comparable >
|
||||||
|
and
|
||||||
|
Aggregate< T >;
|
||||||
|
|
||||||
|
constexpr decltype( auto )
|
||||||
|
equality_lens( const AutoComparableAggregate auto &item ) noexcept
|
||||||
|
{
|
||||||
|
return detail::comparisons::magma_hook{ Reflection::tuplizeAggregate( item ) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::inline exports::inline auto_comparable_module
|
||||||
|
{
|
||||||
|
using namespace detail::auto_comparable_module::exports;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user