假设我有一个对象的引用,我肯定知道它包含在向量中。是否可以从对象的地址在向量上创建迭代器?
template<typename T>
class Container {
public:
using iterator = std::vector<T>::iterator;
iterator get_iterator(T &t) {
// Realistically this would not be a public interface
// and I would guarantee t is in m_vec
return iterator(&t);
}
private:
std::vector<T> m_vec;
}
这可能并且定义明确吗?