dimanche 31 octobre 2021

Creating an object without its known type

I was wondering how can I create an object if type of this object is stored in a string. My goal is to optimise it as good as it's possible, this algorithm will be iterated many times. I know 3 possible solutions:

  1. Creating a list (vector?) of possible classes and iterating over all possible variants (slow as hell if i have >10 possible classes)
  2. std::map approach (creating a map and checking all of it) (performance not checked)
  3. Using Boost::PFR (kind of "reflection" library for C++) (performance also not known)

Do you know which approach would be the best and fastest options? And how to implement that? Sincerely, Karol





Aucun commentaire:

Enregistrer un commentaire