From d62ca9f87906be6f046fe9d07afb8bfb69c166e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 16 Mar 2018 01:11:47 +0100 Subject: Use if constexpr to make things a lot more readable --- src/database/update_query.hpp | 51 +++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'src/database/update_query.hpp') diff --git a/src/database/update_query.hpp b/src/database/update_query.hpp index a29ac3f..0ee2bd9 100644 --- a/src/database/update_query.hpp +++ b/src/database/update_query.hpp @@ -39,27 +39,25 @@ struct UpdateQuery: public Query } template - typename std::enable_if::type - insert_col_name_and_value(const std::tuple& columns) + void insert_col_name_and_value(const std::tuple& columns) { - using ColumnType = std::decay_t(columns))>; - - if (!std::is_same::value) + if constexpr(N < sizeof...(T)) { - this->body += ColumnType::name + "=$"s + std::to_string(this->current_param); - this->current_param++; + using ColumnType = std::decay_t(columns))>; - if (N < (sizeof...(T) - 1)) - this->body += ", "; - } + if (!std::is_same::value) + { + this->body += ColumnType::name + "=$"s + + std::to_string(this->current_param); + this->current_param++; - this->insert_col_name_and_value(columns); - } - template - typename std::enable_if::type - insert_col_name_and_value(const std::tuple&) - {} + if (N < (sizeof...(T) - 1)) + this->body += ", "; + } + this->insert_col_name_and_value(columns); + } + } template void execute(DatabaseEngine& db, const std::tuple& columns) @@ -76,23 +74,20 @@ struct UpdateQuery: public Query } template - typename std::enable_if::type - bind_param(const std::tuple& columns, Statement& statement, int index=1) + void bind_param(const std::tuple& columns, Statement& statement, int index=1) { - auto&& column = std::get(columns); - using ColumnType = std::decay_t; + if constexpr(N < sizeof...(T)) + { + auto&& column = std::get(columns); + using ColumnType = std::decay_t; - if (!std::is_same::value) - actual_bind(statement, column.value, index++); + if (!std::is_same::value) + actual_bind(statement, column.value, index++); - this->bind_param(columns, statement, index); + this->bind_param(columns, statement, index); + } } - template - typename std::enable_if::type - bind_param(const std::tuple&, Statement&, int) - {} - template void bind_id(const std::tuple& columns, Statement& statement) { -- cgit v1.2.3