From 9ee9e844555c4584792725ddcf0083e76f9a8b71 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Wed, 4 Dec 2024 01:16:09 +0100 Subject: [PATCH] Cleanup --- include/tao/pq/parameter_traits.hpp | 8 ++++++-- include/tao/pq/parameter_traits_array.hpp | 8 +++++--- include/tao/pq/parameter_traits_pair.hpp | 6 ------ include/tao/pq/parameter_traits_tuple.hpp | 6 ------ include/tao/pq/result_traits_array.hpp | 8 +++++--- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/tao/pq/parameter_traits.hpp b/include/tao/pq/parameter_traits.hpp index 6fd101e..6271062 100644 --- a/include/tao/pq/parameter_traits.hpp +++ b/include/tao/pq/parameter_traits.hpp @@ -66,6 +66,11 @@ namespace tao::pq template< typename T > struct parameter_traits; + template< typename T > + concept parameter_type_has_element = requires( const parameter_traits< std::decay_t< T > >& t, std::string& s ) { + { t.template element< 0 >( s ) } -> std::same_as< void >; + }; + template< typename T > concept parameter_type_direct = requires( const parameter_traits< std::decay_t< T > >& t, std::string& s ) { { parameter_traits< std::decay_t< T > >::columns } -> std::same_as< const std::size_t& >; @@ -74,9 +79,8 @@ namespace tao::pq { t.template value< 0 >() } -> std::same_as< const char* >; { t.template length< 0 >() } -> std::same_as< int >; { t.template format< 0 >() } -> std::same_as< int >; - { t.template element< 0 >( s ) } -> std::same_as< void >; { t.template copy_to< 0 >( s ) } -> std::same_as< void >; - }; + } && ( ( parameter_traits< std::decay_t< T > >::columns >= 2 ) || parameter_type_has_element< T > ); template<> struct parameter_traits< null_t > diff --git a/include/tao/pq/parameter_traits_array.hpp b/include/tao/pq/parameter_traits_array.hpp index 85656ce..d3871e8 100644 --- a/include/tao/pq/parameter_traits_array.hpp +++ b/include/tao/pq/parameter_traits_array.hpp @@ -49,7 +49,7 @@ namespace tao::pq namespace internal { template< typename T > - requires( !pq::is_array_parameter< T > ) && ( parameter_traits< T >::columns == 1 ) + requires( !pq::is_array_parameter< T > ) void to_array( std::string& data, const T& v ) { parameter_traits< T >( v ).template element< 0 >( data ); @@ -72,10 +72,12 @@ namespace tao::pq } } + template< typename T > + concept array_parameter_type = ( pq::is_array_parameter< T > && ( pq::is_array_parameter< typename T::value_type > || ( parameter_traits< typename T::value_type >::columns == 1 ) ) ); + } // namespace internal - template< typename T > - requires is_array_parameter< T > + template< internal::array_parameter_type T > struct parameter_traits< T > { private: diff --git a/include/tao/pq/parameter_traits_pair.hpp b/include/tao/pq/parameter_traits_pair.hpp index c444b6a..964ac07 100644 --- a/include/tao/pq/parameter_traits_pair.hpp +++ b/include/tao/pq/parameter_traits_pair.hpp @@ -62,12 +62,6 @@ struct tao::pq::parameter_traits< std::pair< T, U > > return std::get< gen::template outer< I > >( m_pair ).template format< gen::template inner< I > >(); } - template< std::size_t I > - void element( std::string& data ) const - { - std::get< gen::template outer< I > >( m_pair ).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/parameter_traits_tuple.hpp b/include/tao/pq/parameter_traits_tuple.hpp index 07be674..41305c7 100644 --- a/include/tao/pq/parameter_traits_tuple.hpp +++ b/include/tao/pq/parameter_traits_tuple.hpp @@ -61,12 +61,6 @@ 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 > - 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_array.hpp b/include/tao/pq/result_traits_array.hpp index c98c8b5..aac03f3 100644 --- a/include/tao/pq/result_traits_array.hpp +++ b/include/tao/pq/result_traits_array.hpp @@ -48,7 +48,7 @@ namespace tao::pq [[nodiscard]] auto parse_unquoted( const char*& value ) -> std::string; template< typename T > - requires( !pq::is_array_result< T > ) && ( result_traits_size< T > == 1 ) + requires( !pq::is_array_result< T > ) [[nodiscard]] auto parse( const char*& value ) -> T { if( *value == '"' ) { @@ -104,10 +104,12 @@ namespace tao::pq } } + template< typename T > + concept array_result_type = ( pq::is_array_result< T > && ( pq::is_array_result< typename T::value_type > || ( result_traits_size< typename T::value_type > == 1 ) ) ); + } // namespace internal - template< typename T > - requires is_array_result< T > + template< internal::array_result_type T > struct result_traits< T > { static auto from( const char* value ) -> T