My_List will contain a lot more variables than just Node_List list_. There will be a Root_List* root_, Sync_List* link_, and unsigned int id_.
I have removed the majority of my code to keep it simple. Node_List list_ in the OP will actually be Root_List* root_ and the Node_List will actually be a std::list<Root_List::iterator>.
My_List is actually called Sync_List. Sync_Lists can be linked to other Sync_Lists via their copy ctor and assignment operator(shallow copies). Each call to push_back() and erase() will be synchronized. Ex:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include "Sync_List.h"
int main()
{
Sync_List<int> list1;
Sync_List<int> list2 = list1; //list2 synced with list1
Sync_List<int> list3;
list3 = list2; //list 3 synced with list 2 and list 1
list2.push_back(50);
list3.push_back(40);
list1.push_back(20);
std::cout << "list1: " << list1 << std::endl; //overloaded operator<<
std::cout << "list2: " << list2 << std::endl;
std::cout << "list3: " << list3 << std::endl;
return 0;
}
|
output
list1: 50 40 20
list2: 50 40 20
list3: 50 40 20
|
Some functions calls will affect all synced lists and others functions will only affect the list its being called by:
void push_back(T& _value); //synchronized
erase(iterator _e); //synchronized
remove(iterator _e); //non-synchronized
swap(iterator _e0, iterator _e1); //non-synchronized
duplicate(iterator _e, iterator _pos); //non-synchronized[/code]