How to specify more than one field as a variadic template function?

The following code:

1
2
3
4
5
6
7
8
9
template <class C, class D>
std::vector<Model::Category> getCategoriesSortedBy( D C::* field)
{
	using namespace sqlite_orm;
	using namespace Model;

	auto collection = ORM::Storage::getStorage().get_all<Model::Category>(order_by(field));
	return collection;
}


allows me to sort by one field at a time. How can I change this to a variadic template function so I can sort by more than one field at a time?


Thanks,
Juan
You're not using C or D in your function template, so just ignore them!

1
2
3
4
5
template <typename... Ts>
std::vector<Model::Category> getCategoriesSortedBy(Ts... fields)
{
  	// e.g. ORM::Storage::getStorage().get_all<Model::Category>(order_by(fields)...);
}
Last edited on
The problem here is the result 'collection'. Does get_all<...>(...) support multiple fields (like mbozzi assumed) or not?
template<typename ...Ts>
std::vector<Model::Category> getCategoriesSortedBy( Ts ... fields)
{
using namespace sqlite_orm;
using namespace Model;

auto collection = ORM::Storage::getStorage().get_all<Model::Category>(multi_order_by(order_by(fields)...));
return collection;
}
Topic archived. No new replies allowed.