Commit 5834dd53 authored by louiz’'s avatar louiz’

Add a 0 default value for template argument N

parent 49bb28c6
...@@ -53,13 +53,13 @@ struct InsertQuery: public Query ...@@ -53,13 +53,13 @@ struct InsertQuery: public Query
{ {
auto statement = this->prepare(db); auto statement = this->prepare(db);
{ {
this->bind_param<0>(columns, statement); this->bind_param(columns, statement);
if (sqlite3_step(statement.get()) != SQLITE_DONE) if (sqlite3_step(statement.get()) != SQLITE_DONE)
log_error("Failed to execute query: ", sqlite3_errmsg(db)); log_error("Failed to execute query: ", sqlite3_errmsg(db));
} }
} }
template <int N, typename... T> template <int N=0, typename... T>
typename std::enable_if<N < sizeof...(T), void>::type typename std::enable_if<N < sizeof...(T), void>::type
bind_param(const std::tuple<T...>& columns, Statement& statement) bind_param(const std::tuple<T...>& columns, Statement& statement)
{ {
...@@ -69,7 +69,7 @@ struct InsertQuery: public Query ...@@ -69,7 +69,7 @@ struct InsertQuery: public Query
this->bind_param<N+1>(columns, statement); this->bind_param<N+1>(columns, statement);
} }
template <int N, typename... T> template <int N=0, typename... T>
typename std::enable_if<N == sizeof...(T), void>::type typename std::enable_if<N == sizeof...(T), void>::type
bind_param(const std::tuple<T...>&, Statement&) bind_param(const std::tuple<T...>&, Statement&)
{} {}
...@@ -78,11 +78,11 @@ struct InsertQuery: public Query ...@@ -78,11 +78,11 @@ struct InsertQuery: public Query
void insert_values(const std::tuple<T...>& columns) void insert_values(const std::tuple<T...>& columns)
{ {
this->body += "VALUES ("; this->body += "VALUES (";
this->insert_value<0>(columns); this->insert_value(columns);
this->body += ")"; this->body += ")";
} }
template <int N, typename... T> template <int N=0, typename... T>
typename std::enable_if<N < sizeof...(T), void>::type typename std::enable_if<N < sizeof...(T), void>::type
insert_value(const std::tuple<T...>& columns) insert_value(const std::tuple<T...>& columns)
{ {
...@@ -93,7 +93,7 @@ struct InsertQuery: public Query ...@@ -93,7 +93,7 @@ struct InsertQuery: public Query
add_param(*this, std::get<N>(columns)); add_param(*this, std::get<N>(columns));
this->insert_value<N+1>(columns); this->insert_value<N+1>(columns);
} }
template <int N, typename... T> template <int N=0, typename... T>
typename std::enable_if<N == sizeof...(T), void>::type typename std::enable_if<N == sizeof...(T), void>::type
insert_value(const std::tuple<T...>&) insert_value(const std::tuple<T...>&)
{ } { }
...@@ -102,11 +102,11 @@ struct InsertQuery: public Query ...@@ -102,11 +102,11 @@ struct InsertQuery: public Query
void insert_col_names(const std::tuple<T...>& columns) void insert_col_names(const std::tuple<T...>& columns)
{ {
this->body += " ("; this->body += " (";
this->insert_col_name<0>(columns); this->insert_col_name(columns);
this->body += ")\n"; this->body += ")\n";
} }
template <int N, typename... T> template <int N=0, typename... T>
typename std::enable_if<N < sizeof...(T), void>::type typename std::enable_if<N < sizeof...(T), void>::type
insert_col_name(const std::tuple<T...>& columns) insert_col_name(const std::tuple<T...>& columns)
{ {
...@@ -119,7 +119,7 @@ struct InsertQuery: public Query ...@@ -119,7 +119,7 @@ struct InsertQuery: public Query
this->insert_col_name<N+1>(columns); this->insert_col_name<N+1>(columns);
} }
template <int N, typename... T> template <int N=0, typename... T>
typename std::enable_if<N == sizeof...(T), void>::type typename std::enable_if<N == sizeof...(T), void>::type
insert_col_name(const std::tuple<T...>&) insert_col_name(const std::tuple<T...>&)
{} {}
......
...@@ -23,7 +23,7 @@ update_id(std::tuple<T...>& columns, sqlite3* db) ...@@ -23,7 +23,7 @@ update_id(std::tuple<T...>& columns, sqlite3* db)
column.value = static_cast<Id::real_type>(res); column.value = static_cast<Id::real_type>(res);
} }
template <std::size_t N, typename... T> template <std::size_t N=0, typename... T>
typename std::enable_if<N < sizeof...(T), void>::type typename std::enable_if<N < sizeof...(T), void>::type
update_autoincrement_id(std::tuple<T...>& columns, sqlite3* db) update_autoincrement_id(std::tuple<T...>& columns, sqlite3* db)
{ {
...@@ -32,7 +32,7 @@ update_autoincrement_id(std::tuple<T...>& columns, sqlite3* db) ...@@ -32,7 +32,7 @@ update_autoincrement_id(std::tuple<T...>& columns, sqlite3* db)
update_autoincrement_id<N+1>(columns, db); update_autoincrement_id<N+1>(columns, db);
} }
template <std::size_t N, typename... T> template <std::size_t N=0, typename... T>
typename std::enable_if<N == sizeof...(T), void>::type typename std::enable_if<N == sizeof...(T), void>::type
update_autoincrement_id(std::tuple<T...>&, sqlite3*) update_autoincrement_id(std::tuple<T...>&, sqlite3*)
{} {}
...@@ -67,7 +67,7 @@ struct Row ...@@ -67,7 +67,7 @@ struct Row
query.execute(this->columns, db); query.execute(this->columns, db);
update_autoincrement_id<0>(this->columns, db); update_autoincrement_id(this->columns, db);
} }
std::tuple<T...> columns; std::tuple<T...> columns;
......
...@@ -53,11 +53,11 @@ struct SelectQuery: public Query ...@@ -53,11 +53,11 @@ struct SelectQuery: public Query
Query("SELECT"), Query("SELECT"),
table_name(table_name) table_name(table_name)
{ {
this->insert_col_name<0>(); this->insert_col_name();
this->body += " from " + this->table_name; this->body += " from " + this->table_name;
} }
template <std::size_t N> template <std::size_t N=0>
typename std::enable_if<N < sizeof...(T), void>::type typename std::enable_if<N < sizeof...(T), void>::type
insert_col_name() insert_col_name()
{ {
...@@ -71,7 +71,7 @@ struct SelectQuery: public Query ...@@ -71,7 +71,7 @@ struct SelectQuery: public Query
this->insert_col_name<N+1>(); this->insert_col_name<N+1>();
} }
template <std::size_t N> template <std::size_t N=0>
typename std::enable_if<N == sizeof...(T), void>::type typename std::enable_if<N == sizeof...(T), void>::type
insert_col_name() insert_col_name()
{} {}
......
...@@ -26,7 +26,7 @@ class Table ...@@ -26,7 +26,7 @@ class Table
std::string res{"CREATE TABLE IF NOT EXISTS "}; std::string res{"CREATE TABLE IF NOT EXISTS "};
res += this->name; res += this->name;
res += " (\n"; res += " (\n";
this->add_column_create<0>(res); this->add_column_create(res);
res += ")"; res += ")";
log_debug(res); log_debug(res);
...@@ -58,7 +58,7 @@ class Table ...@@ -58,7 +58,7 @@ class Table
} }
private: private:
template <std::size_t N> template <std::size_t N=0>
typename std::enable_if<N < sizeof...(T), void>::type typename std::enable_if<N < sizeof...(T), void>::type
add_column_create(std::string& str) add_column_create(std::string& str)
{ {
...@@ -75,7 +75,7 @@ class Table ...@@ -75,7 +75,7 @@ class Table
add_column_create<N+1>(str); add_column_create<N+1>(str);
} }
template <std::size_t N> template <std::size_t N=0>
typename std::enable_if<N == sizeof...(T), void>::type typename std::enable_if<N == sizeof...(T), void>::type
add_column_create(std::string&) add_column_create(std::string&)
{ } { }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment