#Infinite template instantiation

17 messages · Page 1 of 1 (latest)

weak scaffoldBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

glass gulch
#

can you show more of the code

#

I'm not quite sure what the function template even is and why it would be instantiated recursively with different types

#

hmm, any reason why you're not using std::nth_element?

#

because yeah, you're going one layer deeper on the medians each iteration and there is nothing actually stopping it

#

it most likely is implemented using Quickselect under the hood https://en.wikipedia.org/wiki/Quickselect

In computer science, quickselect is a selection algorithm to find the kth smallest element in an unordered list, also known as the kth order statistic. Like the related quicksort sorting algorithm, it was developed by Tony Hoare, and thus is also known as Hoare's selection algorithm. Like quicksort, it is efficient in practice and has good avera...

#

I don't think you can do it with the same complexity without modifying the original array

#

you would need additional memory, like a fixed size priority queue

golden mason
#

I think kthSmallest(medians.begin(), medians.end(), might be killing it?

#

you're storing a vector of iterators

#

so then your iterator is an iterator of iterators

#

and then the next instantiation its an iterator of iterators of iterators

#

etc

#

every function is slightly different (and more nested templates so the error message is going to be a mess)

#

Perhaps creating a wrapper function instead which creates you iterators array and then doing all work on that in a separate function so you arent nesting this way would be perferrable?

weak scaffoldBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

weak scaffoldBOT
#

This question thread is being automatically marked as stale.