How do I acquire a const_iterator
from an iterator
in C++? What about a const_iterator
from an insert_iterator
? The resulting iterator
should point at the same spot as the original does.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Containers are required to provide
iterator
as a type convertible toconst_iterator
, so you can convert implicitly:std::insert_iterator
s are output iterators. This gives no way to convert them to a regularContainer::iterator
which must be a forward iterator.Another kind of insert iterator may allow such a thing, but those obtained from the standard functions don't.
I guess you can write your own wrapper around
std::insert_iterator
that exposes the protected memberiter
, though:You can convert them. Example:
But I guess that is not the answer you are seeking. Show me code. :-)