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 7536237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:31:11+00:00 2026-05-30T06:31:11+00:00

I would like to code a method capable of returning a range of iterators

  • 0

I would like to code a method capable of returning a range of iterators to represent a subset of a bigger list.

Can such “subset” not have being made of contiguous objects ?

For example, if I have a std::list with n objects.

eg.

| object1 | object2 | object3 | object4 | ... | objectn

Can I return a range of iterators (a pair of begin / end we can call ItBegin and ItEnd) which would include only Object 1,3 and 4 ?

eg.

| object1 | object2 | object3 | object4 | ... | objectN
     ^                   ^         ^                      ^
     |                   |         |                      |
   ItBegin           ++ItBegin ++ItBegin                ItEnd

Is that possible or do I need to copy the objects (or use pointers to avoid the copy) onto a new list and return that list ?

Please note that the iterator(s) subset would just be used for reading. (a pair of const_iterator would do the job)

Thanks!
Giacomo

  • 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-30T06:31:12+00:00Added an answer on May 30, 2026 at 6:31 am

    If you don’t mind using Boost, you could use filter_iterator, e.g.

    struct ShouldIncludeChecker
    {
        bool operator()(const Object& obj) const
        {
           return obj == object1 || obj == object3 || obj == object4;
           // ^ Customize this to fit your need.
        }
    };
    
    typedef boost::filter_iterator<ShouldIncludeChecker, std::list<Object>::iterator>
            filter_iterator;
    
    ShouldIncludeChecker checker;
    std::list<Object>::iterator old_begin = the_list.begin();
    std::list<Object>::iterator old_end = the_list.end();
    filter_iterator new_begin (checker, old_begin, old_end);
    filter_iterator new_end (checker, old_end, old_end);
    
    for (filter_iterator it = new_begin; it != new_end; ++ it)
    {
       // read *it
    }
    

    Also, if the thing you are reading to can be made into an output iterator, you could just use std::remove_copy_if.

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

Sidebar

Related Questions

I would like to know whether I can get source code a method on
I have a static method in my code that I would like somehow to
I have VB.NET code in Visual Studio 2008 using an obsolete method and would like to
I would like to code a proxy that forwards method invocations to another object
I would like a code sample for a function that takes a tDateTime and
I would like to be able to do something like (psuedo-code): if (classAvailable) {
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
To help users, I would like my code to discover Oracle databases on the
I'm searching for the cleanest solution here. I would like to code a stored
Problem: I would like to share code between multiple assemblies. This shared code will

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.