From 484117170757d749561127f6114758d34fde00b7 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Thu, 5 Dec 2024 18:10:40 +0100 Subject: [PATCH] Fix tuple --- include/tao/pq/parameter_traits_tuple.hpp | 7 +++++++ include/tao/pq/result_traits.hpp | 2 +- include/tao/pq/result_traits_tuple.hpp | 8 +++++++- src/test/pq/parameter_type.cpp | 10 ++++++++++ src/test/pq/result_type.cpp | 10 ++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/tao/pq/parameter_traits_tuple.hpp b/include/tao/pq/parameter_traits_tuple.hpp index 41305c7..cc2cfd1 100644 --- a/include/tao/pq/parameter_traits_tuple.hpp +++ b/include/tao/pq/parameter_traits_tuple.hpp @@ -61,6 +61,13 @@ struct tao::pq::parameter_traits< std::tuple< Ts... > > return std::get< gen::template outer< I > >( m_tuple ).template format< gen::template inner< I > >(); } + template< std::size_t I > + requires( sizeof...( Ts ) == 1 ) + void element( std::string& data ) const + { + std::get< gen::template outer< I > >( m_tuple ).template element< gen::template inner< I > >( data ); + } + template< std::size_t I > void copy_to( std::string& data ) const { diff --git a/include/tao/pq/result_traits.hpp b/include/tao/pq/result_traits.hpp index f91c541..b06a6b1 100644 --- a/include/tao/pq/result_traits.hpp +++ b/include/tao/pq/result_traits.hpp @@ -36,7 +36,7 @@ namespace tao::pq class row; template< typename T > - concept result_type_composite = ( ( result_traits_size< T > > 1 ) || is_aggregate_result< T > ) && requires( const row& r ) { + concept result_type_composite = ( ( result_traits_size< T > != 1 ) || is_aggregate_result< T > ) && requires( const row& r ) { { result_traits< T >::from( r ) } -> std::same_as< T >; }; diff --git a/include/tao/pq/result_traits_tuple.hpp b/include/tao/pq/result_traits_tuple.hpp index 857c0a4..eb86c66 100644 --- a/include/tao/pq/result_traits_tuple.hpp +++ b/include/tao/pq/result_traits_tuple.hpp @@ -13,6 +13,12 @@ #include #include +template<> +struct tao::pq::result_traits< std::tuple<> > +{ + static constexpr std::size_t size = 0; +}; + template< typename T > struct tao::pq::result_traits< std::tuple< T > > { @@ -33,7 +39,7 @@ struct tao::pq::result_traits< std::tuple< T > > }; template< typename... Ts > - requires( sizeof...( Ts ) != 0 ) + requires( sizeof...( Ts ) >= 2 ) struct tao::pq::result_traits< std::tuple< Ts... > > { static constexpr std::size_t size = ( 0 + ... + result_traits_size< Ts > ); diff --git a/src/test/pq/parameter_type.cpp b/src/test/pq/parameter_type.cpp index e6a5ae6..0ce3e60 100644 --- a/src/test/pq/parameter_type.cpp +++ b/src/test/pq/parameter_type.cpp @@ -60,6 +60,8 @@ static_assert( tao::pq::parameter_type< std::pair< bool, int > > ); static_assert( tao::pq::parameter_type< std::pair< std::string, tao::pq::binary > > ); // tuple +static_assert( !tao::pq::parameter_type< std::tuple<> > ); +static_assert( tao::pq::parameter_type< std::tuple< int > > ); static_assert( tao::pq::parameter_type< std::tuple< bool, int, float > > ); static_assert( tao::pq::parameter_type< std::tuple< std::string, tao::pq::binary, unsigned > > ); @@ -69,11 +71,19 @@ static_assert( tao::pq::parameter_type< std::array< std::string, 42 > > ); static_assert( tao::pq::parameter_type< std::list< std::string_view > > ); static_assert( tao::pq::parameter_type< std::set< double > > ); static_assert( tao::pq::parameter_type< std::unordered_set< char > > ); +static_assert( !tao::pq::parameter_type< std::set< std::pair< int, double > > > ); +static_assert( !tao::pq::parameter_type< std::set< std::tuple<> > > ); +static_assert( tao::pq::parameter_type< std::set< std::tuple< int > > > ); +static_assert( !tao::pq::parameter_type< std::set< std::tuple< bool, int, double > > > ); // note: vector except for T == std::byte are registered as arrays by default static_assert( tao::pq::parameter_type< std::vector< bool > > ); static_assert( tao::pq::parameter_type< std::vector< unsigned long long > > ); +static_assert( tao::pq::parameter_type< std::vector< std::set< double > > > ); +static_assert( tao::pq::parameter_type< std::set< std::vector< double > > > ); +static_assert( tao::pq::parameter_type< std::list< std::unordered_set< std::tuple< int > > > > ); + // aggregate namespace example { diff --git a/src/test/pq/result_type.cpp b/src/test/pq/result_type.cpp index 35a98ae..d7a53f2 100644 --- a/src/test/pq/result_type.cpp +++ b/src/test/pq/result_type.cpp @@ -58,6 +58,8 @@ static_assert( tao::pq::result_type< std::pair< bool, int > > ); static_assert( tao::pq::result_type< std::pair< std::string, tao::pq::binary > > ); // tuple +static_assert( !tao::pq::result_type< std::tuple<> > ); +static_assert( tao::pq::result_type< std::tuple< int > > ); static_assert( tao::pq::result_type< std::tuple< bool, int, float > > ); static_assert( tao::pq::result_type< std::tuple< std::string, tao::pq::binary, unsigned > > ); @@ -67,11 +69,19 @@ static_assert( !tao::pq::result_type< std::array< std::string, 42 > > ); static_assert( tao::pq::result_type< std::list< std::string_view > > ); static_assert( tao::pq::result_type< std::set< double > > ); static_assert( tao::pq::result_type< std::unordered_set< char > > ); +static_assert( !tao::pq::result_type< std::set< std::pair< int, double > > > ); +static_assert( !tao::pq::result_type_direct< std::set< std::tuple<> > > ); +static_assert( tao::pq::result_type< std::set< std::tuple< int > > > ); +static_assert( !tao::pq::result_type< std::set< std::tuple< bool, int, double > > > ); // note: vector except for T == std::byte are registered as arrays by default static_assert( tao::pq::result_type< std::vector< bool > > ); static_assert( tao::pq::result_type< std::vector< unsigned long long > > ); +static_assert( tao::pq::result_type< std::vector< std::set< double > > > ); +static_assert( tao::pq::result_type< std::set< std::vector< double > > > ); +static_assert( tao::pq::result_type< std::list< std::unordered_set< std::tuple< int > > > > ); + // aggregate namespace example {