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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:45:21+00:00 2026-06-07T05:45:21+00:00

Suppose I have something like this: class Collection { private: typedef std::vector< std::shared_ptr<Something> >::iterator

  • 0

Suppose I have something like this:

class Collection
{
private:
    typedef std::vector< std::shared_ptr<Something> >::iterator Iterator;
    std::vector< std::shared_ptr<Something> > data_;

public:
    Iterator begin() {return data_.begin()}
    Iterator end()  {return data_.end()}
}

When I use a Collection::Iterator instance I need to dereference it once, to get the std::shared_ptr<Something> object and once again to get Something object.

But if I want to make the std::shared_ptr<Something> just an implementation detail, it is reasonable that after one dereferencing, I should get a Something object.

That is:

Collection collection;
Collection::Iterator it = collection.begin();
Something firstMember = *it;  // instead of the current **it;

My question is, do I need to make the Iterator as a nested class of Collection from scratch and implement all the functions required for a random access iterator from here http://www.cplusplus.com/reference/std/iterator/ or is there some well known approach? Possibly C++11?

  • 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-07T05:45:22+00:00Added an answer on June 7, 2026 at 5:45 am

    It sounds like what you’re implementing exists and is called boost::ptr_vector. Boost also provides a library for implementing iterators with less pain. It sounds like what you’re looking for is boost::indirect_iterator

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

Sidebar

Related Questions

Suppose I have a class like this: class Foo { std::vector<int> bar; public: std::vector<int>&
Suppose I have something like this: class A { public B mem; public int
Suppose I have something like this: public abstract class AbstractDataObject { public abstract void
Suppose you have something like this: class intlist: def __init__(self,l = []): self.l =
Suppose I have something like this in my models.py: class Hipster(models.Model): name = CharField(max_length=50)
suppose i have a jax-rs resource class that looks like this: @Path(/nodes) public class
Suppose I have something like this page: <noscript>You need JS for this page</noscript> <script>
Suppose I have something like this: if ($command === 'txt') { header('Content-type: text/plain;charset=utf-8'); echo
I have a route that is suppose to match something like this localhost:3000/site/admin and
Suppose I have this model: public class ViewModel { [Required] public string UserInput {

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.