forked from Alepha/Alepha
Split out the tuple adapter from the test framework.
Part of the larger testing framework simplification.
This commit is contained in:
@ -32,6 +32,7 @@ static_assert( __cplusplus > 2020'00 );
|
|||||||
#include <Alepha/IOStreams/String.h>
|
#include <Alepha/IOStreams/String.h>
|
||||||
|
|
||||||
#include <Alepha/Utility/evaluation_helpers.h>
|
#include <Alepha/Utility/evaluation_helpers.h>
|
||||||
|
#include <Alepha/Utility/TupleAdapter.h>
|
||||||
|
|
||||||
#include <Alepha/Reflection/tuplizeAggregate.h>
|
#include <Alepha/Reflection/tuplizeAggregate.h>
|
||||||
|
|
||||||
@ -60,38 +61,6 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
|
|||||||
template< OutputMode outputMode, typename T >
|
template< OutputMode outputMode, typename T >
|
||||||
void printDebugging( const T &witness, const T &expected );
|
void printDebugging( const T &witness, const T &expected );
|
||||||
|
|
||||||
template< Aggregate Agg, TypeListType >
|
|
||||||
struct TupleSneak;
|
|
||||||
|
|
||||||
template< Aggregate Agg >
|
|
||||||
struct TupleSneak< Agg, Nil >
|
|
||||||
: Agg
|
|
||||||
{
|
|
||||||
TupleSneak() { std::cerr << "The inherited default ctor was called." << std::endl; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void set( Agg agg ) { static_cast< Agg & >( *this )= agg; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template< Aggregate Agg, typename ... Args >
|
|
||||||
struct TupleSneak< Agg, TypeList< Args... > >
|
|
||||||
: TupleSneak< Agg, cdr_t< TypeList< Args... > > >
|
|
||||||
{
|
|
||||||
using Parent= TupleSneak< Agg, cdr_t< TypeList< Args... > > >;
|
|
||||||
using Parent::Parent;
|
|
||||||
|
|
||||||
TupleSneak( Args ... args )
|
|
||||||
{
|
|
||||||
std::cerr << "I was the ctor called, with " << sizeof...( Args ) << " arguments." << std::endl;
|
|
||||||
tuple_for_each( std::tuple{ args... } ) <=
|
|
||||||
[]( const auto element )
|
|
||||||
{
|
|
||||||
std::cerr << "Element: " << element << std::endl;
|
|
||||||
};
|
|
||||||
this->set( { args... } );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class TestResult { Passed, Failed };
|
enum class TestResult { Passed, Failed };
|
||||||
|
|
||||||
struct BlankBase {};
|
struct BlankBase {};
|
||||||
@ -100,7 +69,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
|
|||||||
static consteval auto
|
static consteval auto
|
||||||
compute_base_f() noexcept
|
compute_base_f() noexcept
|
||||||
{
|
{
|
||||||
if constexpr ( Aggregate< T > ) return std::type_identity< TupleSneak< T, list_from_tuple_t< Reflection::aggregate_tuple_t< T > > > >{};
|
if constexpr ( Aggregate< T > ) return std::type_identity< Utility::TupleAdapter< T > >{};
|
||||||
else if constexpr( std::is_class_v< T > ) return std::type_identity< T >{};
|
else if constexpr( std::is_class_v< T > ) return std::type_identity< T >{};
|
||||||
else return std::type_identity< BlankBase >{};
|
else return std::type_identity< BlankBase >{};
|
||||||
}
|
}
|
||||||
|
|||||||
55
Utility/TupleAdapter.h
Normal file
55
Utility/TupleAdapter.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
static_assert( __cplusplus > 2020'00 );
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
|
#include <Alepha/type_lisp.h>
|
||||||
|
|
||||||
|
#include <Alepha/Reflection/tuplizeAggregate.h>
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::Utility ::detail:: TupleAdapter_m
|
||||||
|
{
|
||||||
|
inline namespace exports {}
|
||||||
|
|
||||||
|
template< Aggregate, TypeListType >
|
||||||
|
struct TupleAdapter_impl;
|
||||||
|
|
||||||
|
namespace exports
|
||||||
|
{
|
||||||
|
template< Aggregate Agg >
|
||||||
|
using TupleAdapter= TupleAdapter_impl
|
||||||
|
<
|
||||||
|
Agg,
|
||||||
|
list_from_tuple_t< Reflection::aggregate_tuple_t< Agg > >
|
||||||
|
>;
|
||||||
|
}
|
||||||
|
|
||||||
|
template< Aggregate Agg >
|
||||||
|
struct TupleAdapter_impl< Agg, Nil >
|
||||||
|
: Agg
|
||||||
|
{
|
||||||
|
TupleAdapter_impl()= default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void set( Agg agg ) { static_cast< Agg & >( *this )= agg; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template< Aggregate Agg, typename ... Args >
|
||||||
|
struct TupleAdapter_impl< Agg, TypeList< Args... > >
|
||||||
|
: TupleAdapter_impl< Agg, cdr_t< TypeList< Args... > > >
|
||||||
|
{
|
||||||
|
using Parent= TupleAdapter_impl< Agg, cdr_t< TypeList< Args... > > >;
|
||||||
|
using Parent::Parent;
|
||||||
|
|
||||||
|
TupleAdapter_impl( Args ... args )
|
||||||
|
{
|
||||||
|
this->set( { args... } );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::Utility::inline exports::inline TupleAdapter_m
|
||||||
|
{
|
||||||
|
using namespace detail::TupleAdapter_m::exports;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user