[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [csmith-dev] vector<Variable*> and vector<const Variable*>
> Ideally we should use vector<const Variable*> *unless* we expect the Variable object in the vector to be modified. I remember we have to overload some functions with parameters of both 'vector<Variable*>' type and 'vector<const Variable*>' to please the compilers, e.g., MSVC and g++.
>
> Feel free to remove some of the awkwardness if you can keep the compilers pleased. Maybe they have become smarter over the last few years.
I don’t think there is much choice for any correct C++ compiler because 'vector<Variable*>’ and 'vector<const Variable*>’
are different, albeit related, types.
I understand the desire to not allow mutating access to the list of variables.
However, couldn’t this be achieved by a bit more abstraction, e.g., encapsulating 'vector<Variable*>’ in a class and provide
non-mutating and (if necessary) mutating access to it?
Something along the lines of
class VariableList
{
private:
std::vector<Variable*> vars;
public:
size_t size() const { return vars.size(); }
const Variable& operator[](size_t i) const { return *vars[i]; }
Variable& operator[](size_t i) { return *vars[i]; }
// ….
};
Regards
Jens