I'm looking for template code to sort template parameters, something like:
template <typename T, typename ... Args>
list<T> sort(T first, Args ... rest)
All the types in Args are actually T, but I need to use variadic templates, so that I can small compile time lists like:
sort(varA, varB, varC, varD).
(In fact, I plan on having an "all_different", which would sort and remove duplicates, to asses if the 4 values varA, varB, varC, varD are all different).
Anywhere where this kind would have been already written?
This is fairly straightforward to implement, assuming that you want to sort the function arguments. Just build a vector (or a
std::list
, if for whatever reason you want to use it) out of the arguments, and sort it.See this answer for an explanation of how
expander
works.You can abbreviate the "build the vector" part into:
but this incurs an additional copy per element (and doesn't work for move-only types) since you can't move from a
std::initializer_list
.