i need map values ranging between lowerbound , upperbound value. illustrative example: for example, imagine have gps system has users subscribed it. system able provide me distance of user point. based on distance of user want assign them id. thus users in distance 1 100 id: 8.4 101 200 id: 7.2 201 300 id: 3.6 401 600 id: 4.1 and on... my approach: so did, created std::map initializing follows: std::map<int, double> distancetoidmap; distancetoidmap = { {100, 8.4}, {200, 7.2}, {300, 3.6}, }; then use code id given distance: double rounduptohundred = std::ceil(realdistance / 100.0) * 100; double powerfordistance = distancetoidmap.at(rounduptohundred); however approach breaks down 401 600 distance, because ceiling nearest hundred distance of 400+ value 500 don't have entry in map. of course trivial solution add entry 500 distancetoidmap not how want handle problem. i have map ...
Comments
Post a Comment