Assuming I have the following class
class Foo {
public:
// ...
private:
std::unordered_map<std::string, int> param1;
std::vector<int> param2;
// And other complex data types
};
and want to access the private members of its instance from external function, can I define a structure of constant references to pass them all at once, instead of creating a getter for each one and passing a "zoo" of parameters?
struct params_t {
const std::unordered_map<std::string, int> ¶m1;
const std::vector<int> ¶m2;
};
params_t Foo::get_params() { return params_t{param1, param2}; }
void bar()
{
// Initialize an instance of Foo
params_t params = foo.get_params();
// Do something with params
}
Is it considered a good practice? Because in my case, my needs are specific: I need all parameters at once and I need them often, so I aim for efficiency and low memory usage rather than code style.