Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 10, 2024
1 parent 395012f commit 3ea59b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
8 changes: 4 additions & 4 deletions include/tao/pq/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ namespace tao::pq
template< std::size_t Max >
inline constexpr bool is_parameter< parameter< Max > > = true;

template< typename... As >
inline constexpr bool contains_parameter = ( is_parameter< std::decay_t< As > > || ... );

template< typename... As >
inline constexpr std::size_t parameter_size = ( parameter_size< std::decay_t< As > > + ... + 0 );

Expand All @@ -45,7 +42,10 @@ namespace tao::pq
} // namespace internal

template< typename T >
concept parameter_type = parameter_type_direct< T > || internal::is_parameter< std::decay_t< T > >;
concept parameter_type_composite = internal::is_parameter< std::decay_t< T > >;

template< typename T >
concept parameter_type = parameter_type_direct< T > || parameter_type_composite< T >;

template< std::size_t Max >
class parameter
Expand Down
18 changes: 9 additions & 9 deletions include/tao/pq/parameter_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

namespace tao::pq
{
template< typename T >
struct parameter_traits;

namespace internal
{
// helper for arrays
Expand Down Expand Up @@ -61,15 +64,12 @@ namespace tao::pq
}
}

} // namespace internal

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_has_element = requires( const parameter_traits< std::decay_t< T > >& t, std::string& s ) {
{ t.template element< 0 >( s ) } -> std::same_as< void >;
};
} // namespace internal

template< typename T >
concept parameter_type_direct = requires( const parameter_traits< std::decay_t< T > >& t, std::string& s ) {
Expand All @@ -80,7 +80,7 @@ namespace tao::pq
{ t.template length< 0 >() } -> std::same_as< int >;
{ t.template format< 0 >() } -> std::same_as< int >;
{ t.template copy_to< 0 >( s ) } -> std::same_as< void >;
} && ( ( parameter_traits< std::decay_t< T > >::columns >= 2 ) || parameter_type_has_element< T > );
} && ( ( parameter_traits< std::decay_t< T > >::columns >= 2 ) || internal::parameter_type_has_element< T > );

template<>
struct parameter_traits< null_t >
Expand Down
24 changes: 6 additions & 18 deletions include/tao/pq/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,17 @@ namespace tao::pq
send_traits( statement, parameter_traits< std::decay_t< As > >( std::forward< As >( as ) )... );
}

template< std::size_t Max >
void send( const internal::zsv statement, const parameter< Max >& p )
{
send_params( statement, p.m_size, p.m_types, p.m_values, p.m_lengths, p.m_formats );
}

template< std::size_t Max >
void send( const internal::zsv statement, parameter< Max >& p )
{
send_params( statement, p.m_size, p.m_types, p.m_values, p.m_lengths, p.m_formats );
}

template< std::size_t Max >
void send( const internal::zsv statement, parameter< Max >&& p )
template< parameter_type... As >
requires( parameter_type_composite< As > || ... )
void send( const internal::zsv statement, As&&... as )
{
const parameter< internal::parameter_size< As... > > p( std::forward< As >( as )... );
send_params( statement, p.m_size, p.m_types, p.m_values, p.m_lengths, p.m_formats );
}

template< parameter_type... As >
requires internal::contains_parameter< As... >
void send( const internal::zsv statement, As&&... as )
template< parameter_type_composite A >
void send( const internal::zsv statement, A&& p )
{
const parameter< internal::parameter_size< As... > > p( std::forward< As >( as )... );
send_params( statement, p.m_size, p.m_types, p.m_values, p.m_lengths, p.m_formats );
}

Expand Down

0 comments on commit 3ea59b9

Please sign in to comment.