C++: correct way to have heterogenous containers
I am currently working on a basic language parser. For the tokenization process, the tokens can be of different types. So I need a heterogenous container to hold those tokens. 1. What to choose - std::variant or base class pointers? From this thread on StackOverflow, https://stackoverflow.com/questions/59784261/stdvariant-vs-pointer-to-base-class-for-heterogeneous-containers-in-c I found that the main argument against using base class pointers is doing dynamic memory allocations and handling their pointers. But in my case, I'll need to put the tokens on the heap anyways because the nunber of tokens can be huge and putting them on the stack can lead to problems. So in my particular case, which way is better? [point no. 2 as answer in thread because I'm reaching character limit]