From 8e69c9c459600901b998faee80edf654819e2b5b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Aug 2021 14:16:31 +0100 Subject: Simplify some bits with concepts --- lib/dbTypes.h | 3 +-- lib/helpers.h | 7 +++---- lib/input/mysqlBindings.h | 3 +-- lib/output/pq/pqBindings.h | 10 ++++------ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/dbTypes.h b/lib/dbTypes.h index 42b242b..31793e4 100644 --- a/lib/dbTypes.h +++ b/lib/dbTypes.h @@ -107,9 +107,8 @@ namespace MyGrate { return std::string {i}; } - template std::string - operator()(const I & i) const + operator()(const HasToString auto & i) const { return std::to_string(i); } diff --git a/lib/helpers.h b/lib/helpers.h index 5bf1bd8..f09a206 100644 --- a/lib/helpers.h +++ b/lib/helpers.h @@ -8,9 +8,8 @@ #include namespace MyGrate { - template constexpr inline auto - bitslice(const I i, uint8_t offset, uint8_t size) + bitslice(const std::integral auto i, uint8_t offset, uint8_t size) { return (i >> offset) & ((1U << size) - 1U); } @@ -25,9 +24,8 @@ namespace MyGrate { return expr; } - template constexpr inline auto - mod100_extract(T & i) + mod100_extract(std::integral auto & i) { const auto r {i % 100}; i /= 100; @@ -41,6 +39,7 @@ namespace MyGrate { std::to_string(a) } -> std::same_as; }; + template concept Viewable = requires(T a) { diff --git a/lib/input/mysqlBindings.h b/lib/input/mysqlBindings.h index ccf876e..3d1ad7f 100644 --- a/lib/input/mysqlBindings.h +++ b/lib/input/mysqlBindings.h @@ -58,9 +58,8 @@ namespace MyGrate::Input { b.buffer = nullptr; b.is_null = &data.emplace_back(0, 1).null; } - template void - operator()(const T &) + operator()(const auto &) { throw std::logic_error("Not implemented"); } diff --git a/lib/output/pq/pqBindings.h b/lib/output/pq/pqBindings.h index 2a4ac8c..329a2cf 100644 --- a/lib/output/pq/pqBindings.h +++ b/lib/output/pq/pqBindings.h @@ -2,6 +2,7 @@ #define MYGRATE_OUTPUT_PQ_PQBINDINGS #include +#include #include #include #include @@ -21,23 +22,20 @@ namespace MyGrate::Output::Pq { v.visit(*this); } } - template void - operator()(const T & v) + operator()(const Stringable auto & v) { addBuf(std::to_string(v)); } - template void - operator()(const T & v) + operator()(const Viewable auto & v) { values.emplace_back(v.data()); lengths.emplace_back(v.size()); formats.push_back(1); } - template void - operator()(const T & v) + operator()(const auto & v) { addBuf(scprintf<"%?">(v)); } -- cgit v1.2.3