Skip to content

Commit

Permalink
Refactor is_array...
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 5, 2024
1 parent 397d8db commit aab9884
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 68 deletions.
69 changes: 69 additions & 0 deletions include/tao/pq/is_array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2024 Daniel Frey and Dr. Colin Hirsch
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)

#ifndef TAO_PQ_IS_ARRAY_HPP
#define TAO_PQ_IS_ARRAY_HPP

#include <array>
#include <cstddef>
#include <list>
#include <set>
#include <unordered_set>
#include <utility>
#include <vector>

namespace tao::pq
{
namespace internal
{
template< typename >
inline constexpr bool is_array_parameter = false;

template< typename T, std::size_t N >
inline constexpr bool is_array_parameter< std::array< T, N > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::list< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::unordered_set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::vector< Ts... > > = true;

template<>
inline constexpr bool is_array_parameter< std::vector< std::byte > > = false;

template< typename >
inline constexpr bool is_array_result = false;

template< typename... Ts >
inline constexpr bool is_array_result< std::list< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_result< std::set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_result< std::unordered_set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_result< std::vector< Ts... > > = true;

template<>
inline constexpr bool is_array_result< std::vector< std::byte > > = false;

} // namespace internal

template< typename T >
inline constexpr bool is_array_parameter = internal::is_array_parameter< T >;

template< typename T >
inline constexpr bool is_array_result = internal::is_array_result< T >;

} // namespace tao::pq

#endif
37 changes: 2 additions & 35 deletions include/tao/pq/parameter_traits_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,21 @@
#ifndef TAO_PQ_PARAMETER_TRAITS_ARRAY_HPP
#define TAO_PQ_PARAMETER_TRAITS_ARRAY_HPP

#include <array>
#include <cstddef>
#include <list>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#include <tao/pq/is_array.hpp>
#include <tao/pq/oid.hpp>
#include <tao/pq/parameter_traits.hpp>

namespace tao::pq
{
namespace internal
{
template< typename >
inline constexpr bool is_array_parameter = false;

template< typename T, std::size_t N >
inline constexpr bool is_array_parameter< std::array< T, N > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::list< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::unordered_set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_parameter< std::vector< Ts... > > = true;

template<>
inline constexpr bool is_array_parameter< std::vector< std::byte > > = false;

} // namespace internal

template< typename T >
inline constexpr bool is_array_parameter = internal::is_array_parameter< T >;

namespace internal
{
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 ) ) );
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 ) );

template< typename T >
requires( !pq::is_array_parameter< T > )
void to_array( std::string& data, const T& v )
{
parameter_traits< T >( v ).template element< 0 >( data );
Expand Down
34 changes: 2 additions & 32 deletions include/tao/pq/result_traits_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,23 @@
#ifndef TAO_PQ_RESULT_TRAITS_ARRAY_HPP
#define TAO_PQ_RESULT_TRAITS_ARRAY_HPP

#include <list>
#include <set>
#include <stdexcept>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

#include <tao/pq/is_array.hpp>
#include <tao/pq/result_traits.hpp>

namespace tao::pq
{
namespace internal
{
template< typename >
inline constexpr bool is_array_result = false;

template< typename... Ts >
inline constexpr bool is_array_result< std::list< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_result< std::set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_result< std::unordered_set< Ts... > > = true;

template< typename... Ts >
inline constexpr bool is_array_result< std::vector< Ts... > > = true;

template<>
inline constexpr bool is_array_result< std::vector< std::byte > > = false;

} // namespace internal

template< typename T >
inline constexpr bool is_array_result = internal::is_array_result< T >;

namespace internal
{
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 ) ) );
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 ) );

[[nodiscard]] auto parse_quoted( const char*& value ) -> std::string;
[[nodiscard]] auto parse_unquoted( const char*& value ) -> std::string;

template< typename T >
requires( !pq::is_array_result< T > )
[[nodiscard]] auto parse( const char*& value ) -> T
{
if( *value == '"' ) {
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pq/table_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ namespace tao::pq
void insert_raw( const std::string_view data );

template< parameter_type... As >
requires( sizeof...( As ) >= 1 )
void insert( As&&... as )
{
static_assert( sizeof...( As ) >= 1, "calling tao::pq::table_writer::insert() requires at least one argument" );
return insert_traits( parameter_traits< std::decay_t< As > >( std::forward< As >( as ) )... );
}

Expand Down

0 comments on commit aab9884

Please sign in to comment.