Skip to content

Commit

Permalink
Seems we finally get pack indexing, see https://groups.google.com/a/i…
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed May 21, 2024
1 parent 21df9f3 commit bbd855d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/tao/pq/table_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <memory>
#include <string>
#include <string_view>
#if !defined( __cpp_pack_indexing )
#include <tuple>
#endif
#include <type_traits>
#include <utility>

Expand All @@ -25,6 +27,28 @@ namespace tao::pq
std::shared_ptr< transaction > m_previous;
std::shared_ptr< transaction > m_transaction;

#if defined( __cpp_pack_indexing )

template< std::size_t... Os, std::size_t... Is, typename... Ts >
void insert_indexed( std::index_sequence< Os... > /*unused*/,
std::index_sequence< Is... > /*unused*/,
const Ts...& ts )
{
std::string buffer;
( ( ts...[ Os ].template copy_to< Is >( buffer ), buffer += '\t' ), ... );
*buffer.rbegin() = '\n';
table_writer::insert_raw( buffer );
}

template< typename... Ts >
void insert_traits( const Ts&... ts )
{
using gen = internal::gen< Ts::columns... >;
table_writer::insert_indexed( typename gen::outer_sequence(), typename gen::inner_sequence(), ts... );
}

#else

template< std::size_t... Os, std::size_t... Is, typename... Ts >
void insert_indexed( std::index_sequence< Os... > /*unused*/,
std::index_sequence< Is... > /*unused*/,
Expand All @@ -43,6 +67,8 @@ namespace tao::pq
table_writer::insert_indexed( typename gen::outer_sequence(), typename gen::inner_sequence(), std::tie( ts... ) );
}

#endif

void check_result();

public:
Expand Down
28 changes: 28 additions & 0 deletions include/tao/pq/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <cstdio>
#include <memory>
#include <string>
#if !defined( __cpp_pack_indexing )
#include <tuple>
#endif
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -66,6 +68,30 @@ namespace tao::pq
const int lengths[],
const int formats[] );

#if defined( __cpp_pack_indexing )

template< std::size_t... Os, std::size_t... Is, typename... Ts >
void send_indexed( const char* statement,
std::index_sequence< Os... > /*unused*/,
std::index_sequence< Is... > /*unused*/,
const Ts...& ts )
{
const Oid types[] = { static_cast< Oid >( ts...[ Os ].template type< Is >() )... };
const char* const values[] = { ts...[ Os ].template value< Is >()... };
const int lengths[] = { ts...[ Os ].template length< Is >()... };
const int formats[] = { ts...[ Os ].template format< Is >()... };
send_params( statement, sizeof...( Os ), types, values, lengths, formats );
}

template< typename... Ts >
void send_traits( const char* statement, const Ts&... ts )
{
using gen = internal::gen< Ts::columns... >;
transaction::send_indexed( statement, typename gen::outer_sequence(), typename gen::inner_sequence(), ts... );
}

#else

template< std::size_t... Os, std::size_t... Is, typename... Ts >
void send_indexed( const char* statement,
std::index_sequence< Os... > /*unused*/,
Expand All @@ -86,6 +112,8 @@ namespace tao::pq
transaction::send_indexed( statement, typename gen::outer_sequence(), typename gen::inner_sequence(), std::tie( ts... ) );
}

#endif

public:
[[nodiscard]] auto connection() const noexcept -> const std::shared_ptr< pq::connection >&
{
Expand Down

0 comments on commit bbd855d

Please sign in to comment.