ARTICLE AD BOX
The data Location that I need to organize is read by an external function which returns a std::vector of elements, location_data_. I organized the data in a std::map to facilitate fast access based on the Location::label field. I don't want to copy the location_data_ as the vector can be quite large. I want to make the Locations of a label accessible using the GetObjectsAtLocation() function.
What I am struggling with is the best return value of the GetObjectsAtLocation() function. I am using a const reference, but I am unsure if that is the correct choice. Any feedback is appreciated.
struct Location { std::string label; double x; double y; double yaw; }; class LocationDataBase { public: const std::vector<std::unique_ptr<Location>>& GetObjectsAtLocation( const std::string& object_label); private: std::vector<Location> location_data_; std::map<std::string, std::vector<std::unique_ptr<Location>>> objects_at_location_; };