Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:51:36+00:00 2026-05-26T04:51:36+00:00

How do I acquire a const_iterator (of some container class) from an iterator (of

  • 0

How do I acquire a const_iterator (of some container class) from an iterator (of that container class) in C++? What about a const_iterator from an insert_iterator? The resulting iterator should point at the same spot as the original does.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:51:37+00:00Added an answer on May 26, 2026 at 4:51 am

    Containers are required to provide iterator as a type convertible to const_iterator, so you can convert implicitly:

    Container::iterator it = /* blah */;
    Container::const_iterator cit = it;
    

    std::insert_iterators are output iterators. This gives no way to convert them to a regular Container::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 member iter, though:

    template <typename Container>
    class exposing_insert_iterator : public std::insert_iterator<Container> {
    public:
        exposing_insert_iterator(std::insert_iterator<Container> it)
        : std::insert_iterator<Container>(it) {}
        typename Container::iterator get_iterator() const {
            return std::insert_iterator<Container>::iter;
        }
    };
    
    // ...
    std::insert_iterator<Container> ins_it;
    exposing_insert_iterator<Container> exp_it = ins_it;
    Container::iterator it = exp_it.get_iterator();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to acquire single images from a camera, do some processing to
I need to acquire some data from a questions table and then LEFT JOIN
I'm writing some code to acquire images that live on a server. The image
Let's say i acquire the name of a class that i made as a
I have a device to acquire XRay images. Due to some technical constrains, the
I'm using WIA to acquire images from a scanner with C#. I can scan
I have a GPS class which i obviously use to acquire the latitudes and
Is it necessary to acquire a lock on a variable before reading it from
I've got an abstract base class that defines an interface to data sinks. Concrete
I have several threads that acquire Mutexes and then terminate. The mutexes are stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.