Skip to content

Commit

Permalink
Fix tuple<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 5, 2024
1 parent b3f120a commit 4841171
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/tao/pq/parameter_traits_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pq/result_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 >;
};

Expand Down
8 changes: 7 additions & 1 deletion include/tao/pq/result_traits_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include <tao/pq/internal/exclusive_scan.hpp>
#include <tao/pq/result_traits.hpp>

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 > >
{
Expand All @@ -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 > );
Expand Down
10 changes: 10 additions & 0 deletions src/test/pq/parameter_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 > > );

Expand All @@ -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<T> 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
{
Expand Down
10 changes: 10 additions & 0 deletions src/test/pq/result_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 > > );

Expand All @@ -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<T> 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
{
Expand Down

0 comments on commit 4841171

Please sign in to comment.