From b7d3b265af36ea309483678aa57e0cd30026aa29 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Oct 2023 16:21:00 +0100 Subject: Make pq_deleter a generic helper --- libpqpp/pq-column.h | 11 ++--------- libpqpp/pq-helpers.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 libpqpp/pq-helpers.h (limited to 'libpqpp') diff --git a/libpqpp/pq-column.h b/libpqpp/pq-column.h index d3400bf..6bf2669 100644 --- a/libpqpp/pq-column.h +++ b/libpqpp/pq-column.h @@ -1,6 +1,7 @@ #ifndef PG_COLUMN_H #define PG_COLUMN_H +#include "pq-helpers.h" #include #include #include @@ -32,15 +33,7 @@ namespace PQ { const Oid oid; // Buffer for PQunescapeBytea - struct pq_deleter { - void - operator()(unsigned char * p) - { - PQfreemem(p); - } - }; - - using BufPtr = std::unique_ptr; + using BufPtr = std::unique_ptr>; mutable BufPtr buf; }; } diff --git a/libpqpp/pq-helpers.h b/libpqpp/pq-helpers.h new file mode 100644 index 0000000..76e5057 --- /dev/null +++ b/libpqpp/pq-helpers.h @@ -0,0 +1,14 @@ +#ifndef PQ_HELPERS_H +#define PQ_HELPERS_H + +namespace PQ { + template struct pq_deleter { + void + operator()(auto p) const + { + func(p); + } + }; +} + +#endif -- cgit v1.2.3