Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any c++ class that can't be used in STL?

Tags:

c++

stl

Just come up with this question. Any hint?

like image 626
skydoor Avatar asked Mar 18 '10 05:03

skydoor


People also ask

Does C support STL?

C can't have an "exact equivalent" of STL because C doesn't have templates or classes. You might be interested in the "Glib collections" library: http://www.ibm.com/developerworks/linux/tutorials/l-glib/

On which containers sort can be applied?

Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity).

Which of the following are STL containers types?

The three types of containers found in the STL are sequential, associative and unordered.

Under which category can stack and queue be Categorised in STL containers?

The STL containers std::vector , std::deque , and std::list all meet these requirements and can be used for underlying storage. The standard container adapters are: stack provides an LIFO data structure. queue provides a FIFO data structure.


2 Answers

classes that can't be copied. STL containers require objects to be copyable since the container owns a copy of that object, and needs to be able to move it around.

like image 68
Chris H Avatar answered Oct 03 '22 06:10

Chris H


My favourite thing not to put into a STL container is an std::auto_ptr... very bad things happen. .. mostly unexpected loss of objects I think.

In general anything that is not copyable can't go into a container - you'll get compile errors. Something with abnormal copy semantics (like auto_ptr) should not go in a container (but you probably wont get any compiler errors). As the container is free to create various temporary copies.

I think that without a "sane" default constructor and assignment operator you are also in for some pain.

like image 44
Michael Anderson Avatar answered Oct 03 '22 08:10

Michael Anderson