Suppose I have a templated function which has a parameter used as an iterator (albeit without any concepts/requirements - C++17 or earlier), named my_iter
.
Can I generically ensure that iterator is a const iterator, or get a const iterator to the same position?
Note: Unlike in this question, which concerns an iterator
vs a const_iterator
of some assumed-known container class, here we don't know what that container class is, if it exists at all. Thus I don't want to write something like:
auto it = std::cbegin(my_container);
auto desired_iter = it + distance(it, my_iter);
as suggested in this method, nor even:
auto desired_iter = ContainerType::const_iterator(my_iter);