forked from Alepha/Alepha
Started a rewrite... but now I'm going to try it with friends?
This commit is contained in:
2
Buffer.h
2
Buffer.h
@ -235,7 +235,7 @@ namespace Alepha::Hydrogen ::detail:: Buffer_m
|
|||||||
struct BufferModel_capability {};
|
struct BufferModel_capability {};
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
concept UndecayedBufferModelable= Capability< T, BufferModel_capability >;
|
concept UndecayedBufferModelable= HasCapability< T, BufferModel_capability >;
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
concept BufferModelable= UndecayedBufferModelable< std::decay_t< T > >;
|
concept BufferModelable= UndecayedBufferModelable< std::decay_t< T > >;
|
||||||
|
168
Capabilities.h
168
Capabilities.h
@ -4,8 +4,8 @@ static_assert( __cplusplus > 2020'99 );
|
|||||||
|
|
||||||
#include <Alepha/Alepha.h>
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
#include <Alepha/Meta/find.h>
|
#include <Alepha/type_lisp.h>
|
||||||
#include <Alepha/Meta/type_value.h>
|
#include <Alepha/Concepts.h>
|
||||||
|
|
||||||
namespace Alepha::Hydrogen
|
namespace Alepha::Hydrogen
|
||||||
{
|
{
|
||||||
@ -17,122 +17,94 @@ namespace Alepha::Hydrogen
|
|||||||
{
|
{
|
||||||
template< typename ... capabilities >
|
template< typename ... capabilities >
|
||||||
struct Capabilities;
|
struct Capabilities;
|
||||||
|
|
||||||
template< typename T, typename cap >
|
|
||||||
struct has_capability_s; //: std::is_base_of< cap, T > {};
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
template< template< typename ... > class Type, typename ... Caps, typename cap >
|
|
||||||
struct has_capability< Type< Capabilities< Caps... > >, cap >
|
|
||||||
{
|
|
||||||
using T= Type< Capabilities< Caps... > >;
|
|
||||||
static constexpr bool value= Meta::find_in_tuple_v< cap, std::tuple< Caps... > > or std::is_base_of_v< cap, T >;
|
|
||||||
using type= has_capability;
|
|
||||||
};
|
|
||||||
template< template< typename ... > class Type, typename ... Back, typename ... Caps, typename cap >
|
|
||||||
struct has_capability< Type< Capabilities< Caps... >, Back... >, cap >
|
|
||||||
{
|
|
||||||
using T= Type< Capabilities< Caps... >, Back... >;
|
|
||||||
static constexpr bool value= Meta::find_in_tuple_v< cap, std::tuple< Caps... > > or std::is_base_of_v< cap, T >;
|
|
||||||
using type= has_capability;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template< template< typename ... > class Type, typename ... Front, typename ... Caps, typename cap >
|
|
||||||
struct has_capability< Type< Front..., Capabilities< Caps... > >, cap >
|
|
||||||
{
|
|
||||||
using T= Type< Front..., Capabilities< Caps... > >;
|
|
||||||
static constexpr bool value= Meta::find_in_tuple_v< cap, std::tuple< Caps... > > or std::is_base_of_v< cap, T >;
|
|
||||||
using type= has_capability;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CapabilityBase {};
|
||||||
|
template< typename ... capabilities >
|
||||||
|
struct exports::Capabilities : CapabilityBase {};
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
struct is_capability_list_s : std::false_type {};
|
concept CapabilityList= DerivedFrom< T, CapabilityBase >;
|
||||||
|
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
constexpr bool is_capability_list_v= false;
|
||||||
|
|
||||||
template< typename ... Args >
|
template< typename ... Args >
|
||||||
struct is_capability_list_s< Capabilities< Args... > > : std::true_type {};
|
constexpr bool is_capability_list_v< Capabilities< Args... > > { true };
|
||||||
|
|
||||||
inline constexpr Meta::trait< is_capability_list_s > is_capability_list;
|
template< typename Capability, TypeListType List >
|
||||||
|
constexpr bool has_capability_in_list_v= false
|
||||||
|
or SameAs< car_t< List >, Capability >
|
||||||
|
or DerivedFrom< car_t< List >, Capability >
|
||||||
|
or has_capability_in_list_v< Capability, cdr_t< List > >;
|
||||||
|
|
||||||
|
template< typename Capability >
|
||||||
|
constexpr bool has_capability_in_list_v< Capability, Nil > {};
|
||||||
|
|
||||||
|
template< typename ... Args >
|
||||||
|
constexpr TypeListType auto
|
||||||
|
extract_list( const Capabilities< Args... > & )
|
||||||
|
{
|
||||||
|
return TypeList< Args... >{};
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename T > struct get_capability_list { using type= Nil; };
|
||||||
|
|
||||||
|
template< CapabilityList T >
|
||||||
|
struct get_capability_list< T >
|
||||||
|
{
|
||||||
|
using type= decltype( extract_list( std::declval< const T & >() ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
template
|
||||||
|
<
|
||||||
|
template< typename ... > class Built,
|
||||||
|
typename ... LeftArgs,
|
||||||
|
typename ... RightArgs,
|
||||||
|
CapabilityList List
|
||||||
|
>
|
||||||
|
struct get_capability_list< Built< LeftArgs..., List, RightArgs... > >
|
||||||
|
{
|
||||||
|
using type= typename get_capability_list< List >::type;
|
||||||
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
constexpr bool is_capability_list_v= is_capability_list( Meta::type_value< T >{} );
|
using get_capability_list_t= typename get_capability_list< T >::type;
|
||||||
|
|
||||||
|
|
||||||
template< template< typename ... > class ... HigherKinds >
|
|
||||||
struct higher_kind_tuple {};
|
|
||||||
|
|
||||||
template< typename Cap, typename ... Caps >
|
|
||||||
consteval bool
|
|
||||||
has_cap_in_capability_base( const Meta::type_value< Capabilities< Caps... > > &, Meta::type_value< Cap > cap )
|
|
||||||
{
|
|
||||||
Meta::Container::vector< Caps... > types;
|
|
||||||
using std::begin, std::end;
|
|
||||||
return Meta::find_if( begin( types ), end( types ), Meta::bind1st( Meta::is_base_of, cap ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Left, typename Cap >
|
|
||||||
constexpr bool
|
|
||||||
has_cap_in_capability_base( const Left &, Meta::type_value< Cap > cap )
|
|
||||||
{
|
|
||||||
throw "Unevaluated";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Cap, typename ... TParams >
|
|
||||||
consteval bool
|
|
||||||
has_cap( const Meta::Container::vector< TParams... > &types, Meta::type_value< Cap > cap )
|
|
||||||
{
|
|
||||||
bool rv= 0;
|
|
||||||
template_for( types ) <=[&]
|
|
||||||
( const auto type )
|
|
||||||
{
|
|
||||||
if( is_capability_list( type ) and has_cap_in_capability_base( type, cap ) ) rv= true;
|
|
||||||
};
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Cap, template< typename ... > class Class, typename ... TParams >
|
|
||||||
consteval bool
|
|
||||||
has_cap( const Meta::type_value< Class< TParams... > > &, Meta::type_value< Cap > cap )
|
|
||||||
{
|
|
||||||
return has_cap( Meta::Container::vector< TParams... >{}, cap );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Type, typename Cap >
|
|
||||||
consteval bool
|
|
||||||
has_cap( const Meta::type_value< Type > &, Meta::type_value< Cap > )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace exports
|
namespace exports
|
||||||
{
|
{
|
||||||
template< typename T, typename cap >
|
template< typename T, typename Capability >
|
||||||
constexpr bool has_capability_v=
|
constexpr bool has_capability_v=
|
||||||
std::is_base_of_v< cap, T >
|
has_capability_in_list_v< Capability, get_capability_list_t< T > >
|
||||||
or
|
or
|
||||||
has_cap( Meta::type_value< T >{}, Meta::type_value< cap >{} );
|
DerivedFrom< T, Capability >;
|
||||||
|
|
||||||
template< typename T, typename cap >
|
template< typename T, typename Capability >
|
||||||
struct has_capability_s : std::bool_constant< has_capability_v< T, cap > > {};
|
concept HasCapability= has_capability_v< T, Capability >;
|
||||||
|
|
||||||
inline constexpr Meta::trait< has_capability_s > has_capability;
|
template< typename T, typename Capability >
|
||||||
|
concept Capable= HasCapability< T, Capability >;
|
||||||
template< typename T, typename capability >
|
|
||||||
concept Capability= has_capability_v< T, capability >;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct capability_demo {};
|
struct capability_demo {};
|
||||||
struct missing_capability_demo {};
|
struct missing_capability_demo {};
|
||||||
template< typename= Capabilities< capability_demo > >
|
template< typename= Capabilities< capability_demo > >
|
||||||
struct Capable_base {};
|
struct Example_base {};
|
||||||
using Capable= Capable_base<>;
|
using Example= Example_base<>;
|
||||||
static_assert( Capability< Capable, capability_demo > == true );
|
static_assert( not DerivedFrom< Example, capability_demo > );
|
||||||
static_assert( Capability< Capable, missing_capability_demo > == false );
|
static_assert( has_capability_in_list_v< capability_demo, TypeList< capability_demo > > );
|
||||||
template< Capability< missing_capability_demo > C > void f( C ) {}
|
using XXx= get_capability_list_t< Capabilities< capability_demo > >;
|
||||||
|
constexpr XXx qqq= TypeList< capability_demo >{};
|
||||||
|
constexpr TypeList< capability_demo > zzz= get_capability_list_t< Example >{};
|
||||||
|
static_assert( std::is_same_v< get_capability_list_t< Capabilities< capability_demo > >, TypeList< capability_demo > > );
|
||||||
|
static_assert( std::is_same_v< get_capability_list_t< Example >, TypeList< capability_demo > > );
|
||||||
|
static_assert( std::is_same_v< capability_demo, car_t< get_capability_list_t< Example > > > == true );
|
||||||
|
static_assert( has_capability_in_list_v< capability_demo, TypeList< capability_demo > > == true );
|
||||||
|
static_assert( has_capability_in_list_v< capability_demo, get_capability_list_t< Example > > == true );
|
||||||
|
static_assert( HasCapability< Example, capability_demo > == true );
|
||||||
|
static_assert( HasCapability< Example, missing_capability_demo > == false );
|
||||||
|
template< HasCapability< missing_capability_demo > C > void f( C ) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace exports::Capabilities_m
|
namespace exports::Capabilities_m
|
||||||
|
@ -79,7 +79,7 @@ namespace Alepha::Hydrogen ::detail:: swappable_m
|
|||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
concept MemberSwapLensable= Capability< T, swappable > or HasMemberSwapLens< T >;
|
concept MemberSwapLensable= HasCapability< T, swappable > or HasMemberSwapLens< T >;
|
||||||
|
|
||||||
template< MemberSwapLensable T >
|
template< MemberSwapLensable T >
|
||||||
constexpr decltype( auto )
|
constexpr decltype( auto )
|
||||||
|
Reference in New Issue
Block a user