|
|
|
@ -14,11 +14,38 @@ namespace Alepha::Hydrogen ::detail:: template_for_each_m
|
|
|
|
|
{
|
|
|
|
|
inline namespace exports
|
|
|
|
|
{
|
|
|
|
|
constexpr void tuple_for_each( const std::tuple<> &, const Functional auto ) noexcept {}
|
|
|
|
|
template< Tuple Type >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
template_for( Type &tuple ) noexcept;
|
|
|
|
|
|
|
|
|
|
template< Tuple Type >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
template_for( const Type &tuple ) noexcept;
|
|
|
|
|
|
|
|
|
|
template< Aggregate Type >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
template_for( Type &agg, std::optional< Reflection::aggregate_tuple_t< Type > > &&tupled= {} ) noexcept
|
|
|
|
|
{
|
|
|
|
|
tupled= Reflection::tuplizeAggregate( agg );
|
|
|
|
|
return template_for( *tupled );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template< Aggregate Type >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
template_for( const Type &agg, std::optional< Reflection::aggregate_tuple_t< Type > > &&tupled= {} ) noexcept
|
|
|
|
|
{
|
|
|
|
|
tupled= Reflection::tuplizeAggregate( agg );
|
|
|
|
|
return template_for( *tupled );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template< typename ... Args, typename Function >
|
|
|
|
|
constexpr void
|
|
|
|
|
tuple_for_each( const std::tuple< Args... > &tuple, Function body )
|
|
|
|
|
template_for_impl( const std::tuple< Args... > &tuple, Function body )
|
|
|
|
|
noexcept
|
|
|
|
|
(
|
|
|
|
|
( ... and noexcept( body( std::declval< const Args & >() ) ) )
|
|
|
|
@ -36,31 +63,18 @@ namespace Alepha::Hydrogen ::detail:: template_for_each_m
|
|
|
|
|
std::apply( loop_body_handler, tuple );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply type_identity to all tuple elements
|
|
|
|
|
template< typename > struct type_identify_tuple;
|
|
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
|
using type_identify_tuple_t= typename type_identify_tuple< T >::type;
|
|
|
|
|
|
|
|
|
|
template<> struct type_identify_tuple< std::tuple<> > { using type= std::tuple<>; };
|
|
|
|
|
|
|
|
|
|
template< typename ... Args >
|
|
|
|
|
struct type_identify_tuple< std::tuple< Args... > >
|
|
|
|
|
{
|
|
|
|
|
using type= std::tuple< std::type_identity< Args >... >;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Nicer for-each syntax helper:
|
|
|
|
|
template< typename Tuple >
|
|
|
|
|
struct for_each_syntax_adaptor
|
|
|
|
|
struct [[nodiscard]] syntax_adaptor
|
|
|
|
|
{
|
|
|
|
|
Tuple &tuple;
|
|
|
|
|
|
|
|
|
|
template< typename Function >
|
|
|
|
|
constexpr void
|
|
|
|
|
operator <= ( Function &&func ) noexcept( noexcept( tuple_for_each( tuple, std::forward< Function >( func ) ) ) )
|
|
|
|
|
operator <= ( Function &&func ) noexcept( noexcept( template_for_impl( tuple, std::forward< Function >( func ) ) ) )
|
|
|
|
|
{
|
|
|
|
|
return tuple_for_each( tuple, std::forward< Function >( func ) );
|
|
|
|
|
return template_for_impl( tuple, std::forward< Function >( func ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr operator decltype( std::ignore ) () const= delete;
|
|
|
|
@ -69,43 +83,34 @@ namespace Alepha::Hydrogen ::detail:: template_for_each_m
|
|
|
|
|
template< typename Tuple >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
tuple_for_each( Tuple &tuple ) noexcept
|
|
|
|
|
template_for_impl( Tuple &tuple ) noexcept
|
|
|
|
|
{
|
|
|
|
|
return for_each_syntax_adaptor< Tuple >{ tuple };
|
|
|
|
|
return syntax_adaptor< Tuple >{ tuple };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template< typename Tuple >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
tuple_for_each( const Tuple &tuple ) noexcept
|
|
|
|
|
template_for_impl( const Tuple &tuple ) noexcept
|
|
|
|
|
{
|
|
|
|
|
return for_each_syntax_adaptor< const Tuple >{ tuple };
|
|
|
|
|
return syntax_adaptor< const Tuple >{ tuple };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template< typename Type >
|
|
|
|
|
concept TemplateLoopable= false
|
|
|
|
|
or Tuple< Type >
|
|
|
|
|
or Aggregate< Type >
|
|
|
|
|
// or Array< T > // Do we need array support? Does it matter?
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
template< TemplateLoopable Type >
|
|
|
|
|
template< Tuple Type >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
template_for( Type &tuple, std::optional< Reflection::aggregate_tuple_t< Type > > &&tupled= {} ) noexcept
|
|
|
|
|
exports::template_for( Type &tuple ) noexcept
|
|
|
|
|
{
|
|
|
|
|
tupled= Reflection::tuplizeAggregate( tuple );
|
|
|
|
|
return tuple_for_each( *tupled );
|
|
|
|
|
return template_for_impl( tuple );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template< TemplateLoopable Type >
|
|
|
|
|
template< Tuple Type >
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
constexpr auto
|
|
|
|
|
template_for( const Type &tuple, std::optional< Reflection::aggregate_tuple_t< Type > > &&tupled= {} ) noexcept
|
|
|
|
|
exports::template_for( const Type &tuple ) noexcept
|
|
|
|
|
{
|
|
|
|
|
tupled= Reflection::tuplizeAggregate( tuple );
|
|
|
|
|
return tuple_for_each( *tupled );
|
|
|
|
|
}
|
|
|
|
|
return template_for_impl( tuple );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|