0

Currently, I have a vector of maps that contain strings as keys and size_t as a count which was useful to have as size_t before.

example of current vector:

(std::vector<std::map<std::string, size_t>> allFiles;)

Now I need to multiply those counts by numbers that contain decimals/doubles and store them. What would be the best and most efficient way to do this?

example of necessary vector:

(std::vector<std::map<std::string,double>> simMaps;)

Unfortunately for other reasons, I am hamstrung into only using the stdlib.

Ideally, I would not have to make a new vector of maps, as the keys are in the hundreds of thousands. However, I know that otherwise I would have to go through my whole program to change those to and hopefully no obscure errors pop up.

Any Ideas?

nomim
  • 51
  • 6
  • I'm not quite sure what you are asking. Are you perhaps just looking for `static_cast` somewhere? Btw; what's the problem with just changing the type of the existing containers? Most IDE's have refactoring tools that will do that in a second. Even a simple `perl -p -i -e` oneliner will do it from the commandline - doing that should be trivial.... – Jesper Juhl Oct 24 '17 at 21:52
  • Basically, I have a program with many classes that interact with each other. When I change the data type of the container the compiler throws a ton of errors. Not quite sure how to use perl but how would I refactor that with something like CLion? My program stores them as size_t and i want to multiply it but keep the datastructure without having to copy it. – nomim Oct 24 '17 at 21:59
  • 1
    If nothing else you've probably just learned the value of `typedef` and `auto`, since changing the type would've been trivial. Assuming you don't want to lose precision (i.e. you need the decimals) there isn't any great efficient way you can do this without changing the type or making a new container. I suggest just changing the type – Tas Oct 25 '17 at 00:04

0 Answers0