Hello. I am in the middle of writing a series of classes to compute pretty much anything (distances, temperatures, times, speeds, etc.). My approach consists of a base Unit class where all units of measurement derive from. For higher level "dimensions" as I call them, the units can be the product of two or more simple units. I call this a CompoundUnit class. Each unit class knows its own conversion factor, so a compound unit can calculate the compound conversion factor from the conversion factors that compose it.
So there is a vector containing the unit object and the exponent the unit is raised to. I just need to for_each(). I have never coded a functor before, so here it is my first one. The thing is, I am unsure if I did it right. I am still writing other stuff and I am nowhere near compilation time. May I ask that you check it for me and let me know if I did it right?
Ok, so no worries anymore. Today I was able to compile and perform a quick test. The functor object is copied when for_each() is called and then copied again in the return value of for_each(). :-( This means I had to change the code so I could intercept the return value to be able to get the conversion factor out of the functor.
Or, I could make it use an external variable by reference. But this is good for now.