From e0e99ead461ed5d52e2e7520a58ff1a8ae47f3f1 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 5 Nov 2023 00:30:15 -0400 Subject: [PATCH] Split out the tuple adapter from the test framework. Part of the larger testing framework simplification. --- Testing/TableTest.h | 35 ++------------------------- Utility/TupleAdapter.h | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 Utility/TupleAdapter.h diff --git a/Testing/TableTest.h b/Testing/TableTest.h index 70b125c..4d96289 100644 --- a/Testing/TableTest.h +++ b/Testing/TableTest.h @@ -32,6 +32,7 @@ static_assert( __cplusplus > 2020'00 ); #include #include +#include #include @@ -60,38 +61,6 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test template< OutputMode outputMode, typename T > 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 }; struct BlankBase {}; @@ -100,7 +69,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test static consteval auto 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 return std::type_identity< BlankBase >{}; } diff --git a/Utility/TupleAdapter.h b/Utility/TupleAdapter.h new file mode 100644 index 0000000..6caa139 --- /dev/null +++ b/Utility/TupleAdapter.h @@ -0,0 +1,55 @@ +static_assert( __cplusplus > 2020'00 ); + +#pragma once + +#include + +#include + +#include + +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; +}