QSharedPointer VS std::tr1::shared_ptr VS boost::tr1::shared_ptr [duplicate] - c++

This question already has answers here:
What C++ Smart Pointer Implementations are available?
(3 answers)
Closed 8 years ago.
These three are shared pointer classes from Qt, STL and Boost, respectively. They seem to be identical in functionality so I'm puzzled as to:
What are advantages and disadvantages of each of them?
Why do Boost and Qt versions even exist -- it was in STL already, why make your own?
How should I choose which one to use?

Look here for the answers to your questions.

QSharedPointer requires Qt, shared_ptr is standard and portable
std::shared_ptr is a standard replacement for boost::shared_ptr (that is, the boost one came first and it became standard)
Don't use QSharedPointer unless you have a Qt class that requires it. If you have a tr1, or C++0x implementation use std::shared_ptr, otherwise used boost::shared_ptr.

Related

Alternatives to boost::scoped_ptr in C++ 11

We've just upgraded our compiler to VC++ 2013 which has support for C++ 11. Previously we've been using shared_ptr and scoped_ptr classes from Boost, but since that is all we've been using from Boost, we're looking to remove that dependency.
As far as I can tell, std::shared_ptrs are a drop-in replacement for boost::shared_ptrs, so that's (hopefully) easy.
However, what is the best replacement for Boost scoped_ptrs (if there is one)? Would it be unique_ptr?
(To be honest, even though I wrote the code, it was about 10 years ago, and I've forgotten what the purpose of using scoped_ptrs was... Maybe I was just "playing" with Boost, but as far as I can see a plain pointer would probably do in the cases I've examined).
Yes, scoped_ptr can and should be replaced with unique_ptr. They represent the same idea (unique ownership), but unique_ptr does it better, and allows transfer of ownership via move semantics. (scoped_ptr didn't because it wasn't possible in C++98)

Is the C++ standard library thread safe? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Do I need to protect read access to an STL container in a multithreading environment?
I am using the C++ standard library which comes with (Linux) GCC or (Windows) VC.
Can anyone please say clearly whether or not this library is thread safe?
"Thread safe" is not a clearly-defined boolean property of a library. Some things can be done concurrently and others cannot.
Almost certainly if you were to ask a more detailed question specifying what it is you want to do, the answer would be "no, it is not thread-safe". But only almost.
If by "thread-safe" you mean something like the difference between Vector and ArrayList in Java, then C++ standard containers are non-thread-safe.

Is there a clean separating definition between "STL" and "C++ Standard Library"? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What's this STL vs. “C++ Standard Library” fight all about?
I am very much used to the term STL ("Standard Template Library") and I catch myself often using it when I really mean the C++ Standard Library. So, since almost everything in the C++(-11) Standard Library is a template nowadays, I wonder: Is there a definition what is STL and what is not, in the C++Standard-Lib? Maybe containers, streams, algorithms, etc?
Or should I just stop using the term "STL", because it's the historic one that SGI (correct?) used for their lib years back? It will be difficult...
STL has evolved into C++ Standard Library, it contained containers, iterators and algorithms but not streams. It is better not to use term "STL" it is the name of the old library.

What is a pure-C alternative to STL containers? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Container Class / Library for C
One of the primary reasons to use C++ over C is the superbly convenient containers that STL provides. However, if I want to write my code in pure C and not have to write all my containers from scratch, what alternative do I have ?
Some of the ones that I have heard of (but never used) are
Glib
iMatix Standard Function Library
disparate elements from the Linux kernel headers (e.g. list)
Any opinions and/or experiences with containers in pure C (Ansi or otherwise) would be much appreciated.
I'd recommend GLib solely because it's got a nice set of features and it's relatively mature, stable, portable, and widely used.
You, or a library writer, can write containers etc. each time you want to use them for a different type, possibly putting definitions into gigantic macros, or you can use void * for containers, losing all hope of type safety and sometimes some performance. (C's qsort function can be significantly less efficient than C++'s sort template.) There is no way to get the equivalent of C++ containers, iterators, and algorithms in C.
I don't know much about Glib, and your reference to disparate elements from Linux kernel headers is a little vague. The Linux list you mention is probably typical of what you'd get: no type safety and a set of well-written functions that will be named differently for each data type. A quick look at iMatix didn't disclose any containers.

Does the STL contain a hashtable? [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicates:
Hashtable in C++?
can anybody offer a simple hash_map example in C++?
Does the STL contain an implementation of a hashtable?
If so, can you provide a brief example of how to use it?
Current standard implementation doesn't, STL::TR1 does, see Unordered Map.
Most modern compilers have a TR1 implementation, if that fails, you may always use the Boost TR1 implementation.
MSVC has it for VS2008 via service pack 1
GCC has it shipped with 4.x, but you can make it work with 3.4.x too AFAIR
Usage is almost the same as with a std::map.
While not officially part of the STL standard, hash_map and hash_set are commonly used to improve searching times......
http://msdn.microsoft.com/en-us/library/0d462wfh%28VS.80%29.aspx
So, long story short--no .
A quick google came up with this description of hash_map.