Skip to content

Commit

Permalink
More concept checks
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Nov 28, 2024
1 parent 6f20dbc commit c2686fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/tao/pq/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace tao::pq

namespace internal
{
template< typename A >
template< typename >
inline constexpr bool is_parameter = false;

template< std::size_t Max >
Expand Down
19 changes: 15 additions & 4 deletions include/tao/pq/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace tao::pq

[[nodiscard]] auto at( const std::size_t row ) const -> pq::row;

template< typename T >
template< result_type T >
[[nodiscard]] auto as() const -> T
{
switch( size() ) {
Expand All @@ -240,7 +240,7 @@ namespace tao::pq
}
}

template< typename T >
template< result_type T >
[[nodiscard]] auto optional() const -> std::optional< T >
{
switch( size() ) {
Expand All @@ -255,19 +255,20 @@ namespace tao::pq
}
}

template< typename T, typename U >
template< result_type T, result_type U >
[[nodiscard]] auto pair() const
{
return as< std::pair< T, U > >();
}

template< typename... Ts >
template< result_type... Ts >
[[nodiscard]] auto tuple() const
{
return as< std::tuple< Ts... > >();
}

template< typename T >
requires result_type< typename T::value_type >
[[nodiscard]] auto as_container() const -> T
{
check_has_result_set();
Expand All @@ -282,60 +283,70 @@ namespace tao::pq
}

template< typename... Ts >
requires result_type< typename std::vector< Ts... >::value_type >
[[nodiscard]] auto vector() const
{
return as_container< std::vector< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::list< Ts... >::value_type >
[[nodiscard]] auto list() const
{
return as_container< std::list< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::set< Ts... >::value_type >
[[nodiscard]] auto set() const
{
return as_container< std::set< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::multiset< Ts... >::value_type >
[[nodiscard]] auto multiset() const
{
return as_container< std::multiset< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_set< Ts... >::value_type >
[[nodiscard]] auto unordered_set() const
{
return as_container< std::unordered_set< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_multiset< Ts... >::value_type >
[[nodiscard]] auto unordered_multiset() const
{
return as_container< std::unordered_multiset< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::map< Ts... >::value_type >
[[nodiscard]] auto map() const
{
return as_container< std::map< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::multimap< Ts... >::value_type >
[[nodiscard]] auto multimap() const
{
return as_container< std::multimap< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_map< Ts... >::value_type >
[[nodiscard]] auto unordered_map() const
{
return as_container< std::unordered_map< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_multimap< Ts... >::value_type >
[[nodiscard]] auto unordered_multimap() const
{
return as_container< std::unordered_multimap< Ts... > >();
Expand Down
13 changes: 12 additions & 1 deletion include/tao/pq/table_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace tao::pq
void check_result();

public:
template< typename... As >
template< parameter_type... As >
table_reader( const std::shared_ptr< transaction >& transaction, const internal::zsv statement, As&&... as )
: m_previous( transaction ),
m_transaction( std::make_shared< internal::transaction_guard >( transaction->connection() ) ),
Expand Down Expand Up @@ -154,6 +154,7 @@ namespace tao::pq
}

template< typename T >
requires result_type< typename T::value_type >
[[nodiscard]] auto as_container() -> T
{
T nrv;
Expand All @@ -164,60 +165,70 @@ namespace tao::pq
}

template< typename... Ts >
requires result_type< typename std::vector< Ts... >::value_type >
[[nodiscard]] auto vector()
{
return as_container< std::vector< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::list< Ts... >::value_type >
[[nodiscard]] auto list()
{
return as_container< std::list< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::set< Ts... >::value_type >
[[nodiscard]] auto set()
{
return as_container< std::set< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::multiset< Ts... >::value_type >
[[nodiscard]] auto multiset()
{
return as_container< std::multiset< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_set< Ts... >::value_type >
[[nodiscard]] auto unordered_set()
{
return as_container< std::unordered_set< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_multiset< Ts... >::value_type >
[[nodiscard]] auto unordered_multiset()
{
return as_container< std::unordered_multiset< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::map< Ts... >::value_type >
[[nodiscard]] auto map()
{
return as_container< std::map< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::multimap< Ts... >::value_type >
[[nodiscard]] auto multimap()
{
return as_container< std::multimap< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_map< Ts... >::value_type >
[[nodiscard]] auto unordered_map()
{
return as_container< std::unordered_map< Ts... > >();
}

template< typename... Ts >
requires result_type< typename std::unordered_multimap< Ts... >::value_type >
[[nodiscard]] auto unordered_multimap()
{
return as_container< std::unordered_multimap< Ts... > >();
Expand Down

0 comments on commit c2686fa

Please sign in to comment.