forked from Alepha/Alepha
Well this whole () base TMP experiment kinda works.
It's a lot of heavy lifting. I'm not sure it actually adds any useful value yet, but I'll continue to play with it. It is nice that we can *sometimes* use loops. Sometimes we can't though. And we have to make some blind-corner evaluations that throw dummy failures to keep the compiler from complaining about missing cases -- despite the fact that they;ll never be reached at compiletime. (Runtime evaluation could be different, of course.) I think, perhaps, a universal representation of a dereferenced iterator might solve some of this, but I also don't want to sink too much effort into this, despite how much fun I'm having.
This commit is contained in:
@ -12,21 +12,35 @@ namespace Alepha::Hydrogen::Meta
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
template< typename >
|
||||
struct type_value {};
|
||||
template< typename Type >
|
||||
struct type_value { using type= Type; };
|
||||
|
||||
template< template< typename > class Trait, typename Value >
|
||||
constexpr bool
|
||||
check_trait( type_value< Value > )
|
||||
{
|
||||
return Trait< Value >::value;
|
||||
}
|
||||
|
||||
template< template< typename, typename > class Trait, typename A, typename B >
|
||||
constexpr bool
|
||||
check_trait( type_value< A >, type_value< B > )
|
||||
{
|
||||
return Trait< A, B >::value;
|
||||
}
|
||||
|
||||
template< typename Lhs, typename Rhs >
|
||||
constexpr bool
|
||||
operator == ( type_value< Lhs >, type_value< Rhs > )
|
||||
operator == ( type_value< Lhs > lhs, type_value< Rhs > rhs )
|
||||
{
|
||||
return false;
|
||||
return check_trait< std::is_same >( lhs, rhs );
|
||||
}
|
||||
|
||||
template< typename Value >
|
||||
template< typename Lhs, typename Rhs >
|
||||
constexpr bool
|
||||
operator == ( type_value< Value >, type_value< Value > )
|
||||
operator != ( type_value< Lhs > lhs, type_value< Rhs > rhs )
|
||||
{
|
||||
return true;
|
||||
return not( lhs == rhs );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
@ -35,6 +49,34 @@ namespace Alepha::Hydrogen::Meta
|
||||
{
|
||||
return type_value< std::decay_t< T > >{};
|
||||
}
|
||||
|
||||
template< template< typename ... > class Trait > struct trait;
|
||||
|
||||
template< template< typename > class Trait >
|
||||
struct trait< Trait >
|
||||
{
|
||||
template< typename Type >
|
||||
constexpr bool
|
||||
operator() ( type_value< Type > ) const
|
||||
{
|
||||
return Trait< Type >::value;
|
||||
}
|
||||
};
|
||||
|
||||
template< template< typename, typename > class Trait >
|
||||
struct trait< Trait >
|
||||
{
|
||||
template< typename A, typename B >
|
||||
constexpr bool
|
||||
operator() ( type_value< A >, type_value< B > ) const
|
||||
{
|
||||
return Trait< A, B >::value;
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr trait< std::is_base_of > is_base_of;
|
||||
inline constexpr trait< std::is_same > is_same;
|
||||
inline constexpr trait< std::is_default_constructible > is_default_constructible;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user