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

  • SEARCH
  • Home
  • 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 8836143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:25:24+00:00 2026-06-14T09:25:24+00:00

Suppose I have a container with three iterators, it1 , it2 and it3 .

  • 0

Suppose I have a container with three iterators, it1, it2 and it3. Now I am using it1 and it2 to define a range, e.g. to pass to some std algorithm.

How do I find out, whether it3 lies within the range defined by it1 and it2?

I am aware of the brute force method of advancing a temporary iterator from it1 to it2 and checking against it3 at each step. Is there a quicker way?

The preferred solution would be in standard C++, without libraries such as boost.

edit: It is not given apriori that ìt3 acts on the same instance of a given container, for it1 and it2 that is always the case. So an additional qustion is: Is there a way to find out that two iterators belong to the same instance of a container?

  • 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-06-14T09:25:25+00:00Added an answer on June 14, 2026 at 9:25 am

    Random access iterators are comparable. Just do it1 < it3 && it2 > it3 – if they belong to the same collection.

    You get random access iterators on collections that support O(1) indexing, such as vector, deque, and array.

    edit: Checking if an interator belongs to a given collection is not obviously feasible, and this should be a whole different question. See this question for more details. (tl;dr: you can’t.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose I have a simple container which have three element: <div> <span>hello world</span> <input
Suppose I have a class encapsulating std container: class Stash { list<int> Data; public:
Suppose I have a div named container as shown <div id='container'>50</div> Now if I
Suppose I have an element called #container-main . How do I make that display:none
Suppose I have a li styled as follows: #app-container ul.apps li.app1 { border-color:#57b6dd; background:url(app-icons/app1.png)
suppose I have a panel with draggable element, and a droppable container,when I drag
Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
Suppose I have a function that does something on an arbitrary container type (C++11):
Suppose I have two or more different server applications developed in Clojure using ZeroMQ
Suppose I have two containers of elements: std::vector<std::string> foo = { aa, bb, cc

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.