I need to design a container similar to a std::set, but where the
stored objects may be modified via a non-const iterator. In some
cases the modification will effect the sort order.
Here's an example:
class Object { // an object from the database };
class Sorter { // functor that determines sort order for Objects };
template <class Obj, class Sort> class Set {};
Set<Object, Sorter> query;
Set<Object, Sorter>::Iterat or it(query.begin( ));
while (it != query.end())
{
it->modify(); // uh oh, Set<> may be invalid now
}
In addition to this basic concept, is there a way to design Set<> so
that it automagically knows when a contained object has been changed
in a way that requires the set to be resorted? 4 1349
"Michael Klatt" <md*****@ou.edu > wrote in message news:2c******** *************** ***@posting.goo gle.com... In addition to this basic concept, is there a way to design Set<> so that it automagically knows when a contained object has been changed in a way that requires the set to be resorted?
There's no way to tell. A container can't tell an arbitrary internal object has been
changed. There's nothing that says you can't get a reference or pointer to an
object from an iterator and release, increment, or otherwise destroy the interator.
On 18 Jan 2004 15:15:41 -0800 in comp.lang.c++, md*****@ou.edu (Michael
Klatt) was alleged to have written: I need to design a container similar to a std::set, but where the stored objects may be modified via a non-const iterator. In some cases the modification will effect the sort order.
My approach would be to use a std::set, and whenever you modify a stored
object you obtain a copy, erase the stored object, modify the copy, and
insert it back in the set. Encapsulate in a suitable class wrapper.
Michael Klatt wrote: I need to design a container similar to a std::set, but where the stored objects may be modified via a non-const iterator. In some cases the modification will effect the sort order.
I wouldn't modify the values in a set without first removing
the old item. What if you modify the item to be the same as
some other item? What if the implementation locates items
based on the sort order?
"Michael Klatt" <md*****@ou.edu > wrote in message
news:2c******** *************** ***@posting.goo gle.com... I need to design a container similar to a std::set, but where the stored objects may be modified via a non-const iterator. In some cases the modification will effect the sort order.
Here's an example:
class Object { // an object from the database };
class Sorter { // functor that determines sort order for Objects };
template <class Obj, class Sort> class Set {};
Set<Object, Sorter> query; Set<Object, Sorter>::Iterat or it(query.begin( )); while (it != query.end()) { it->modify(); // uh oh, Set<> may be invalid now }
I'm not sure what you mean by invalidating it. You mean calling it's own
destructor or something drastic ? If so, well yes anything could happen. But
this is not down to bad class design as you can screw up a program anyplace
by deleting an object when your not supposed to. In addition to this basic concept, is there a way to design Set<> so that it automagically knows when a contained object has been changed in a way that requires the set to be resorted?
Depends what you mean by contained object.
Perhaps you mean a Base class or a nested class. Or perhaps simply member
data?
But in general I believe your idea could work. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Soulshift |
last post by:
Hi all,
Here's my problem. I have a design where the class Container inherits
class Widget, and is used to contain and handle the proper display of
widgets and behaves like a widget itself. I have a class IsoWidget
which inherits from class Widget which is used to display isometric
widgets. I want to make a class IsoContainer (which contains
IsoWidgets and behaves like an IsoWidget), and since an IsoContainer
seems like it should...
|
by: Matt Stanley |
last post by:
I am trying to build a page that scales to fit the browser window regardless
of size or resolution. The navigation on the top of the page is framed in
dark red/brown using CSS with a background color specified in a custom class
tag.
I only want those cells that are using this custom class to be 1 pixel wide.
In the code I did not specify the <td> width but instead inserted a
single-pixel, transparent GIF and specified the dimensions of...
|
by: Jackson Yap |
last post by:
can someone kind enough to help me look at the attached html and js
file? Why is it that the javascript menu could not work at
www.apchosting.net but could work at
http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work
at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it
is a server problem but was told it is not possible, therefore assuming
it is a client script problem? the script works last time...
|
by: Jack Addington |
last post by:
I've got a fairly simple application implementation that over time is going
to get a lot bigger. I'm really trying to implement it in a way that will
facilitate the growth. I am first writing a WinForms interface and then
need to port that to a web app. I am kinda stuck on a design issue and need
some suggestions / direction.
Basically I have a business layer that I want to use to process any
dataentry logic (row focus changes, data...
|
by: Raed Sawalha |
last post by:
I have the following table which i can not switcha to design view error
message said
Could not open in Design view. Quote values differently inside a '<%
...."value"... %>' block.
and the line which make the error is anchor but i cannot make it work.
<TABLE id="tblDocList" dir="<%#strLangDir%>" style="DISPLAY:inline"
| |
by: Tom |
last post by:
This is probably pretty easy, but how does one determine if
a control is a CONTAINER control? I thought something like
If Typeof myControl is ContainerControl then ....
would work but that seems to always return FALSE.
Thanks.
Tom
|
by: Miguel Dias Moura |
last post by:
Hello,
I have a GridView in my page which is created in runtime. It works fine.
My page has 2 Asp Buttons:
- The HIDE button makes GridView.Visible = False;
- The SHOW button makes GridView.Visible = True.
I press HIDE and the GridView disappears as expected.
After it I press SHOW and the GridView doesn't show.
|
by: bsruth |
last post by:
I tried for an hour to find some reference to concrete information on
why this particular inheritance implementation is a bad idea, but
couldn't. So I'm sorry if this has been answered before. Here's the
scenario:
We have a base class with all virtual functions. We'll call this the
Animal class. We then make two classes Fish and Bird that both inherit
from Animal. In the program, we have a single array of Animal pointers
that will...
|
by: gerry |
last post by:
I am trying to create a custom container control that will only ever contain
a specific type of control.
At design time, when a control of a different type is added to the container
I would like to wrap the control in the proper control type - which is also
a container.
At design time I want to be able to turn this :
<my:container>
<asp:textbox />
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |