Just out of curiosity:
When would using std::list be more efficient / effective than using
other containers such as vector, deque, etc?
As far as I'm aware, list doesn't appear to be specialized for
anything.
Thanks,
Josh McFarlane
Dec 12 '05
44 3878 ro**********@gm ail.com wrote: Axter wrote: roberts.n...@gm ail.com wrote:
I don't agree. Every container serves a particular purpose. It could be that in YOUR case most development domains seem to be least served by the list container there are certainly a lot of cases when a list is a very appropriate choice. The best thing is to understand the implementations of the different containers and where those kind of algorithms are best used. Take a class or read a book on data structures and implement your own list, vector, map, etc...and then you will be able to understand their value and when to use what.
As a contractor, I've worked in many locations, and it's been my experience when finding std::list used in code, that 9 out of 10 times, std::list is being used inappropriately , and std::vector or std::deque would have done the same job faster.
I'm sorry but I just don't buy your "credential s". Anyone that would call that dynamic_array class of yours an example of how TO do something doesn't meet my requirements of an expert. Judging by the single code example I have seen from you I am not at all impressed.
Don't take my credentials. As I've previously recommended to you, you
should read more advance books like that of Sutters and Meyers.
These two authors have very well known established credentials.
It's a mistake to base your opinions just on online information,
because anyone can write an FAQ or a web site, and claim authority on
the subject.
It's also a mistake to base your opinions on out dated beginner's C++
books.
If you're going to advocate a position that contradicts others, you
should at least make the effort to be well informed by more respectable
sources.
Otherwise garbage in, garbage out.
You read garbage, and you're going to end up reiterating the same
garbage, which is what I've mostly seen from your previous posting.
Here are the top 10 programming books that I recommend to all C++
programmers:
Effective C++ by Scott Meyers
More Effective C++ by Scott Meyers
Exceptional C++ by Herb Sutter
More Exceptional C++ by Herb Sutter
Effective STL by Scott Meyers
C++ Coding Standards : 101 Rules, Guidelines, and Best Practices {Herb
Sutter, Andrei Alexandrescu}
Programming languages - C++ STANDARD ISO/IEC 14882:1998(E)
C++ Programming Language Special Edition, The by Bjarne Stroustrup
Efficient C++ by Dov Bulka & David Mayhew
Modern C++ Design by Andrei Alexandrescu
And you don't have to take my word for it. Instead look them up in the
following well known respected site:
advanced c++ http://www.accu.org/bookreviews/publ...vanced_c__.htm
Axter wrote: It's also a mistake to base your opinions on out dated beginner's C++ books.
You sure make a lot of assumptions little boy.
Thinking in C++ V2 is (c) 2003. The standard was altered in this one
little way just before publication apparently. This is really no big
deal, it happens. This is a very good book in every other way. I
refer to it quite often in fact, along with "The C++ Standard Library",
which is equally "outdated" by your standard. I have quite a few
"beginner" books I use as reference when I need to.
If you're going to advocate a position that contradicts others, you should at least make the effort to be well informed by more respectable sources.
By "contradict others" I think you must mean yourself? I don't need my
degrees, my experience, or my references to know that the code sample
you keep touting around is trash.
Otherwise garbage in, garbage out.
Well, if that is true then I would have to assume the books you read
are garbage. Luckily it doesn't work that way.
You read garbage, and you're going to end up reiterating the same garbage, which is what I've mostly seen from your previous posting.
Thinking in C++ is not garbage. The first volume is a great
introduction to the language. The second volume is very good
instruction on how to USE the language at several levels. The second
volume is one of the best C++ books around.
Neil Cerutti <le*******@emai l.com> writes: Nothing prevents a standard compliant implementation from always reserving 100,000,000*siz e(T) bytes for each vector, either, but mostly we don't need to worry about that unless the vendor of our compiler is named Snidely Wiplash. ;-)
But reserving space for 100,000,000 items by default would be deemed
as unreasonable by most people, while I think it's perfectly
reasonable for a copy constructor to reserve the same amount of
memory as the source vector has reserved. Especially since it's
trivial to call another constructor if one doesn't need that
amount of reserved space in the copy.
/Niklas Norrthon
On 2005-12-16, Niklas Norrthon <do********@inv alid.net> wrote: Neil Cerutti <le*******@emai l.com> writes: Nothing prevents a standard compliant implementation from always reserving 100,000,000*siz e(T) bytes for each vector, either, but mostly we don't need to worry about that unless the vendor of our compiler is named Snidely Wiplash. ;-)
But reserving space for 100,000,000 items by default would be deemed as unreasonable by most people, while I think it's perfectly reasonable for a copy constructor to reserve the same amount of memory as the source vector has reserved.
I don't agree. Copying capacity makes unsuppported assumptions.
At extremes, it's making the same assumption that you find
unreasonable in a default constructor.
--
Neil Cerutti
* Neil Cerutti: On 2005-12-16, Niklas Norrthon <do********@inv alid.net> wrote: Neil Cerutti <le*******@emai l.com> writes: Nothing prevents a standard compliant implementation from always reserving 100,000,000*siz e(T) bytes for each vector, either, but mostly we don't need to worry about that unless the vendor of our compiler is named Snidely Wiplash. ;-)
But reserving space for 100,000,000 items by default would be deemed as unreasonable by most people, while I think it's perfectly reasonable for a copy constructor to reserve the same amount of memory as the source vector has reserved.
I don't agree. Copying capacity makes unsuppported assumptions. At extremes, it's making the same assumption that you find unreasonable in a default constructor.
Well, the reason I used assign (I should really have used the constructor
taking iterators) was that this was once asked about in clc++m, but there
concerning std::string, and I posted code using the copy constructor and was
quickly corrected by someone noting that with their compiler, the
std::string copy constructor actually did copy the capacity.
So whether it's an unsupported assumption or not, it's Out There.
Waiting for a chance to grab you... ;-)
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anton |
last post by:
Hello !
I am writing a small program and wondering whether this expression is
right?
std::list< std::string > strList
I mean that this is container into container and don't know the side
effects of this expression, that could crash my program. Please , if
you know any side effect will you explain me where is it ?
|
by: Dave |
last post by:
Hello all,
After perusing the Standard, I believe it is true to say that once you
insert an element into a std::list<>, its location in memory never changes.
This makes a std::list<> ideal for storing vertices of an arbitrary n-ary
tree where a vertex contain pointers to its parent / children. These parent
/ child vertices need to stay put if we've got pointers to them somewhere!
Am I correct in my assertion?
|
by: JustSomeGuy |
last post by:
I need to write an new class derived from the list class.
This class stores data in the list to the disk if an object
that is added to the list is over 1K in size.
What methods of the std stl list class must Ioverride in order for this
to work?
|
by: Glen Able |
last post by:
Without further ado, here's some code:
std::list<int> things;
things.push_back(1);
things.push_back(2);
things.push_back(3);
std::list<int>::iterator it;
int test;
|
by: PengYu.UT |
last post by:
Hi,
Suppose I have a list which contains pointers. I want the pointer got
by dereferencing the iterator be a pointer pointing to a const object.
But std::list<const T*>::const_iterator doens't give me this
capability. So I want std::list<T*>::iterator.
However, the container is of type std::list<T*>. How to get
std::list<const T*>::iterator?
| |
by: Markus Svilans |
last post by:
Hi,
There seems to be some functionality missing from the STL.
I am iterating through a linked list (std::list) using a reverse
iterator and attempting to erase certain items from the list. It is
important that I iterate through the list backwards, because the items
in it have to be processed in reverse order before erasing. However,
there does not appear to be an std::list::erase() method defined for
reverse iterators.
|
by: desktop |
last post by:
If I have a sorted std::list with 1.000.000 elements it takes 1.000.000
operations to find element with value = 1.000.000 (need to iterator
through the whole list).
In comparison, if I have a std::set with 1.000.000 element it will only
take approx lg 1.000.000 = 20 operations! Can it really be true that the
difference is a factor of 1.000.000/20 = 50.000 in this case?
|
by: Spoon |
last post by:
Hello,
Could someone explain why the following code is illegal?
(I'm trying to use a list of (C-style) arrays.)
#include <list>
typedef std::list < int foo_t;
int main()
{
int v = { 12, 34 };
|
by: isliguezze |
last post by:
template <class T>
class List {
public:
List();
List(const List&);
List(int, const T&);
void push_back(const T &);
void push_front(const T &);
void pop_back();
|
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: 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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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: 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...
| |