class DatabaseImpl {
public:
template<typename Table>
- std::string getTableName(Table) const noexcept { return std::string(); }
+ std::string getTableName(Table&&) const noexcept { return std::string(); }
template<typename Column>
- std::string getColumnName(Column column) const noexcept { return std::string(); }
+ std::string getColumnName(Column&&) const noexcept { return std::string(); }
};
template<typename Front, typename... Rest>
public:
using Table = Front;
- DatabaseImpl(Front front, Rest ...rest) : Base(rest...), table(front) {}
+ DatabaseImpl(Front&& front, Rest&& ...rest) :
+ Base(std::forward<Rest>(rest)...), table(front) {}
Table table;
template<typename Table>
- std::string getTableName(Table table) const noexcept
+ std::string getTableName(Table&& table) const noexcept
{
- if (this->table.find(table))
+ if (this->table.compare(table))
return this->table.name;
- return Base::template getTableName<Table>(table);
+ return Base::template getTableName<Table>(std::forward<Table>(table));
}
template<typename Column>
- std::string getColumnName(Column column) const noexcept
+ std::string getColumnName(Column&& column) const noexcept
{
- using TableType = typename decltype(column)::TableType;
- if (this->table.find(TableType())) {
+ using ColumnType = typename std::decay<Column>::type;
+ using TableType = typename ColumnType::TableType;
+ if (this->table.compare(TableType())) {
auto cname = this->table.getColumnName(column.type);
return this->table.name + "." + cname;
}
- return Base::template getColumnName<Column>(column);
+ return Base::template getColumnName<Column>(std::forward<Column>(column));
}
private:
using ColumnNames = std::vector<std::string>;
using TableNames = std::set<std::string>;
- explicit Database(const std::string& name, ImplType impl);
+ explicit Database(const std::string& name, ImplType&& impl);
template<typename ...Ts>
friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
}
template<typename ...Tables>
-Database<Tables...>::Database(const std::string& name, ImplType impl)
- : name(name), impl(impl) {}
+Database<Tables...>::Database(const std::string& name, ImplType&& impl)
+ : name(name), impl(std::move(impl)) {}
template<typename... Tables>
template<typename... ColumnTypes>
std::vector<std::string> getColumnNames() const noexcept { return {}; }
template<class Type>
- std::string getColumnName(Type type) const noexcept { return std::string(); }
+ std::string getColumnName(Type&&) const noexcept { return std::string(); }
int size() const noexcept { return 0; }
};
using Column = Front;
using TableType = typename Column::TableType;
- explicit TableImpl(Front front, Rest ...rest) : Base(rest...), column(front) {}
+ explicit TableImpl(Front&& front, Rest&& ...rest) :
+ Base(std::forward<Rest>(rest)...), column(front) {}
int size() const noexcept { return Base::size() + 1; }
}
template<typename ColumnType>
- std::string getColumnName(ColumnType type) const noexcept
+ std::string getColumnName(ColumnType&& type) const noexcept
{
- if (type::cast_compare(column.type, type))
+ if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
return column.name;
- return Base::template getColumnName<ColumnType>(type);
+ return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(type));
}
private:
template<typename Expr>
Self where(Expr expr);
- template<typename Column>
- bool find(Column column);
+ template<typename That>
+ bool compare(const That& that) const noexcept;
operator std::string();
std::string name;
private:
- explicit Table(const std::string& name, ImplType impl);
+ explicit Table(const std::string& name, ImplType&& impl);
template<typename ...Cs>
friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
}
template<typename... Columns>
-Table<Columns...>::Table(const std::string& name, ImplType impl)
- : name(name), impl(impl) {}
+Table<Columns...>::Table(const std::string& name, ImplType&& impl)
+ : name(name), impl(std::move(impl)) {}
template<typename... Columns>
template<typename... ColumnTypes>
template<typename... Columns>
template<typename That>
-bool Table<Columns...>::find(That that)
+bool Table<Columns...>::compare(const That& that) const noexcept
{
using This = TableType;
- return type::compare(This(), That());
+ return type::compare(This(), that);
}
template<typename... Columns>