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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:17:54+00:00 2026-05-11T18:17:54+00:00

I have a class TContainer that is an aggregate of several stl collections pointers

  • 0

I have a class TContainer that is an aggregate of several stl collections pointers to TItems class.

I need to create an Iterator to traverse the elements in all the collections in my TContainer class abstracting the client of the inner workings.

What would be a good way to do this?. Should I crate a class that extends an iterator (if so, what iterator class should I extend), should I create an iterator class that is an aggregate of iterators?

I only need a FORWARD_ONLY iterator.

I.E, If this is my container:

typedef std::vector <TItem*> ItemVector;
class TContainer {
   std::vector <ItemVector *> m_Items;
};

What would be a good Iterator to traverse all the items contained in the vectors of the m_Items member variable.

  • 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-11T18:17:54+00:00Added an answer on May 11, 2026 at 6:17 pm

    When I did my own iterator (a while ago now) I inherited from std::iterator and specified the type as the first template parameter. Hope that helps.

    For forward iterators user forward_iterator_tag rather than input_iterator_tag in the following code.

    This class was originally taken from istream_iterator class (and modified for my own use so it may not resemble the istram_iterator any more).

    template<typename T>
    class <PLOP>_iterator
             :public std::iterator<std::input_iterator_tag,       // type of iterator
                                   T,ptrdiff_t,const T*,const T&> // Info about iterator
    {
        public:
            const T& operator*() const;
            const T* operator->() const;
            <PLOP>__iterator& operator++();
            <PLOP>__iterator operator++(int);
            bool equal(<PLOP>__iterator const& rhs) const;
    };
    
    template<typename T>
    inline bool operator==(<PLOP>__iterator<T> const& lhs,<PLOP>__iterator<T> const& rhs)
    {
        return lhs.equal(rhs);
    }
    

    Check this documentation on iterator tags:
    http://www.sgi.com/tech/stl/iterator_tags.html

    Having just re-read the information on iterators:
    http://www.sgi.com/tech/stl/iterator_traits.html

    This is the old way of doing things (iterator_tags) the more modern approach is to set up iterator_traits<> for your iterator to make it fully compatible with the STL.

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

Sidebar

Related Questions

I have code that looks like this: class T {}; class container { const
I have a dynamic class that serves as a storage container for configuration settings.
In Java, assume I have the following class Container that contains a list of
I have a container class that has a generic parameter which is constrained to
I'm tying to create a class that holds a reference to another classes method.
I have a DIV container that is a CSS class defined on the top
I have an interface and a couple of implementations of a class that stores
I have a C++ class Finder that stores a location in containers plus some
I have a class CContainer that has some members CMemberX , CMemberY , which
I have class foo that contains a std::auto_ptr member that I would like to

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.