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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:41:06+00:00 2026-05-29T15:41:06+00:00

I have made a List of Lists implementation of a sparse matrix, and I’ve

  • 0

I have made a List of Lists implementation of a sparse matrix, and I’ve implemented iterator and const_iterator with success.

The iterator doesn’t point directly to the container where the value is stored, but creates a struct, named element, so defined:

template <typename T>
struct element{
 int i,j; //Coordinates
 T value;
};

But there’s one problem with the iterator: when I use it to edit the values in the struct, this should even affect the internal structure of the matrix.
I thought to store the original values in other private attributes of the iterator, then to compare them with the data stored into the struct: if something is different I’d call the methods of the matrix to edit the real internal structure.

The only thing I miss is: when is it the right moment to call this method inside iterator class?

  • 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-29T15:41:07+00:00Added an answer on May 29, 2026 at 3:41 pm

    The short answer, you should call this function as soon as *it is assigned to, where it is an iterator.

    I don’t think you have the right approach. Iterators in C++ can’t really cache changes, because there might be other iterators pointing at the same place in the container. Changes made via the iterator should affect the matrix immediately, and changes in the matrix should be visible via the iterator immediately. Here’s a test case:

    typedef whatever_type_you_like T; // maybe int
    
    matrix<T> mymatrix(5, 5);
    matrix<T>::iterator it1 = get_iterator_from(mymatrix, 2, 3);
    matrix<T>::iterator it2 = get_iterator_from(mymatrix, 2, 3);
    assert(it1 == it2);
    assert(*it1 == *it2);
    assert(*it1 == T());
    
    *it1 = T(1); // or some other constructor parameter
    assert(*it1 != T());
    assert(*it1 == T(1));
    assert(*it2 == T(1));
    assert(it1 == it2);
    assert(*it1 == *it2);
    assert(*it1 == mymatrix[2][3]); // or whatever syntax you have for matrix access
    
    *it2 = T(2);
    assert(*it1 != T(1));
    assert(*it1 == T(2));
    assert(*it2 == T(2));
    assert(it1 == it2);
    assert(*it1 == *it2);
    assert(*it2 == mymatrix[2][3]);
    
    mymatrix[2][3] = T(3);
    assert(*it2 != T(2));
    assert(*it2 == mymatrix[2][3]);
    

    So rather than element storing a copy of the value intended for the matrix, it should directly access the matrix, reading the value from there and storing the value there (and hence creating a real entry in the sparse matrix when required to store). Also, your element class should be convertible to T.

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

Sidebar

Related Questions

So I have a self-made double-linked-list implementation that is being used as a stand
I have made a list with few elements in it. Now everything looks right,
I have made a list view containing two childs. Now i am trying to
I have made a basic unordered list. <ul> <li><a>abc</a></li> <li><a>def</a></li> <li><a>ghi</a></li> <li><a>jkl</a></li> </ul> I
I have made a XML parser that list correctly in the UITableViewController. It passes
I have made a page in which i m using a list to display
I have made a drag-to-trigger_event page based on this guide . I'm displaying list
I have built a nav where I have an unordered list made up of
I have a Task list in Sharepoint 2007 SP2. For this list I made
I have several libraries made by myself (a geometry library, a linked list library,

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.