I have multiple containers with the same element type T. I would like to select one of the containers depending on a enum.
I tried something like this:
auto range = [category,system]() -> auto { switch(category) { case sound_category::voice: return std::ranges::views::all (system->dialogue_voices); // could be std::array case sound_category::mono: return std::ranges::views::all (system->mono_voices); // could be std::vector case sound_category::music: return std::ranges::views::all (system->music_voices); // could be std::list default: return std::ranges::views::all (system->sfx_voices); // could be std::deque } }(); but that will result in a compiler error, since the deduced type in the cases is different.
Is there some way to achieve that?
std::spanof the array you want?std::spanis the way to go. Changing the return type of the lambda tostd::span<T>and returnstd::span(system->...)should work for the purpose.