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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:51:53+00:00 2026-05-10T15:51:53+00:00

In C++, what alternatives do I have for exposing a collection, from the point

  • 0

In C++, what alternatives do I have for exposing a collection, from the point of view of performance and data integrity?

My problem is that I want to return an internal list of data to the caller, but I don’t want to generate a copy. Thant leaves me with either returning a reference to the list, or a pointer to the list. However, I’m not crazy about letting the caller change the data, I just want to let it read the data.

  • Do I have to choose between performance and data integrity?
  • If so, is in general better to go one way or is it particular to the case?
  • Are there other alternatives?
  • 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. 2026-05-10T15:51:53+00:00Added an answer on May 10, 2026 at 3:51 pm

    RichQ’s answer is a reasonable technique, if you’re using an array, vector, etc.

    If you’re using a collection that isn’t indexed by ordinal values… or think you might need to at some point in the near future… then you might want to consider exposing your own iterator type(s), and associated begin()/end() methods:

    class Blah { public:    typedef std::vector<mydata> mydata_collection;    typedef myDataCollection::const_iterator mydata_const_iterator;     // ...     mydata_const_iterator data_begin() const        { return myPreciousData.begin(); }    mydata_const_iterator data_end() const        { return myPreciousData.end(); }  private:    mydata_collection  myPreciousData; }; 

    …which you can then use in the normal fashion:

    Blah blah; for (Blah::mydata_const_iterator itr = blah.data_begin();    itr != blah.data_end();    ++itr) {    // ... } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What alternatives are there to GAE, given that I already have a good bit
I have a hashmap and an iterator that iterates through four alternatives and the
I have a website (ASP.net MVC2) where a database stores data/times of events. I
I have a tool strip which contains a ToolStripDropDownButton. As an alternative access method,
Are there any alternatives to The CMU Pronouncing Dictionary , commercial or open source?
Which of theese two alternatives do you find yourself using most often, and which
Consider the following two alternatives: console.log("double"); console.log('single'); The former uses double quotes around the
Are there any alternatives to JSTL? One company I worked for 3 years ago
What are some alternatives to make for linux/freebsd?
Are there any alternatives to IIS for Windows to run ASP.NET? CassiniEx seems pretty

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.