How can I insert an empty element in a list? The insert method has as
a parameter the source object to insert... So you have to use it in
this way:
(where MyObject is an object with only a member, x (an integer))
Normally a copy constructor is longer to execute than a simple
constructor, and this example code uses the constructor once (for the
obj object) and the copy constructor five times (to add the elements
in the list)
list <MyObject>::ite rator L_Iter;
list<MyObject> L;
MyObject obj;
for (int i = 1 ; i < 6 ; i++ )
{
L_Iter = L.insert(L.end( ), obj);
L_Iter->x = i;
} 3 2209
Massimiliano Alberti wrote: How can I insert an empty element in a list? The insert method has as a parameter the source object to insert... So you have to use it in this way: (where MyObject is an object with only a member, x (an integer)) Normally a copy constructor is longer to execute than a simple constructor, and this example code uses the constructor once (for the obj object) and the copy constructor five times (to add the elements in the list)
list <MyObject>::ite rator L_Iter; list<MyObject> L; MyObject obj;
for (int i = 1 ; i < 6 ; i++ ) { L_Iter = L.insert(L.end( ), obj); L_Iter->x = i; }
This is how STL works. Annoying, but this is the way. Some of us were
porposing to look at possible templated solution (so it would try to use
your int to construct the "object inside") but the Goths (Gurus Of The Holy
Standard) said that its stupid, it is only our problem noone else has it
etc. At that time I was receiving 5 mails per day saying: I have that
problem too...
Thanx God in your case it does not matter. If obj has an inlinable, simple
constructor it does not matter if you pass in an int or an obj. What it
will end up being is copying the int.
--
WW aka Attila
> Thanx God in your case it does not matter. If obj has an inlinable, simple constructor it does not matter if you pass in an int or an obj. What it will end up being is copying the int.
I thought it was quite obvious that it was only a sample... and then
you can't know what are the other members of that class... You know
only what I've initialized... Perhaps there is a char buffer[10000]
:-)
Massimiliano Alberti wrote: Thanx God in your case it does not matter. If obj has an inlinable, simple constructor it does not matter if you pass in an int or an obj. What it will end up being is copying the int.
I thought it was quite obvious that it was only a sample... and then you can't know what are the other members of that class... You know only what I've initialized... Perhaps there is a char buffer[10000] :-)
I know it is not true. You have a long double unused[10000] ;-)
--
WW aka Attila This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bill |
last post by:
How can I insert a record with a null value in one of the fields?
I need to use the update method from a data adapter. The data is in a XML
file.
|
by: Matthias |
last post by:
Hi,
I am just reading that book by Scott Meyers. In Item 4 Meyers suggests
to always use empty() instead of size() when probing for emptyness of
STL containers. His reasoning is that size() might take linear time on
some list implementations. That makes sense at first.
However, he also says this at the very beginning:
"That being the case , you might wonder why one construct should be
preferred to the other, especially in view of the...
|
by: Ryan Graham |
last post by:
I totally bombed this question in an interview so I'm posting my answer here
for comments and suggestions... perhaps (god help me) I'm just not that
bright, but this works and seems to be fairly efficent. The idea was simple,
insert an integer into a list that has already been sorted.
private int _list;
....
public void Insert(int value)
{
int tempArray;
|
by: Allerdyce.John |
last post by:
Hi,
How can I Random access an element in a STL List if I have a pointer to
that list?
I know how to do that if I have a reference to a STL list, but how can
I do that if I have a pointer to a STL List.
void function (vector<int>& myLIst) {
// access the first element of myList
printf ("%d", myList);
|
by: Steve R. Hastings |
last post by:
So, Python 2.5 will have new any() and all() functions.
http://www.python.org/dev/peps/pep-0356/
any(seq) returns True if any value in seq evaluates true, False otherwise.
all(seq) returns True if all values in seq evaluate true, False otherwise.
I have a question: what should these functions return when seq is an empty
list?
| |
by: Jakob Bieling |
last post by:
Hi,
I want to move an element from a std::list to the end of the same list.
To get this done, I thought I'd just do something like:
std::list <intlst;
lst.push_back (0);
lst.push_back (1);
lst.push_back (2);
lst.splice (lst.end (), lst, lst.begin (), ++ lst.begin ());
|
by: gruvin |
last post by:
Hi.
I need to insert an image element into text in an iframe in design mode. That part I can do:
var sel = oEditor.eFrameDoc.selection;
var range = sel.createRange();
range.pasteHTML('<img src="'+imagePath+'" border="0" />');
But I need a reference to that new IMG tag to do other stuff with it.
|
by: barcaroller |
last post by:
If an STL container is empty, what will its begin() member function return?
Would it be a valid value that an iterator could use, like the end() member
function? In particular, can I assume that begin() == end()?
|
by: toyin |
last post by:
hello, pls help look through this code its not inserting the record in dataset into the another database.
i want to insert the row in the dataset into another table in another database.
pls help. it urgent i submit this application. when it runs it gives: this OdbcTransaction has completed,it no longer usable.
thx
toyin
here is the code
Sub ProcessAllSynchOperations()
Dim sSourceURL, sWebSiteIP As String
Dim...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |