I have a database which has 4 types of indexes. Each index type has a sort order. That is, if you know the static index type, then there is one correct functor to use to sort the objects in that index, and it is also known as soon as you know the index type, i.e. statically at compile time.
The database has a function which contains a runtime switch statement to decide which index to talk to. I would like that function to return runtime information from the index (iterators, mostly), but also, the static order type to use.
To show the intention, here is some pseudo-code:
template <typename Iterator, typename Order>
struct LookupInfo {
typedef Order order;
uint64_t cost;
Iterator it1, it2, it3, it4;
};
LookupInfo Database::getLookupInfo(LookupData data)
{
if (data == ....) {
return LookupInfo<Iterator1, Order1>();
}
return LookupInfo<Iterator2, Order2>();
}
some_function(LookupInfo lookup_info) {
vector<Record> records(lookup_info.begin(), lookup_info.end());
sort(records.begin(), records.end(), lookup_info::order());
}
Is something like this at all possible?
Aucun commentaire:
Enregistrer un commentaire