I have a container similar to the following:
class MySpecialContainer { std::vector<std::tuple<InternalType, Type1, Type2>> _vec; };
where Type1 and Type2 can be used outside the container, and InternalType used only inside the container. To iterate over elements from the outside, I use a member function similar to the following:
void MySpecialContainer::iterate(std::function<void(const Type1&, const Type2&)> fun) { for(auto& it : _vec) { fun(std::get<1>(it), std::get<2>(it)); } }
As you can see, this approach has several limitations, such as the inability to iterate over the subrange or the inability to use non mutating std::algorithms .
Given that the MySpecialContainer elements MySpecialContainer not change externally for logical reasons, does it make sense to provide only const_iterator for this?
If the answer, if yes for the first question, is it better ...?
divide _vec into 2 containers, one for InternalType and one for std::pair<Type1, Type2> , synchronize them and just return const_iterator for the second vector
save the vector as it is now and create a custom iterator that provides only const Type1 and const Type2
source share