I need to write a little function that makes a new std::set taking the last n elements from an existing one.
Here is the code:
template <typename S, typename T, typename Z>
std::set<T,S,Z> get_first_subset(std::set<T,S,Z> const& set, size_t size) {
if (size == 0)
return std::set<T,S,Z>();
typename std::set<T,S,Z>::reverse_iterator j = set.rbegin();
std::advance(j, size - 1);
return std::set<T,S,Z> ((++j).base(), set.end());
}
It works, however since I do not need to access the type T, S, and Z I was wondering if there is a way to simply say "any std::set" without three template parameters.