From d0e3c71b91f1a1c1780158789fd42b8ac7209495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 17 Mar 2018 17:28:41 +0100 Subject: Revert "Use if constexpr to make things a lot more readable" This reverts commit d62ca9f87906be6f046fe9d07afb8bfb69c166e3. --- src/database/row.hpp | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) (limited to 'src/database/row.hpp') diff --git a/src/database/row.hpp b/src/database/row.hpp index 194a9c5..3703ff7 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -29,39 +29,41 @@ struct Row return col.value; } - void save(std::unique_ptr& db) + template + void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) { - if constexpr(is_one_of) + this->insert(*db); + } + + template + void save(std::unique_ptr& db, typename std::enable_if && Coucou>::type* = nullptr) + { + const Id& id = std::get(this->columns); + if (id.value == Id::unset_value) { - const Id& id = std::get(this->columns); - if (id.value == Id::unset_value) - { - this->insert(*db); - if (db->last_inserted_rowid >= 0) - std::get(this->columns).value = static_cast(db->last_inserted_rowid); - } - else - this->update(*db); + this->insert(*db); + if (db->last_inserted_rowid >= 0) + std::get(this->columns).value = static_cast(db->last_inserted_rowid); } else - this->insert(*db); + this->update(*db); } private: - void insert(DatabaseEngine& db) + template + void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) { - if constexpr(is_one_of) - { - InsertQuery query(this->table_name, this->columns); - // Ugly workaround for non portable stuff - query.body += db.get_returning_id_sql_string(Id::name); - query.execute(db, this->columns); - } - else - { - InsertQuery query(this->table_name, this->columns); - query.execute(db, this->columns); - } + InsertQuery query(this->table_name, this->columns); + // Ugly workaround for non portable stuff + query.body += db.get_returning_id_sql_string(Id::name); + query.execute(db, this->columns); + } + + template + void insert(DatabaseEngine& db, typename std::enable_if && Coucou>::type* = nullptr) + { + InsertQuery query(this->table_name, this->columns); + query.execute(db, this->columns); } void update(DatabaseEngine& db) -- cgit v1.2.3