Remove all the empty “options” members in Column classes

By using SFINAE to use that member only when it exists.
This commit is contained in:
louiz’
2017-07-08 12:36:08 +02:00
parent 870d462914
commit cf56b60fd3
2 changed files with 29 additions and 42 deletions
+12 -2
View File
@@ -28,6 +28,17 @@ void add_column_to_table(sqlite3* db, const std::string& table_name)
}
}
template <typename ColumnType, decltype(ColumnType::options) = nullptr>
void append_option(std::string& s)
{
s += " "s + ColumnType::options;
}
template <typename>
void append_option(...)
{ }
template <typename... T>
class Table
{
@@ -110,14 +121,13 @@ class Table
str += ColumnType::name;
str += " ";
str += TypeToSQLType<RealType>::type;
str += " "s + ColumnType::options;
append_option<ColumnType>(str);
if (N != sizeof...(T) - 1)
str += ",";
str += "\n";
add_column_create<N+1>(str);
}
template <std::size_t N=0>
typename std::enable_if<N == sizeof...(T), void>::type
add_column_create(std::string&)