I have a factory for creating containers based on ugly containers
template<class T>
std::vector<T> containerFactory(const UglyContainer* uglyContainer)
{
std::vector<T> container(uglyContainer->count);
Getter getter;
for(unsigned int i=0;i<uglyContainer->count;++i)
{
getter(container[i], uglyContainer->values[i]);
}
return container;
}
How might I go about complementing containerFactory with a factory function which returns const std::vector?
Const on the returned vector is irrelevant. Since it is returned by value, it will be copied and const will apply to the usage of the copy.
Since you are creating the vector on the stack in the factory method, you cannot return the vector by reference.
As a matter of robustness of the container Factory, you might consider taking a vector as an argument to the factory method and appending to it to avoid the copy of the vector.